You are here

public function CalendarSystemsBlock::blockForm in Calendar Systems 8.3

Overrides BlockPluginTrait::blockForm

File

src/Plugin/Block/CalendarSystemsBlock.php, line 22

Class

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

Namespace

Drupal\calendar_systems\Plugin\Block

Code

public function blockForm($form, FormStateInterface $form_state) {
  $f = parent::blockForm($form, $form_state);
  $def = $this
    ->defaultConfiguration();

  // Retrieve existing configuration for this block.
  $cfg = $this
    ->getConfiguration();
  $cfg = [
    'calendar_systems_calendar' => isset($cfg['calendar_systems_calendar']) ? $cfg['calendar_systems_calendar'] ?: $def['calendar_systems_calendar'] : $def['calendar_systems_calendar'],
    'calendar_systems_format' => isset($cfg['calendar_systems_format']) ? $cfg['calendar_systems_format'] ?: $def['calendar_systems_format'] : $def['calendar_systems_format'],
    'calendar_systems_timezone' => isset($cfg['calendar_systems_timezone']) ? $cfg['calendar_systems_timezone'] ?: $def['calendar_systems_timezone'] : $def['calendar_systems_timezone'],
    'calendar_systems_text' => isset($cfg['calendar_systems_text']) ? $cfg['calendar_systems_text'] ?: $def['calendar_systems_text'] : $def['calendar_systems_text'],
    'cache' => isset($cfg['cache']) ? $cfg['cache'] : 3600,
  ];
  $f['calendar_systems_calendar'] = [
    '#title' => t('Calendar'),
    '#type' => 'select',
    '#options' => [
      'persian' => t('Persian'),
      'gregorian' => t('Gregorian'),
      'global' => t("Global (by site's langauge"),
    ],
    '#default_value' => $cfg['calendar_systems_calendar'],
  ];
  $f['calendar_systems_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['calendar_systems_format'],
  ];
  $f['calendar_systems_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['calendar_systems_timezone'],
  ];
  $f['calendar_systems_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['calendar_systems_text'],
  ];
  $f['cache'] = [
    '#title' => t('Cache lifetime'),
    '#type' => 'textfield',
    '#description' => t('How long the block should be cached, in seconds'),
    '#default_value' => $cfg['cache'],
  ];
  return $f;
}