Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Block.php

function Block::validateRegion

Validates that a region exists in the active theme.

Parameters

null|string $region: The region to validate.

\Symfony\Component\Validator\Context\ExecutionContextInterface $context: The validation context.

File

core/modules/block/src/Entity/Block.php, line 380

Class

Block
Defines a Block configuration entity class.

Namespace

Drupal\block\Entity

Code

public static function validateRegion(?string $region, ExecutionContextInterface $context) : void {
    if ($theme = $context->getRoot()
        ->get('theme')
        ->getValue()) {
        if (!array_key_exists($region, system_region_list($theme))) {
            $context->addViolation('This is not a valid region of the %theme theme.', [
                '%theme' => $theme,
            ]);
        }
    }
    else {
        $context->addViolation('This block does not say which theme it appears in.');
    }
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal