public function TwigItem::fieldSettingsForm in Twig Field 8
Returns a form for the field-level settings.
Invoked from \Drupal\field_ui\Form\FieldConfigEditForm to allow administrators to configure field-level settings.
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 settings.
Overrides FieldItemBase::fieldSettingsForm
File
- src/
Plugin/ Field/ FieldType/ TwigItem.php, line 33
Class
- TwigItem
- Defines the Twig field type.
Namespace
Drupal\twig_field\Plugin\Field\FieldTypeCode
public function fieldSettingsForm(array $form, FormStateInterface $form_state) {
$element = [];
$definition = $this
->getFieldDefinition();
$entity_type = $definition
->getTargetEntityTypeId();
$bundle = $definition
->getTargetBundle();
$display_modes = \Drupal::service('entity_display.repository')
->getViewModeOptionsByBundle($entity_type, $bundle);
$options = [
'' => $this
->t('- None -'),
];
foreach ($display_modes as $key => $label) {
$id = $entity_type . '.' . $bundle . '.' . $key;
$options[$id] = $label;
}
$element['display_mode'] = [
'#type' => 'select',
'#title' => $this
->t('Display mode to fetch context from'),
'#description' => $this
->t('The template will receive an additional Twig context from parent entity rendered with the specified display mode.'),
'#default_value' => $this
->getSetting('display_mode'),
'#options' => $options,
];
return $element;
}