You are here

public function MoveBlockForm::validateForm in Layout Builder Restrictions 8.2

Form validation handler.

Parameters

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

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Overrides FormBase::validateForm

File

src/Form/MoveBlockForm.php, line 22

Class

MoveBlockForm
Provides a form for moving a block.

Namespace

Drupal\layout_builder_restrictions\Form

Code

public function validateForm(array &$form, FormStateInterface $form_state) {
  $to_region = $this
    ->getSelectedRegion($form_state);
  $to_delta = $this
    ->getSelectedDelta($form_state);
  $from_delta = $this->delta;

  // $original_section = $this->sectionStorage->getSection($from_delta);
  // $component = $original_section->getComponent($this->uuid);
  // Retrieve defined Layout Builder Restrictions plugins.
  $layout_builder_restrictions_manager = \Drupal::service('plugin.manager.layout_builder_restriction');
  $restriction_definitions = $layout_builder_restrictions_manager
    ->getDefinitions();
  foreach ($restriction_definitions as $restriction_definition) {

    // @todo: respect ordering of plugins (see #3045266)
    $plugin_instance = $layout_builder_restrictions_manager
      ->createInstancE($restriction_definition['id']);
    $block_status = $plugin_instance
      ->blockAllowedinContext($this->sectionStorage, $from_delta, $to_delta, $to_region, $this->uuid, NULL);
    if ($block_status !== TRUE) {
      $form_state
        ->setErrorByName('region', $block_status);
    }
  }
}