You are here

public function ShareEverywhereService::isRestricted in Share Everywhere 8

Same name and namespace in other branches
  1. 2.x src/ShareEverywhereService.php \Drupal\share_everywhere\ShareEverywhereService::isRestricted()

Determines if module is restricted to show or not on certain pages.

Parameters

string $view_mode: Entity view mode.

Return value

bool Returns TRUE or FALSE.

Overrides ShareEverywhereServiceInterface::isRestricted

File

src/ShareEverywhereService.php, line 162

Class

ShareEverywhereService
Defines a ShareEverywhereService service.

Namespace

Drupal\share_everywhere

Code

public function isRestricted($view_mode) {
  $config = $this->configFactory
    ->get('share_everywhere.settings');
  switch ($view_mode) {
    case 'search_result':
    case 'search_index':
    case 'rss':
      return TRUE;
  }
  $restricted_pages = $config
    ->get('restricted_pages.pages');
  if (is_array($restricted_pages) && !empty($restricted_pages)) {
    $restriction_type = $config
      ->get('restricted_pages.type');

    // Replace a single / with <front> so it matches with the front path.
    if (($index = array_search('/', $restricted_pages)) !== FALSE) {
      $restricted_pages[$index] = '<front>';
    }

    /** @var \Drupal\system\Plugin\Condition\RequestPath $request_path_condition */
    $request_path_condition = $this->conditionManager
      ->createInstance('request_path', [
      'pages' => implode("\n", $restricted_pages),
      'negate' => $restriction_type == 'show' ? TRUE : FALSE,
    ]);
    return $request_path_condition
      ->execute();
  }
  return FALSE;
}