You are here

public function InlineEntityFormBase::settingsForm in Inline Entity Form 8

Returns a form to configure settings for the widget.

Invoked from \Drupal\field_ui\Form\EntityDisplayFormBase to allow administrators to configure the widget. The field_ui module takes care of handling submitted form values.

Parameters

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

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array The form definition for the widget settings.

Overrides WidgetBase::settingsForm

1 call to InlineEntityFormBase::settingsForm()
InlineEntityFormComplex::settingsForm in src/Plugin/Field/FieldWidget/InlineEntityFormComplex.php
Returns a form to configure settings for the widget.
1 method overrides InlineEntityFormBase::settingsForm()
InlineEntityFormComplex::settingsForm in src/Plugin/Field/FieldWidget/InlineEntityFormComplex.php
Returns a form to configure settings for the widget.

File

src/Plugin/Field/FieldWidget/InlineEntityFormBase.php, line 230

Class

InlineEntityFormBase
Inline entity form widget base class.

Namespace

Drupal\inline_entity_form\Plugin\Field\FieldWidget

Code

public function settingsForm(array $form, FormStateInterface $form_state) {
  $entity_type_id = $this
    ->getFieldSetting('target_type');
  $states_prefix = 'fields[' . $this->fieldDefinition
    ->getName() . '][settings_edit_form][settings]';
  $element = [];
  $element['form_mode'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Form mode'),
    '#default_value' => $this
      ->getSetting('form_mode'),
    '#options' => $this->entityDisplayRepository
      ->getFormModeOptions($entity_type_id),
    '#required' => TRUE,
  ];
  $element['revision'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Create new revision'),
    '#default_value' => $this
      ->getSetting('revision'),
  ];
  $element['override_labels'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Override labels'),
    '#default_value' => $this
      ->getSetting('override_labels'),
  ];
  $element['label_singular'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Singular label'),
    '#default_value' => $this
      ->getSetting('label_singular'),
    '#states' => [
      'visible' => [
        ':input[name="' . $states_prefix . '[override_labels]"]' => [
          'checked' => TRUE,
        ],
      ],
    ],
  ];
  $element['label_plural'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Plural label'),
    '#default_value' => $this
      ->getSetting('label_plural'),
    '#states' => [
      'visible' => [
        ':input[name="' . $states_prefix . '[override_labels]"]' => [
          'checked' => TRUE,
        ],
      ],
    ],
  ];
  $element['collapsible'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Collapsible'),
    '#default_value' => $this
      ->getSetting('collapsible'),
  ];
  $element['collapsed'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Collapsed by default'),
    '#default_value' => $this
      ->getSetting('collapsed'),
    '#states' => [
      'visible' => [
        ':input[name="' . $states_prefix . '[collapsible]"]' => [
          'checked' => TRUE,
        ],
      ],
    ],
  ];
  return $element;
}