You are here

public static function LayoutBuilderIdsConfigureSection::layoutBuilderIdsConfigureSectionFormValidation in Layout builder ids 2.0.x

File

src/EventSubscriber/LayoutBuilderIdsConfigureSection.php, line 82

Class

LayoutBuilderIdsConfigureSection
Add section id to layout builder sections.

Namespace

Drupal\layout_builder_ids\EventSubscriber

Code

public static function layoutBuilderIdsConfigureSectionFormValidation(array &$form, FormStateInterface $form_state) {

  // Get the layout builder id from the form.
  $layout_builder_id = $form_state
    ->getValue([
    'layout_settings',
    'layout_builder_id',
  ]);

  // Ensure that we are not checking for blank layout builder id.
  if ($layout_builder_id !== '') {

    // Put the id through the HTML getId to make sure
    // that we form a valid id.
    $layout_builder_id = Html::getId($layout_builder_id);

    // Check if we have a duplicate id somewhere.
    $found_id = layoutBuilderIdsService::layoutBuilderIdsCheckIds($layout_builder_id, $form_state, 'section');

    // If we have a duplicate id, then set the form error.
    if ($found_id) {

      // Set the form error on the layout builder id form element.
      $form_state
        ->setError($form['layout_settings']['layout_builder_id'], 'There is already a block or section with the ID "' . $layout_builder_id . '".');
    }
  }
}