You are here

public function EntityFormField::buildOptionsForm in Views Entity Form Field 8

Default options form that provides the label widget that all fields should have.

Overrides FieldPluginBase::buildOptionsForm

File

src/Plugin/views/field/EntityFormField.php, line 364

Class

EntityFormField
Defines a views form element for an entity field widget.

Namespace

Drupal\views_entity_form_field\Plugin\views\field

Code

public function buildOptionsForm(&$form, FormStateInterface $form_state) {
  parent::buildOptionsForm($form, $form_state);
  $field_definition = $this
    ->getBundleFieldDefinition();
  $form['plugin'] = [
    'type' => [
      '#type' => 'select',
      '#title' => $this
        ->t('Widget type'),
      '#options' => $this
        ->getPluginApplicableOptions($field_definition),
      '#default_value' => $this->options['plugin']['type'],
      '#attributes' => [
        'class' => [
          'field-plugin-type',
        ],
      ],
      '#ajax' => [
        'url' => views_ui_build_form_url($form_state),
      ],
      '#submit' => [
        [
          $this,
          'submitTemporaryForm',
        ],
      ],
      '#executes_submit_callback' => TRUE,
    ],
    'hide_title' => [
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Hide widget title'),
      '#default_value' => $this->options['plugin']['hide_title'],
    ],
    'hide_description' => [
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Hide widget description'),
      '#default_value' => $this->options['plugin']['hide_description'],
    ],
    'settings_edit_form' => [],
  ];

  // Generate the settings form and allow other modules to alter it.
  if ($plugin = $this
    ->getPluginInstance()) {
    $settings_form = $plugin
      ->settingsForm($form, $form_state);

    // Adds the widget third party settings forms.
    $third_party_settings_form = [];
    foreach ($this->moduleHandler
      ->getImplementations('field_widget_third_party_settings_form') as $module) {
      $third_party_settings_form[$module] = $this->moduleHandler
        ->invoke($module, 'field_widget_third_party_settings_form', [
        $plugin,
        $field_definition,
        'views_view',
        $form,
        $form_state,
      ]);
    }
    if ($settings_form || $third_party_settings_form) {
      $form['plugin']['#cell_attributes'] = [
        'colspan' => 3,
      ];
      $form['plugin']['settings_edit_form'] = [
        '#type' => 'fieldset',
        '#title' => $this
          ->t('Widget settings'),
        '#attributes' => [
          'class' => [
            'field-plugin-settings-edit-form',
          ],
        ],
        'settings' => $settings_form,
        'third_party_settings' => $third_party_settings_form,
      ];
      $form['#attributes']['class'][] = 'field-plugin-settings-editing';
    }
  }
}