1 layout.module layout_context_required_by_path($path)

Given a path with wildcard placeholders (%), determine the required contexts.

Parameters

string $path: The path for which required contexts should be retrieved.

Return value

array: An array of required contexts that match the given path.

File

core/modules/layout/layout.module, line 1729
The Layout module creates pages and wraps existing pages in layouts.

Code

function layout_context_required_by_path($path) {
  $required_context_info = array();

  // Populate each required context on the available known handlers.
  $all_info = _layout_get_all_info('layout_context');
  foreach ($all_info as $context_info) {
    foreach ($context_info['menu paths'] as $context_path) {
      // Remove named placeholders to just match on % symbols.
      $cleaned_path = preg_replace('/%[a-z0-9_]+/', '%', $context_path);

      // If it is an exact path match, assign the context without a position.
      if (strpos($path, '%') === FALSE && $path === $cleaned_path) {
        $required_context_info[$context_info['name']] = array(
          'plugin' => $context_info['name'],
        );
      }
      // If the path matches based on % wildcards, add this context as a
      // required context info in the correct order.
      elseif (strpos($path, $cleaned_path) === 0) {
        // Determine the argument placement within the path.
        $parts = explode('/', $context_path);
        foreach ($parts as $part_index => $part) {
          if ($part === $context_info['path placeholder']) {
            $required_context_info[$part_index] = array(
              'plugin' => $context_info['name'],
              'position' => $part_index,
            );
          }
        }
      }
    }
  }

  // If any wildcards are not filled, populate with a placeholder context
  // that can be modified.
  $parts = explode('/', $path);
  foreach ($parts as $part_index => $part) {
    if ($part === '%' && !isset($required_context_info[$part_index])) {
      $required_context_info[$part_index] = array(
        'plugin' => 'string',
        'position' => $part_index,
      );
    }
  }

  // Put the required contexts in order based on the path.
  ksort($required_context_info);

  // Convert required context info into objects.
  $required_contexts[$path] = array();
  foreach ($required_context_info as $context_position => $context_info) {
    $context = layout_create_context($context_info['plugin']);
    $context->required = TRUE;
    // String placeholders are not locked, allowing a new value to be set.
    $context->locked = $context_info['plugin'] !== 'string';
    $context->position = $context_position;
    $context->plugin = $context_info['plugin'];
    $required_contexts[$path][$context_position] = $context;
  }

  return $required_contexts[$path];
}