You are here

protected function LanguageSelectionPageBlock::blockAccess in Language Selection Page 8.2

Indicates whether the block should be shown.

Blocks with specific access checking should override this method rather than access(), in order to avoid repeating the handling of the $return_as_object argument.

Parameters

\Drupal\Core\Session\AccountInterface $account: The user session for which to check access.

Return value

\Drupal\Core\Access\AccessResult The access result.

Overrides BlockPluginTrait::blockAccess

See also

self::access()

File

src/Plugin/Block/LanguageSelectionPageBlock.php, line 103

Class

LanguageSelectionPageBlock
Provides a Language Selection Page block.

Namespace

Drupal\language_selection_page\Plugin\Block

Code

protected function blockAccess(AccountInterface $account) {
  $config = $this->configFactory
    ->get('language_selection_page.negotiation');
  $manager = $this->languageSelectionPageConditionManager;
  $defs = array_filter($manager
    ->getDefinitions(), static function ($value) {
    return isset($value['runInBlock']) && $value['runInBlock'];
  });
  foreach ($defs as $def) {

    /** @var \Drupal\Core\Executable\ExecutableInterface $condition_plugin */
    $condition_plugin = $manager
      ->createInstance($def['id'], $config
      ->get());
    if (!$manager
      ->execute($condition_plugin)) {
      return AccessResult::forbidden();
    }
  }
  return AccessResult::allowed();
}