1 layout.api.php hook_layout_context_info()

Provides a list of all "contexts" available to Layout module.

A context is a named type of data, such as a "node" or "user". When creating a new context through this hook, you are providing a mapping between certain paths and a type of data. For example this hook may identify "node/%" as a known path that maps to node data. Any path that starts with "node/%" will automatically be assigned the node context, because its path is known. Besides defining paths that map to a certain kind of data, this hook must also specify how that content may be loaded.

Each type of context requires a class that provides information about the context. See the LayoutContext base class for additional documentation.

Return value

array Each item in the returned array of info should have the following keys:

  • title: The human-readable name of the context.
  • class: The name of a class to handle this context. This class should extend the LayoutContext class. The class should be registered in hook_autoload_info().
  • menu paths: Optional. An array of paths at which this context should be available. If left empty, this context can only be assigned through the UI by the user.
  • path placeholder: Optional. A string identifying the part of the URL from the menu paths array that contains this context's argument. This is only necessary if menu paths are also provided.
  • load callback: The name of a function that will load the argument from the URL and return the loaded data.
  • hidden: Optional. Boolean if this context should be shown in the UI.

See also

hook_autoload_info()

layout_layout_context_info()

LayoutContext

Related topics

File

core/modules/layout/layout.api.php, line 97
Describe hooks provided by the Layout module.

Code

function hook_layout_context_info() {
  $info['node'] = array(
    'title' => t('Node'),
    // Define the class which is used to handle this context.
    'class' => 'EntityLayoutContext',
    // Define menu paths where the node ID is a "known" context.
    'menu paths' => array(
      'node/%node',
      'node/%node/view',
    ),
    // Given the menu paths defined above, identify the part of the path that
    // is needed to generate this context.
    'path placeholder' => '%node',

    // Given an argument, the callback that will be responsible for loading the
    // main context data.
    'load callback' => 'node_load',
  );
  return $info;
}