views_ui_add_ajax_trigger example

$form['displays']['show']['wizard_key'] = [
      '#type' => 'select',
      '#title' => $this->t('Show'),
      '#options' => $options,
      '#sort_options' => TRUE,
    ];
    $show_form = &$form['displays']['show'];
    $default_value = $this->moduleHandler->moduleExists('node') ? 'node' : 'users';
    $show_form['wizard_key']['#default_value'] = WizardPluginBase::getSelected($form_state['show', 'wizard_key']$default_value$show_form['wizard_key']);
    // Changing this dropdown updates the entire content of $form['displays'] via     // AJAX.     views_ui_add_ajax_trigger($show_form, 'wizard_key', ['displays']);

    // Build the rest of the form based on the currently selected wizard plugin.     $wizard_key = $show_form['wizard_key']['#default_value'];
    $wizard_instance = $this->wizardManager->createInstance($wizard_key);
    $form = $wizard_instance->buildForm($form$form_state);

    return $form;
  }

  /** * {@inheritdoc} */
// Create the dropdown for choosing the display format.     $form['displays']['page']['options']['style']['style_plugin'] = [
      '#title' => $this->t('Display format'),
      '#type' => 'select',
      '#options' => $style_options,
    ];
    $style_form = &$form['displays']['page']['options']['style'];
    $style_form['style_plugin']['#default_value'] = static::getSelected($form_state['page', 'style', 'style_plugin'], 'default', $style_form['style_plugin']);
    // Changing this dropdown updates $form['displays']['page']['options'] via     // AJAX.     views_ui_add_ajax_trigger($style_form, 'style_plugin', ['displays', 'page', 'options']);

    $this->buildFormStyle($form$form_state, 'page');
    $form['displays']['page']['options']['items_per_page'] = [
      '#title' => $this->t('Items to display'),
      '#type' => 'number',
      '#default_value' => 10,
      '#min' => 0,
    ];
    $form['displays']['page']['options']['pager'] = [
      '#title' => $this->t('Use a pager'),
      '#type' => 'checkbox',
      
Home | Imprint | This part of the site doesn't use cookies.