You are here

public function UltimenuTool::isAllowedBlock in Ultimenu 8.2

Checks if user has access to view a block, including its path visibility.

File

src/UltimenuTool.php, line 248

Class

UltimenuTool
Provides Ultimenu utility methods.

Namespace

Drupal\ultimenu

Code

public function isAllowedBlock(EntityInterface $block, array $config) {
  $access = $block
    ->access('view', $this->currentUser, TRUE);
  $allowed = $access
    ->isAllowed();

  // If not allowed, checks block visibility by paths and roles.
  // Ensures we are on the same page before checking visibility by roles.
  if (!$allowed && ($match = $this
    ->isPageMatch($block, $config))) {

    // If we have visibility by roles, still restrict access accordingly.
    if ($roles = $this
      ->getAllowedRoles($block)) {
      $allowed = $this
        ->isAllowedByRole($block, $roles);
    }
    else {

      // Assumes visibility by paths in the least.
      $allowed = !empty($match);
    }
  }
  return $allowed;
}