summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrobin.ingelbrecht2018-10-16 11:33:36 (GMT)
committerRobin Ingelbrecht2018-10-16 11:33:36 (GMT)
commit0289ed1a8b2824fe1897ebaaf39cb231658e6e3f (patch)
treeda329debdfe651fdfda5ce26d1e857aab8cde912
parent405c8e083af91ab5ac7be728a772902bc6b207d1 (diff)
Issue #3006989 by robin.ingelbrecht: multilanguage support
-rw-r--r--flipclock.libraries.yml6
-rw-r--r--src/FlipClockManager.php32
-rw-r--r--src/Plugin/Block/FlipClockBlock.php23
-rw-r--r--src/Plugin/Field/FieldFormatter/DateTimeFlipClockFormatter.php30
4 files changed, 75 insertions, 16 deletions
diff --git a/flipclock.libraries.yml b/flipclock.libraries.yml
index d326d3f..8e70619 100644
--- a/flipclock.libraries.yml
+++ b/flipclock.libraries.yml
@@ -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
diff --git a/src/FlipClockManager.php b/src/FlipClockManager.php
new file mode 100644
index 0000000..0d092bd
--- /dev/null
+++ b/src/FlipClockManager.php
@@ -0,0 +1,32 @@
+<?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
diff --git a/src/Plugin/Block/FlipClockBlock.php b/src/Plugin/Block/FlipClockBlock.php
index 4e6f86c..2820c99 100644
--- a/src/Plugin/Block/FlipClockBlock.php
+++ b/src/Plugin/Block/FlipClockBlock.php
@@ -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
diff --git a/src/Plugin/Field/FieldFormatter/DateTimeFlipClockFormatter.php b/src/Plugin/Field/FieldFormatter/DateTimeFlipClockFormatter.php
index 292bac8..057be4e 100644
--- a/src/Plugin/Field/FieldFormatter/DateTimeFlipClockFormatter.php
+++ b/src/Plugin/Field/FieldFormatter/DateTimeFlipClockFormatter.php
@@ -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;
}