function ListItemBase::storageSettingsForm

Overrides FieldItemBase::storageSettingsForm

File

core/modules/options/src/Plugin/Field/FieldType/ListItemBase.php, line 84

Class

ListItemBase
Plugin base class inherited by the options field types.

Namespace

Drupal\options\Plugin\Field\FieldType

Code

public function storageSettingsForm(array &$form, FormStateInterface $form_state, $has_data) {
  $allowed_values = $this->getSetting('allowed_values');
  $allowed_values_function = $this->getSetting('allowed_values_function');
  $element['allowed_values'] = [
    '#type' => 'textarea',
    '#title' => t('Allowed values list'),
    '#default_value' => $this->allowedValuesString($allowed_values),
    '#rows' => 10,
    '#access' => empty($allowed_values_function),
    '#element_validate' => [
      [
        get_class($this),
        'validateAllowedValues',
      ],
    ],
    '#field_has_data' => $has_data,
    '#field_name' => $this->getFieldDefinition()
      ->getName(),
    '#entity_type' => $this->getEntity()
      ->getEntityTypeId(),
    '#allowed_values' => $allowed_values,
  ];
  $element['allowed_values']['#description'] = $this->allowedValuesDescription();
  $element['allowed_values_function'] = [
    '#type' => 'item',
    '#title' => t('Allowed values list'),
    '#markup' => t('The value of this field is being determined by the %function function and may not be changed.', [
      '%function' => $allowed_values_function,
    ]),
    '#access' => !empty($allowed_values_function),
    '#value' => $allowed_values_function,
  ];
  return $element;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.