You are here

public function SmartDateFieldItemList::defaultValuesForm in Smart Date 8.2

Same name and namespace in other branches
  1. 8 src/Plugin/Field/FieldType/SmartDateFieldItemList.php \Drupal\smart_date\Plugin\Field\FieldType\SmartDateFieldItemList::defaultValuesForm()
  2. 3.x src/Plugin/Field/FieldType/SmartDateFieldItemList.php \Drupal\smart_date\Plugin\Field\FieldType\SmartDateFieldItemList::defaultValuesForm()
  3. 3.0.x src/Plugin/Field/FieldType/SmartDateFieldItemList.php \Drupal\smart_date\Plugin\Field\FieldType\SmartDateFieldItemList::defaultValuesForm()
  4. 3.1.x src/Plugin/Field/FieldType/SmartDateFieldItemList.php \Drupal\smart_date\Plugin\Field\FieldType\SmartDateFieldItemList::defaultValuesForm()
  5. 3.2.x src/Plugin/Field/FieldType/SmartDateFieldItemList.php \Drupal\smart_date\Plugin\Field\FieldType\SmartDateFieldItemList::defaultValuesForm()
  6. 3.3.x src/Plugin/Field/FieldType/SmartDateFieldItemList.php \Drupal\smart_date\Plugin\Field\FieldType\SmartDateFieldItemList::defaultValuesForm()
  7. 3.4.x src/Plugin/Field/FieldType/SmartDateFieldItemList.php \Drupal\smart_date\Plugin\Field\FieldType\SmartDateFieldItemList::defaultValuesForm()

Returns a form for the default value input.

Invoked from \Drupal\field_ui\Form\FieldConfigEditForm to allow administrators to configure instance-level default value.

Parameters

array $form: The form where the settings form is being included in.

\Drupal\Core\Form\FormStateInterface $form_state: The form state of the (entire) configuration form.

Return value

array The form definition for the field default value.

Overrides DateTimeFieldItemList::defaultValuesForm

File

src/Plugin/Field/FieldType/SmartDateFieldItemList.php, line 21

Class

SmartDateFieldItemList
Represents a configurable entity smartdate field.

Namespace

Drupal\smart_date\Plugin\Field\FieldType

Code

public function defaultValuesForm(array &$form, FormStateInterface $form_state) {
  if (empty($this
    ->getFieldDefinition()
    ->getDefaultValueCallback())) {
    if ($this
      ->getFieldDefinition()
      ->getDefaultValueLiteral()) {
      $default_value = $this
        ->getFieldDefinition()
        ->getDefaultValueLiteral()[0];
    }
    else {
      $default_value = [];
    }
    $element = parent::defaultValuesForm($form, $form_state);
    $element['default_date_type']['#options']['next_hour'] = t('Next hour');
    unset($element['default_time_type']);
    $description = '<p>' . $this
      ->t('The possible durations this field can contain. Enter one value per line, in the format key|label.');
    $description .= '<br/>' . $this
      ->t('The key is the stored value, and must be numeric or "custom" to allow an arbitrary length. The label will be used in edit forms.');
    $description .= '<br/>' . $this
      ->t('The label is optional: if a line contains a single number, it will be used as key and label.') . '</p>';
    $element['default_duration_increments'] = [
      '#type' => 'textarea',
      '#title' => $this
        ->t('Allowed duration increments'),
      '#description' => $description,
      '#default_value' => isset($default_value['default_duration_increments']) ? $default_value['default_duration_increments'] : "30\n60|1 hour\n90\n120|2 hours\ncustom",
      '#required' => TRUE,
    ];
    $element['default_duration'] = [
      '#type' => 'textfield',
      '#title' => $this
        ->t('Default duration'),
      '#description' => $this
        ->t('Set which of the duration increments provided above that should be selected by default.'),
      '#default_value' => isset($default_value['default_duration']) ? $default_value['default_duration'] : '60',
      '#required' => TRUE,
    ];
    return $element;
  }
}