You are here

public function Eva::submitOptionsForm in EVA: Entity Views Attachment 8.2

Same name and namespace in other branches
  1. 8 src/Plugin/views/display/Eva.php \Drupal\eva\Plugin\views\display\Eva::submitOptionsForm()

Handle any special handling on the validate form.

Overrides DisplayPluginBase::submitOptionsForm

File

src/Plugin/views/display/Eva.php, line 307

Class

Eva
The plugin that handles an EVA display in views.

Namespace

Drupal\eva\Plugin\views\display

Code

public function submitOptionsForm(&$form, FormStateInterface $form_state) {
  parent::submitOptionsForm($form, $form_state);
  switch ($form_state
    ->get('section')) {
    case 'entity_type':
      $new_entity = $form_state
        ->getValue('entity_type');
      $old_entity = $this
        ->getOption('entity_type');
      $this
        ->setOption('entity_type', $new_entity);
      if ($new_entity != $old_entity) {

        // Each entity has its own list of bundles and view modes. If there's
        // only one on the new type, we can select it automatically. Otherwise
        // we need to wipe the options and start over.
        $new_bundles_keys = $this->bundleInfo
          ->getBundleInfo($new_entity);
        $new_bundles = [];
        if (count($new_bundles_keys) == 1) {
          $new_bundles[] = $new_bundles_keys[0];
        }
        $this
          ->setOption('bundles', $new_bundles);
      }
      break;
    case 'bundles':
      $this
        ->setOption('bundles', array_values(array_filter($form_state
        ->getValue('bundles'))));
      break;
    case 'arguments':
      $this
        ->setOption('argument_mode', $form_state
        ->getValue('argument_mode'));
      if ($form_state
        ->getValue('argument_mode') == 'token') {
        $this
          ->setOption('default_argument', $form_state
          ->getValue('default_argument'));
      }
      else {
        $this
          ->setOption('default_argument', NULL);
      }
      break;
    case 'show_title':
      $this
        ->setOption('show_title', $form_state
        ->getValue('show_title'));
      break;
  }
}