Commit 0289ed1a authored by robin.ingelbrecht's avatar robin.ingelbrecht Committed by robin.ingelbrecht

Issue #3006989 by robin.ingelbrecht: multilanguage support

parent 405c8e08
......@@ -6,10 +6,10 @@ flipclock:
url: 'https://github.com/objectivehtml/FlipClock/blob/master/README.md'
gpl-compatible: false
js:
/libraries/flipclock/compiled/flipclock.min.js: {}
/libraries/FlipClock/compiled/flipclock.min.js: {}
css:
theme:
/libraries/flipclock/compiled/flipclock.css: {}
/libraries/FlipClock/compiled/flipclock.css: {}
dependencies:
- core/jquery
flipclock.load:
......@@ -17,4 +17,4 @@ flipclock.load:
js/flipclock.load.js: {}
dependencies:
- core/drupalSettings
- flipclock/flipclock
- flipclock/flipclock
\ No newline at end of file
<?php
namespace Drupal\flipclock;
/**
* Class FlipClockManager
*/
class FlipClockManager {
/**
* @return array
*/
public static function getLanguages() {
return [
'ar-ar' => 'Arabic',
'da-dk' => 'Danish',
'de-de' => 'German',
'en-us' => 'English',
'es-es' => 'Spanish',
'fi-fi' => 'Finnish',
'fr-ca' => 'French',
'it-it' => 'Italian',
'lv-lv' => 'Latvian',
'nl-be' => 'Dutch',
'no-nb' => 'Norwegian',
'pt-br' => 'Portugese',
'ru-ru' => 'Russian',
'sv-se' => 'Swedish',
];
}
}
\ No newline at end of file
......@@ -6,10 +6,9 @@ use Drupal\Core\Block\BlockBase;
use Drupal\Core\Block\BlockPluginInterface;
use Drupal\Core\Datetime\DrupalDateTime;
use Drupal\Core\Form\FormStateInterface;
use Drupal\flipclock\FlipClockManager;
/**
* FlipClock Module Block File.
*
* @Block(
* id = "flipclock_block",
* admin_label = @Translation("Clock"),
......@@ -78,6 +77,14 @@ class FlipClockBlock extends BlockBase implements BlockPluginInterface {
'#default_value' => isset($config['show_seconds']) ? $config['show_seconds'] : TRUE,
];
$form['language'] = [
'#type' => 'select',
'#options' => FlipClockManager::getLanguages(),
'#required' => TRUE,
'#description' => $this->t('The language to render the flipclock in.'),
'#default_value' => isset($config['language']) ? $config['language'] : 'en-us',
];
return $form;
}
......@@ -85,14 +92,18 @@ class FlipClockBlock extends BlockBase implements BlockPluginInterface {
* {@inheritdoc}
*/
public function blockSubmit($form, FormStateInterface $form_state) {
/** @var \Drupal\Core\Datetime\DrupalDateTime $date */
$date = $form_state->getValue('date');
$this->setConfigurationValue('date', $date->format(DATETIME_DATETIME_STORAGE_FORMAT));
if($date instanceof DrupalDateTime){
$date = $date->format(DATETIME_DATETIME_STORAGE_FORMAT);
}
$this->setConfigurationValue('date', $date);
$this->setConfigurationValue('clock_face', $form_state->getValue('clock_face'));
$this->setConfigurationValue('auto_play', $form_state->getValue('auto_play'));
$this->setConfigurationValue('auto_start', $form_state->getValue('auto_start'));
$this->setConfigurationValue('countdown', $form_state->getValue('countdown'));
$this->setConfigurationValue('show_seconds', $form_state->getValue('show_seconds'));
$this->setConfigurationValue('language', $form_state->getValue('language'));
}
/**
......@@ -109,6 +120,7 @@ class FlipClockBlock extends BlockBase implements BlockPluginInterface {
'autoStart' => ($this->configuration['auto_start']) ? TRUE : FALSE,
'countdown' => ($this->configuration['countdown']) ? TRUE : FALSE,
'showSeconds' => ($this->configuration['show_seconds']) ? TRUE : FALSE,
'language'=> ($this->configuration['language']) ? $this->configuration['language'] : 'en-us',
],
];
......@@ -125,4 +137,5 @@ class FlipClockBlock extends BlockBase implements BlockPluginInterface {
return $build;
}
}
}
\ No newline at end of file
......@@ -2,9 +2,11 @@
namespace Drupal\flipclock\Plugin\Field\FieldFormatter;
use Drupal\Core\Datetime\DrupalDateTime;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\FormatterBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\flipclock\FlipClockManager;
/**
* Plugin implementation of the 'FlipClock' formatter for 'datetime' fields.
......@@ -15,7 +17,7 @@ use Drupal\Core\Form\FormStateInterface;
* field_types = {
* "datetime"
* }
* )
*)
*/
class DateTimeFlipClockFormatter extends FormatterBase {
......@@ -24,12 +26,13 @@ class DateTimeFlipClockFormatter extends FormatterBase {
*/
public static function defaultSettings() {
return [
'clock_face' => 'HourlyCounter',
'auto_play' => TRUE,
'auto_start' => TRUE,
'countdown' => FALSE,
'show_seconds' => TRUE,
] + parent::defaultSettings();
'clock_face' => 'HourlyCounter',
'auto_play' => TRUE,
'auto_start' => TRUE,
'countdown' => FALSE,
'show_seconds' => TRUE,
'language' => 'en-us'
] + parent::defaultSettings();
}
/**
......@@ -52,7 +55,8 @@ class DateTimeFlipClockFormatter extends FormatterBase {
'autoPlay' => $this->getSetting('auto_play') ? TRUE : FALSE,
'autoStart' => $this->getSetting('auto_start') ? TRUE : FALSE,
'countdown' => $this->getSetting('countdown') ? TRUE : FALSE,
'showSeconds' => $this->getSetting('show_Seconds') ? TRUE : FALSE,
'showSeconds' => $this->getSetting('show_seconds') ? TRUE : FALSE,
'language'=> $this->getSetting('language'),
],
];
......@@ -122,6 +126,15 @@ class DateTimeFlipClockFormatter extends FormatterBase {
'#default_value' => $this->getSetting('show_seconds'),
];
$form['language'] = [
'#type' => 'select',
'#options' => FlipClockManager::getLanguages(),
'#required' => TRUE,
'#description' => $this->t('The language to render the flipclock in.'),
'#default_value' => $this->getSetting('language'),
];
return $form;
}
......@@ -144,6 +157,7 @@ class DateTimeFlipClockFormatter extends FormatterBase {
$summary[] = $this->t('Auto start: @auto_start', ['@auto_start' => $this->getSetting('auto_start') ? $this->t('Yes') : $this->t('No')]);
$summary[] = $this->t('Countdown: @countdown', ['@countdown' => $this->getSetting('countdown') ? $this->t('Yes') : $this->t('No')]);
$summary[] = $this->t('Show seconds: @show_seconds', ['@show_seconds' => $this->getSetting('show_seconds') ? $this->t('Yes') : $this->t('No')]);
$summary[] = $this->t('Language: @language', ['@language' => FlipClockManager::getLanguages()[$this->getSetting('language')]]);
return $summary;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment