/**
  * {@inheritdoc}
  */
 function settingsForm(array $form, FormStateInterface $form_state)
 {
     $element = parent::settingsForm($form, $form_state);
     $element['date_order'] = array('#type' => 'select', '#title' => t('Date part order'), '#default_value' => $this->getSetting('date_order'), '#options' => array('MDY' => t('Month/Day/Year'), 'DMY' => t('Day/Month/Year'), 'YMD' => t('Year/Month/Day')));
     if ($this->getFieldSetting('datetime_type') == 'datetime') {
         $element['time_type'] = array('#type' => 'select', '#title' => t('Time type'), '#default_value' => $this->getSetting('time_type'), '#options' => array('24' => t('24 hour time'), '12' => t('12 hour time')));
     } else {
         $element['time_type'] = array('#type' => 'hidden', '#value' => 'none');
     }
     $element['increment'] = array('#type' => 'select', '#title' => t('Time increments'), '#default_value' => $this->getSetting('increment'), '#options' => array(1 => t('1 minute'), 5 => t('5 minute'), 10 => t('10 minute'), 15 => t('15 minute'), 30 => t('30 minute')));
     return $element;
 }
Esempio n. 2
0
 /**
  * {@inheritdoc}
  */
 public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state)
 {
     $element = parent::formElement($items, $delta, $element, $form, $form_state);
     $element['#element_validate'][] = [$this, 'validateStartEnd'];
     $element['value']['#title'] = $this->t('Start');
     $element['end_value'] = ['#title' => $this->t('End')] + $element['value'];
     if ($items[$delta]->start_date) {
         /** @var \Drupal\Core\Datetime\DrupalDateTime $start_date */
         $start_date = $items[$delta]->start_date;
         $element['value']['#default_value'] = $this->createDefaultValue($start_date, $element['value']['#date_timezone']);
     }
     if ($items[$delta]->end_date) {
         /** @var \Drupal\Core\Datetime\DrupalDateTime $end_date */
         $end_date = $items[$delta]->end_date;
         $element['end_value']['#default_value'] = $this->createDefaultValue($end_date, $element['end_value']['#date_timezone']);
     }
     return $element;
 }
Esempio n. 3
0
 /**
  * {@inheritdoc}
  */
 public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state)
 {
     $element = parent::formElement($items, $delta, $element, $form, $form_state);
     // Identify the type of date and time elements to use.
     switch ($this->getFieldSetting('datetime_type')) {
         case DateTimeItem::DATETIME_TYPE_DATE:
             $date_type = 'date';
             $time_type = 'none';
             $date_format = $this->dateStorage->load('html_date')->getPattern();
             $time_format = '';
             break;
         default:
             $date_type = 'date';
             $time_type = 'time';
             $date_format = $this->dateStorage->load('html_date')->getPattern();
             $time_format = $this->dateStorage->load('html_time')->getPattern();
             break;
     }
     $element['value'] += array('#date_date_format' => $date_format, '#date_date_element' => $date_type, '#date_date_callbacks' => array(), '#date_time_format' => $time_format, '#date_time_element' => $time_type, '#date_time_callbacks' => array());
     return $element;
 }
 /**
  * {@inheritdoc}
  */
 public static function defaultSettings()
 {
     return array('behaviour' => 'create') + parent::defaultSettings();
 }