You are here

layout_builder_restrictions_by_region.module in Layout Builder Restrictions 8.2

Module file for Layout Builder Restrictions by Region.

File

modules/layout_builder_restrictions_by_region/layout_builder_restrictions_by_region.module
View source
<?php

/**
 * @file
 * Module file for Layout Builder Restrictions by Region.
 */
use Drupal\Core\Form\FormStateInterface;
use Drupal\layout_builder_restrictions_by_region\Form\FormAlter;

/**
 * Implements hook_form_FORM_ID_alter() for the entity view display edit form.
 */
function layout_builder_restrictions_by_region_form_entity_view_display_edit_form_alter(&$form, FormStateInterface &$form_state, $form_id) {
  $entity_view_mode_restriction_active = TRUE;
  if ($config = \Drupal::config('layout_builder_restrictions.plugins')
    ->get('plugin_config')) {

    // Provide the per view mode restriction UI *unless* the plugin is disabled.
    if (isset($config['entity_view_mode_restriction_by_region']) && $config['entity_view_mode_restriction_by_region']['enabled'] == FALSE) {
      $entity_view_mode_restriction_active = FALSE;
    }
  }
  if ($entity_view_mode_restriction_active) {
    \Drupal::classResolver(FormAlter::class)
      ->alterEntityViewDisplayForm($form, $form_state, $form_id);
  }
}

Functions