etsy-1.0.0-alpha3/etsy.module
etsy.module
<?php
/**
* Implements hook_help().
*/
function etsy_help($route_name, \Drupal\Core\Routing\RouteMatchInterface $route_match) {
switch ($route_name) {
case 'help.page.etsy':
return t('
<h3>About</h3>
<p><em>@todo</em> We need a description here.</p>
');
}
}
/**
* Implements hook_cron().
*/
function etsy_cron() {
/**
* @var \Drupal\etsy\EtsyService
*/
$etsyApi = \Drupal::service('etsy.api');
// Ping Etsy API to keep the OAuth2 alive.
$etsyApi->ping();
}
/**
* Implements hook_requirements().
*/
function etsy_requirements($phase) {
switch( $phase ) {
case 'runtime':
$config = \Drupal::config('etsy.settings');
$client_id = $config->get('oauth2_client_id');
if(is_null($client_id)) {
$status = REQUIREMENT_WARNING;
$description = t('Etsy API OAuth2 client is not installed.');
$value = '';
}
else {
/**
* @var \Drupal\etsy\EtsyService
*/
$etsyApi = \Drupal::service('etsy.api');
if ( $etsyApi ) {
$ping = $etsyApi->ping();
if( $ping === FALSE ) {
$status = REQUIREMENT_ERROR;
$description = t('Failed to connect with the Etsy API. Check your OAuth2 settings.');
$value = '';
} else {
$status = REQUIREMENT_OK;
$description = t('Successfully connected to the Etsy API.');
$value = t('Application ID: @id', ['@id' => $ping->application_id] );
}
}
}
$requirements['etsy'] = [
'title' => 'Etsy API',
'value' => $value,
'description' => $description,
'severity' => $status,
];
return $requirements;
default:
// do nothing.
}
}
function etsy_uninstall() {
// Delete configuration.
\Drupal::configFactory()->getEditable('etsy.settings')->delete();
// Optionally, delete other configuration files.
\Drupal::configFactory()->getEditable('oauth2_client.oauth2_client.etsy')->delete();
// Optional: Log the uninstallation.
\Drupal::logger('etsy')->notice('Etsy API configuration uninstalled.');
\Drupal::logger('etsy')->notice('Etsy OAuth2 client uninstalled.');
\Drupal::cache()->invalidateAll();
}
/**
* Currencies supported by Etsy.
*
* @return array[]
*/
function etsy_supported_currencies() {
return [
'USD' => ['symbol' => '$', 'text' => t('United States Dollar')],
'CAD' => ['symbol' => '$', 'text' => t('Canadian Dollar')],
'EUR' => ['symbol' => '€', 'text' => t('Euro')],
'GBP' => ['symbol' => '£', 'text' => t('British Pound')],
'AUD' => ['symbol' => '$', 'text' => t('Australian Dollar')],
'JPY' => ['symbol' => '¥', 'text' => t('Japanese Yen')],
'CNY' => ['symbol' => '¥', 'text' => t('Chinese Yuan')],
'CZK' => ['symbol' => 'Kč', 'text' => t('Czech Koruna')],
'DKK' => ['symbol' => 'kr', 'text' => t('Danish Krone')],
'HKD' => ['symbol' => '$', 'text' => t('Hong Kong Dollar')],
'HUF' => ['symbol' => 'Ft', 'text' => t('Hungarian Forint')],
'INR' => ['symbol' => '₹', 'text' => t('Indian Rupee')],
'IDR' => ['symbol' => 'Rp', 'text' => t('Indonesian Rupiah')],
'ILS' => ['symbol' => '₪', 'text' => t('Israeli Shekel')],
'MYR' => ['symbol' => 'RM', 'text' => t('Malaysian Ringgit')],
'MXN' => ['symbol' => '$', 'text' => t('Mexican Peso')],
'MAD' => ['symbol' => 'DH', 'text' => t('Moroccan Dirham')],
'NZD' => ['symbol' => '$', 'text' => t('New Zealand Dollar')],
'NOK' => ['symbol' => 'kr', 'text' => t('Norwegian Krone')],
'PHP' => ['symbol' => '₱', 'text' => t('Philippine Peso')],
'SGD' => ['symbol' => '$', 'text' => t('Singapore Dollar')],
'VND' => ['symbol' => '₫', 'text' => t('Vietnamese Dong')],
'ZAR' => ['symbol' => 'R', 'text' => t('South African Rand')],
'SEK' => ['symbol' => 'kr', 'text' => t('Swedish Krona')],
'CHF' => ['symbol' => '', 'text' => t('Swiss Franc')],
'THB' => ['symbol' => '฿', 'text' => t('Thai Baht')],
'TWD' => ['symbol' => 'NT$', 'text' => t('Taiwan New Dollar')],
'TRY' => ['symbol' => '₺', 'text' => t('Turkish Lira')],
'PLN' => ['symbol' => 'zł', 'text' => t('Polish Zloty')],
'BRL' => ['symbol' => 'R$', 'text' => t('Brazilian Real')],
];
}