buildConfigurationForm example

/** * {@inheritdoc} */
  public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
    $bundles = $this->entityTypeBundleInfo->getBundleInfo($this->getDerivativeId());
    $form['bundles'] = [
      '#title' => $this->pluginDefinition['label'],
      '#type' => 'checkboxes',
      '#options' => array_combine(array_keys($bundles)array_column($bundles, 'label')),
      '#default_value' => $this->configuration['bundles'],
    ];
    return parent::buildConfigurationForm($form$form_state);
  }

  /** * {@inheritdoc} */
  public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
    $this->configuration['bundles'] = array_filter($form_state->getValue('bundles'));
    parent::submitConfigurationForm($form$form_state);
  }

  /** * {@inheritdoc} */
$form['description'] = [
      '#type' => 'textfield',
      '#title' => $this->t('Description'),
      '#description' => $this->t('Shown when hovering over the menu link.'),
      // @todo Ensure that the view is not loaded with a localized description.       // https://www.drupal.org/node/2309507       '#default_value' => $this->menuLink->getDescription(),
      '#weight' => -5,
    ];

    $form += parent::buildConfigurationForm($form$form_state);

    $form['info']['#weight'] = -8;
    $form['path']['#weight'] = -7;

    $view = $this->menuLink->loadView();
    $id = $view->storage->id();
    $label = $view->storage->label();
    if ($this->moduleHandler->moduleExists('views_ui')) {
      $message = $this->t('This link is provided by the Views module. The path can be changed by editing the view <a href=":url">@label</a>', [':url' => Url::fromRoute('entity.view.edit_form', ['view' => $id])->toString(), '@label' => $label]);
    }
    else {
      
default:
        break;
    }
    return NULL;
  }

  /** * {@inheritdoc} */
  public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
    $form = parent::buildConfigurationForm($form$form_state);

    $domain = $this->configFactory->get('media.settings')->get('iframe_domain');
    if (!$this->iFrameUrlHelper->isSecure($domain)) {
      array_unshift($form[
        '#markup' => '<p>' . $this->t('It is potentially insecure to display oEmbed content in a frame that is served from the same domain as your main Drupal site, as this may allow execution of third-party code. <a href=":url">You can specify a different domain for serving oEmbed content in the Media settings</a>.', [
          ':url' => Url::fromRoute('media.settings')->setAbsolute()->toString(),
        ]) . '</p>',
      ]);
    }

    $form['thumbnails_directory'] = [
      
'#field_prefix' => 'search/',
      '#default_value' => $this->entity->getPath(),
      '#maxlength' => '255',
      '#required' => TRUE,
    ];
    $form['plugin'] = [
      '#type' => 'value',
      '#value' => $this->entity->get('plugin'),
    ];

    if ($this->plugin instanceof PluginFormInterface) {
      $form += $this->plugin->buildConfigurationForm($form$form_state);
    }

    return parent::form($form$form_state);
  }

  /** * Determines if the search page entity already exists. * * @param string $id * The search configuration ID. * * @return bool * TRUE if the search configuration exists, FALSE otherwise. */

  public function defaultConfiguration() {
    return parent::defaultConfiguration() + [
      'upscale' => FALSE,
    ];
  }

  /** * {@inheritdoc} */
  public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
    $form = parent::buildConfigurationForm($form$form_state);
    $form['width']['#required'] = FALSE;
    $form['height']['#required'] = FALSE;
    $form['upscale'] = [
      '#type' => 'checkbox',
      '#default_value' => $this->configuration['upscale'],
      '#title' => $this->t('Allow Upscaling'),
      '#description' => $this->t('Let scale make images larger than their original size.'),
    ];
    return $form;
  }

  
'#options' => $states,
    ];

    // Add additional form fields from the workflow type plugin.     if ($workflow_type->hasFormClass(TransitionInterface::PLUGIN_FORM_KEY)) {
      $form['type_settings'] = [
        '#tree' => TRUE,
      ];
      $subform_state = SubformState::createForSubform($form['type_settings']$form$form_state);
      $form['type_settings'] += $this->pluginFormFactory
        ->createInstance($workflow_type, TransitionInterface::PLUGIN_FORM_KEY)
        ->buildConfigurationForm($form['type_settings']$subform_state);
    }

    return $form;
  }

  /** * Determines if the workflow transition already exists. * * @param string $transition_id * The workflow transition ID. * * @return bool * TRUE if the workflow transition exists, FALSE otherwise. */
public function doBuildForm(array $form, FormStateInterface $form_state, SectionStorageInterface $section_storage = NULL, $delta = NULL, SectionComponent $component = NULL) {
    $this->sectionStorage = $section_storage;
    $this->delta = $delta;
    $this->uuid = $component->getUuid();
    $this->block = $component->getPlugin();

    $form_state->setTemporaryValue('gathered_contexts', $this->getPopulatedContexts($section_storage));

    $form['#tree'] = TRUE;
    $form['settings'] = [];
    $subform_state = SubformState::createForSubform($form['settings']$form$form_state);
    $form['settings'] = $this->getPluginForm($this->block)->buildConfigurationForm($form['settings']$subform_state);

    $form['actions']['submit'] = [
      '#type' => 'submit',
      '#value' => $this->submitLabel(),
      '#button_type' => 'primary',
    ];
    if ($this->isAjax()) {
      $form['actions']['submit']['#ajax']['callback'] = '::ajaxSubmit';
      // @todo static::ajaxSubmit() requires data-drupal-selector to be the same       // between the various Ajax requests. A bug in       // \Drupal\Core\Form\FormBuilder prevents that from happening unless

  public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
    $form['theme'] = [
      '#type' => 'select',
      '#title' => $this->t('Theme'),
      '#default_value' => $this->configuration['theme'],
      '#options' => array_map(function D$theme_info) {
        return $theme_info->info['name'];
      }$this->themeHandler->listInfo()),
    ];
    return parent::buildConfigurationForm($form$form_state);
  }

  /** * {@inheritdoc} */
  public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
    $this->configuration['theme'] = $form_state->getValue('theme');
    parent::submitConfigurationForm($form$form_state);
  }

  /** * {@inheritdoc} */

  public function buildForm(array $form, FormStateInterface $form_state, MenuLinkInterface $menu_link_plugin = NULL) {
    $form['menu_link_id'] = [
      '#type' => 'value',
      '#value' => $menu_link_plugin->getPluginId(),
    ];
    $class_name = $menu_link_plugin->getFormClass();
    $form['#plugin_form'] = $this->classResolver->getInstanceFromDefinition($class_name);
    $form['#plugin_form']->setMenuLinkInstance($menu_link_plugin);

    $form += $form['#plugin_form']->buildConfigurationForm($form$form_state);

    $form['actions'] = ['#type' => 'actions'];
    $form['actions']['submit'] = [
      '#type' => 'submit',
      '#value' => $this->t('Save'),
      '#button_type' => 'primary',
    ];
    return $form;
  }

  /** * {@inheritdoc} */


    // Add additional form fields from the workflow type plugin.     if ($workflow_type->hasFormClass(StateInterface::PLUGIN_FORM_KEY)) {
      $form['type_settings'] = [
        '#tree' => TRUE,
      ];
      $subform_state = SubformState::createForSubform($form['type_settings']$form$form_state);
      $subform_state->set('state', $state);
      $form['type_settings'] += $this->pluginFormFactory
        ->createInstance($workflow_type, StateInterface::PLUGIN_FORM_KEY)
        ->buildConfigurationForm($form['type_settings']$subform_state);
    }

    $header = [
      'label' => $this->t('Transition'),
      'state' => $this->t('To'),
      'operations' => $this->t('Operations'),
    ];
    $form['transitions'] = [
      '#type' => 'table',
      '#header' => $header,
      '#empty' => $this->t('There are no transitions to or from this state yet.'),
    ];
$form['field_layouts']['settings_wrapper'] = [
      '#type' => 'container',
      '#id' => 'field-layout-settings-wrapper',
      '#tree' => TRUE,
    ];

    $form['field_layouts']['settings_wrapper']['icon'] = $layout_plugin->getPluginDefinition()->getIcon();

    if ($layout_plugin instanceof PluginFormInterface) {
      $form['field_layouts']['settings_wrapper']['layout_settings'] = [];
      $subform_state = SubformState::createForSubform($form['field_layouts']['settings_wrapper']['layout_settings']$form$form_state);
      $form['field_layouts']['settings_wrapper']['layout_settings'] = $layout_plugin->buildConfigurationForm($form['field_layouts']['settings_wrapper']['layout_settings']$subform_state);
    }

    return $form;
  }

  /** * Gets the layout plugin for the currently selected field layout. * * @param \Drupal\field_layout\Display\EntityDisplayWithLayoutInterface $entity * The current form entity. * @param \Drupal\Core\Form\FormStateInterface $form_state * The current state of the form. * * @return \Drupal\Core\Layout\LayoutInterface * The layout plugin. */
'sort' => [
        'field' => 'name',
        'direction' => 'asc',
      ],
    ] + parent::defaultConfiguration();
  }

  /** * {@inheritdoc} */
  public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
    $form = parent::buildConfigurationForm($form$form_state);

    // Sorting is not possible for taxonomy terms because we use     // \Drupal\taxonomy\TermStorageInterface::loadTree() to retrieve matches.     $form['sort']['#access'] = FALSE;

    return $form;

  }

  /** * {@inheritdoc} */
'#return_value' => 'visible',
      ],
      'context_mapping' => [],
      'display_message' => [
        '#type' => 'textfield',
        '#title' => 'Display message',
        '#default_value' => 'My custom display message.',
      ],
    ];
    $form_state = new FormState();
    // Ensure there are no form elements that do not belong to the plugin.     $actual_form = $display_block->buildConfigurationForm([]$form_state);
    // Remove the visibility sections, as that just tests condition plugins.     unset($actual_form['visibility']$actual_form['visibility_tabs']);
    $this->assertEquals($expected_form$actual_form, 'Only the expected form elements were present.');

    $expected_build = [
      '#children' => 'My custom display message.',
    ];
    // Ensure the build array is proper.     $this->assertSame($expected_build$display_block->build(), 'The plugin returned the appropriate build array.');

    // Ensure the machine name suggestion is correct. In truth, this is actually
/** * {@inheritdoc} */
  public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
    $form['roles'] = [
      '#type' => 'checkboxes',
      '#title' => $this->t('When the user has the following roles'),
      '#default_value' => $this->configuration['roles'],
      '#options' => array_map('\Drupal\Component\Utility\Html::escape', user_role_names()),
      '#description' => $this->t('If you select no roles, the condition will evaluate to TRUE for all users.'),
    ];
    return parent::buildConfigurationForm($form$form_state);
  }

  /** * {@inheritdoc} */
  public function defaultConfiguration() {
    return [
      'roles' => [],
    ] + parent::defaultConfiguration();
  }

  
'view_name' => NULL,
        'display_name' => NULL,
        'arguments' => [],
      ],
    ] + parent::defaultConfiguration();
  }

  /** * {@inheritdoc} */
  public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
    $form = parent::buildConfigurationForm($form$form_state);

    $view_settings = $this->getConfiguration()['view'];
    $displays = Views::getApplicableViews('entity_reference_display');
    // Filter views that list the entity type we want, and group the separate     // displays by view.     $entity_type = $this->entityTypeManager->getDefinition($this->configuration['target_type']);
    $view_storage = $this->entityTypeManager->getStorage('view');

    $options = [];
    foreach ($displays as $data) {
      [$view_id$display_id] = $data;
      
Home | Imprint | This part of the site doesn't use cookies.