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.');
  }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.