You are here

function _shadowbox_activation in Shadowbox 8

Same name and namespace in other branches
  1. 7.4 shadowbox.module \_shadowbox_activation()
  2. 7.3 shadowbox.module \_shadowbox_activation()

Verify that Shadowbox should be activation for the current URL.

Return value

TRUE if Shadowbox should be activation for the current page.

3 calls to _shadowbox_activation()
FileShadowboxFormatter::viewElements in file_shadowbox/lib/Drupal/file_shadowbox/Plugin/Field/FieldFormatter/FileShadowboxFormatter.php
Builds a renderable array for a field value.
ImageShadowboxFormatter::viewElements in image_shadowbox/lib/Drupal/image_shadowbox/Plugin/Field/FieldFormatter/ImageShadowboxFormatter.php
Builds a renderable array for a field value.
shadowbox_page_build in ./shadowbox.module
Implements hook_page_build().

File

./shadowbox.module, line 176
Shadowbox, a JavaScript media viewer application for displaying content in a modal dialogue.

Code

function _shadowbox_activation() {
  $config = \Drupal::config('shadowbox.settings');
  $pages = $config
    ->get('shadowbox_pages');
  $activation = $config
    ->get('shadowbox_activation_type');

  // Match path if necessary.
  if ($pages) {

    // Convert path to lowercase. This allows comparison of the same path with
    // different case. Ex: /Page, /page, /PAGE.
    $lowercase_pages = drupal_strtolower($pages);
    if ($activation < SHADOWBOX_ACTIVATION_PHP) {
      $current_path = current_path();

      // Convert the Drupal path to lowercase.
      $path_alias = \Drupal::service('path.alias_manager.cached')
        ->getPathByAlias($current_path);
      $path = drupal_strtolower($path_alias);

      // Compare the lowercase internal and lowercase path alias (if any).
      $page_match = drupal_match_path($path, $lowercase_pages);
      if ($path != $current_path) {
        $page_match = $page_match || drupal_match_path($current_path, $lowercase_pages);
      }

      // When $ACTIVATION has a value of 0 (SHADOWBOX_ACTIVATION_NOTLISTED),
      // shadowbox is added on all pages except those listed in $pages.
      // When set to 1 (SHADOWBOX_ACTIVATION_LISTED), it is added only on those
      // pages listed in $pages.
      $page_match = !($activation xor $page_match);
    }
    elseif (\Drupal::moduleHandler()
      ->moduleExists('php')) {
      $page_match = php_eval($pages);
    }
    else {
      $page_match = FALSE;
    }
  }
  else {
    $page_match = TRUE;
  }
  return $page_match;
}