You are here

public function DatexBlock::blockForm in Datex 8

Overrides BlockPluginTrait::blockForm

File

src/Plugin/Block/DatexBlock.php, line 27

Class

DatexBlock
Provides a block to show a localized current/relative date.

Namespace

Drupal\datex\Plugin\Block

Code

public function blockForm($form, FormStateInterface $form_state) {
  $f = parent::blockForm($form, $form_state);

  // Retrieve existing configuration for this block.
  $cfg = $this
    ->getConfiguration();
  $cfg = [
    'cal' => isset($cfg['cal']) ? $cfg['cal'] : 'persian',
    'fmt' => isset($cfg['fmt']) ? $cfg['fmt'] : 'Y/m/d H:i:s',
    'tz' => isset($cfg['tz']) ? $cfg['tz'] : 'user',
    'text' => isset($cfg['text']) ? $cfg['text'] : '{}',
    'cache' => isset($cfg['cache']) ? $cfg['cache'] : 3600,
  ];
  $f['datex_calendar'] = [
    '#title' => t('Calendar'),
    '#type' => 'select',
    '#options' => _datex_available_calendars(),
    '#default_value' => $cfg['cal'],
  ];
  $f['datex_format'] = [
    '#title' => t('Date/Time format'),
    '#type' => 'textfield',
    '#description' => 'TODO add medium short and ... See php.net/manual/en/function.date.php for date formats',
    '#default_value' => $cfg['fmt'],
  ];
  $f['datex_timezone'] = [
    '#title' => t('Timezone'),
    '#type' => 'select',
    '#options' => [
      'site' => t("Use site's timezone"),
      'user' => t("Use user's timezone"),
    ] + system_time_zones(),
    '#default_value' => $cfg['tz'],
  ];
  $f['datex_text'] = [
    '#title' => t('Content'),
    '#type' => 'textfield',
    '#description' => t('The blocks content. {} is replaced with the actual date. If unsure, leave this field empty or set it to {}'),
    '#default_value' => $cfg['text'],
  ];
  $f['datex_cache'] = [
    '#title' => t('Cache lifetime'),
    '#type' => 'textfield',
    '#description' => t('How long the block should be cached, in seconds'),
    '#default_value' => $cfg['cache'],
  ];
  return $f;
}