You are here

public function EntityMatcher::buildConfigurationForm in Linkit 8.4

Same name and namespace in other branches
  1. 8.5 src/Plugin/Linkit/Matcher/EntityMatcher.php \Drupal\linkit\Plugin\Linkit\Matcher\EntityMatcher::buildConfigurationForm()

Form constructor.

Plugin forms are embedded in other forms. In order to know where the plugin form is located in the parent form, #parents and #array_parents must be known, but these are not available during the initial build phase. In order to have these properties available when building the plugin form's elements, let this method return a form element that has a #process callback and build the rest of the form in the callback. By the time the callback is executed, the element's #parents and #array_parents properties will have been set by the form API. For more documentation on #parents and #array_parents, see \Drupal\Core\Render\Element\FormElement.

Parameters

array $form: An associative array containing the initial structure of the plugin form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form. Calling code should pass on a subform state created through \Drupal\Core\Form\SubformState::createForSubform().

Return value

array The form structure.

Overrides PluginFormInterface::buildConfigurationForm

4 calls to EntityMatcher::buildConfigurationForm()
FileMatcher::buildConfigurationForm in src/Plugin/Linkit/Matcher/FileMatcher.php
Form constructor.
NodeMatcher::buildConfigurationForm in src/Plugin/Linkit/Matcher/NodeMatcher.php
Form constructor.
TermMatcher::buildConfigurationForm in src/Plugin/Linkit/Matcher/TermMatcher.php
Form constructor.
UserMatcher::buildConfigurationForm in src/Plugin/Linkit/Matcher/UserMatcher.php
Form constructor.
4 methods override EntityMatcher::buildConfigurationForm()
FileMatcher::buildConfigurationForm in src/Plugin/Linkit/Matcher/FileMatcher.php
Form constructor.
NodeMatcher::buildConfigurationForm in src/Plugin/Linkit/Matcher/NodeMatcher.php
Form constructor.
TermMatcher::buildConfigurationForm in src/Plugin/Linkit/Matcher/TermMatcher.php
Form constructor.
UserMatcher::buildConfigurationForm in src/Plugin/Linkit/Matcher/UserMatcher.php
Form constructor.

File

src/Plugin/Linkit/Matcher/EntityMatcher.php, line 149
Contains \Drupal\linkit\Plugin\Linkit\Matcher\EntityMatcher.

Class

EntityMatcher
Plugin annotation @Matcher( id = "entity", label = @Translation("Entity"), deriver = "\Drupal\linkit\Plugin\Derivative\EntityMatcherDeriver" )

Namespace

Drupal\linkit\Plugin\Linkit\Matcher

Code

public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
  $entity_type = $this->entityManager
    ->getDefinition($this->target_type);
  $form['result_description'] = [
    '#title' => $this
      ->t('Result description'),
    '#type' => 'textfield',
    '#default_value' => $this->configuration['result_description'],
    '#size' => 120,
    '#maxlength' => 255,
    '#weight' => -100,
  ];
  $this
    ->insertTokenList($form, [
    $this->target_type,
  ]);

  // Filter the possible bundles to use if the entity has bundles.
  if ($entity_type
    ->hasKey('bundle')) {
    $bundle_options = [];
    foreach ($this->entityManager
      ->getBundleInfo($this->target_type) as $bundle_name => $bundle_info) {
      $bundle_options[$bundle_name] = $bundle_info['label'];
    }
    $form['bundles'] = [
      '#type' => 'checkboxes',
      '#title' => $this
        ->t('Restrict to the selected bundles'),
      '#options' => $bundle_options,
      '#default_value' => $this->configuration['bundles'],
      '#description' => $this
        ->t('If none of the checkboxes is checked, allow all bundles.'),
      '#element_validate' => [
        [
          get_class($this),
          'elementValidateFilter',
        ],
      ],
      '#weight' => -50,
    ];

    // Group the results by bundle.
    $form['group_by_bundle'] = [
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Group by bundle'),
      '#default_value' => $this->configuration['group_by_bundle'],
      '#weight' => -50,
    ];
  }
  return $form;
}