You are here

function HijriDateListWidget::formElement in Hijri 8.2

Same name and namespace in other branches
  1. 3.0.x src/Plugin/Field/FieldWidget/HijriDateListWidget.php \Drupal\hijri\Plugin\Field\FieldWidget\HijriDateListWidget::formElement()
  2. 1.0.x src/Plugin/Field/FieldWidget/HijriDateListWidget.php \Drupal\hijri\Plugin\Field\FieldWidget\HijriDateListWidget::formElement()

Define the form for the field type.

Inside this method we can define the form used to edit the field type.

Here there is a list of allowed element types: https://goo.gl/XVd4tA

Overrides DateTimeDatelistWidget::formElement

File

src/Plugin/Field/FieldWidget/HijriDateListWidget.php, line 29

Class

HijriDateListWidget
Plugin implementation of the 'HijriDateListWidget' widget.

Namespace

Drupal\hijri\Plugin\Field\FieldWidget

Code

function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) {
  $element = parent::formElement($items, $delta, $element, $form, $form_state);

  // print date('c', time());
  // exit;
  // @TODO: We may have to make this range configurable from settings form.
  // $element['value']['#date_year_range'] = '1300:1500';
  // $element['value']['#date_year_range'] = '-3:+3';
  $element['value']['#element_validate'] = [
    [
      $this,
      'validate',
    ],
  ];

  // $element['#element_validate'] = [
  //   [$this, 'validate'],
  // ];
  //
  // // $element['value']['#date_month_range'] = '1900:1910';
  // // $element['#date_year_range'] = '1900:1910';
  // // $element['#date_month_range'] = '1900:1910';
  // foreach ($element['value'] as $key => $value) {
  //   print $key .'<br />';
  // }
  // unset($element['value']['#date_part_order'][0]);
  // print_r($element['value']['#date_part_order']);
  // exit;
  // $element['value'] = [
  //   '#type' => 'date',
  //   '#title' => t('Hijri'),
  //   '#default_value' => isset($items[$delta]->value) ? $items[$delta]->value : null,
  //   '#empty_value' => '',
  //   '#placeholder' => t('Hijri'),
  //   '#element_validate' => [
  //     [$this, 'validate'],
  //   ],
  // ];
  // $element['correction'] = [
  //   '#type' => 'textfield',
  //   '#title' => t('Correction'),
  //   '#default_value' => isset($items[$delta]->correction) ? $items[$delta]->correction : null,
  //   '#empty_value' => '',
  //   '#placeholder' => t('Correction'),
  // ];
  return $element;
}