You are here

public function NotConditionPluginBase::buildConfigurationForm in Block Visibility Conditions 8

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 ConditionPluginBase::buildConfigurationForm

File

src/Plugin/Condition/NotConditionPluginBase.php, line 97

Class

NotConditionPluginBase
Provides a 'Not {ContentEntityType}'-base condition.

Namespace

Drupal\block_visibility_conditions\Plugin\Condition

Code

public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
  $form = parent::buildConfigurationForm($form, $form_state);

  // Disallow negation of this condition.
  unset($form['negate']);

  // Create list of content types.
  $options = [];
  $node_types = $this->entityTypeManager
    ->getStorage(static::CONTENT_ENTITY_TYPE)
    ->loadMultiple();
  foreach ($node_types as $type) {
    $options[$type
      ->id()] = $type
      ->label();
  }
  $form['bundles'] = [
    '#title' => $this->contentEntityType
      ->getLabel(),
    '#description' => $this
      ->t('The %content_entity_type_label(s) to hide the block on. The block will still be shown on all other pages, including non-%bundle_label pages.<br>This differs from the negated condition "%content_entity_type_label", which will only be evaluated on %bundle_label pages, which means the block won\'t be shown on other pages like views.', [
      '%content_entity_type_label' => $this->contentEntityType
        ->getLabel(),
      '%bundle_label' => $this->bundle
        ->getLabel(),
    ]),
    '#type' => 'checkboxes',
    '#options' => $options,
    '#default_value' => $this->configuration['bundles'],
  ];
  return $form;
}