You are here

public function InlineEntityFormComplex::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 InlineEntityFormBase::settingsForm

File

src/Plugin/Field/FieldWidget/InlineEntityFormComplex.php, line 116

Class

InlineEntityFormComplex
Complex inline widget.

Namespace

Drupal\inline_entity_form\Plugin\Field\FieldWidget

Code

public function settingsForm(array $form, FormStateInterface $form_state) {
  $element = parent::settingsForm($form, $form_state);
  $labels = $this
    ->getEntityTypeLabels();
  $states_prefix = 'fields[' . $this->fieldDefinition
    ->getName() . '][settings_edit_form][settings]';
  $element['allow_new'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Allow users to add new @label.', [
      '@label' => $labels['plural'],
    ]),
    '#default_value' => $this
      ->getSetting('allow_new'),
  ];
  $element['allow_existing'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Allow users to add existing @label.', [
      '@label' => $labels['plural'],
    ]),
    '#default_value' => $this
      ->getSetting('allow_existing'),
  ];
  $element['match_operator'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Autocomplete matching'),
    '#default_value' => $this
      ->getSetting('match_operator'),
    '#options' => $this
      ->getMatchOperatorOptions(),
    '#description' => $this
      ->t('Select the method used to collect autocomplete suggestions. Note that <em>Contains</em> can cause performance issues on sites with thousands of nodes.'),
    '#states' => [
      'visible' => [
        ':input[name="' . $states_prefix . '[allow_existing]"]' => [
          'checked' => TRUE,
        ],
      ],
    ],
  ];
  $element['allow_duplicate'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Allow users to duplicate @label.', [
      '@label' => $labels['plural'],
    ]),
    '#default_value' => $this
      ->getSetting('allow_duplicate'),
  ];
  return $element;
}