You are here

class og_CrumbsMultiPlugin_groups_overview in Crumbs, the Breadcrumbs suite 7

Same name in this branch
  1. 7 plugins/crumbs.og.inc \og_CrumbsMultiPlugin_groups_overview
  2. 7 plugins/crumbs.og.2.inc \og_CrumbsMultiPlugin_groups_overview
Same name and namespace in other branches
  1. 7.2 plugins/crumbs.og.inc \og_CrumbsMultiPlugin_groups_overview
  2. 7.2 plugins/crumbs.og.2.inc \og_CrumbsMultiPlugin_groups_overview

Make $groups_overview_path the parent path for group nodes. The priorities can be configured per group node type.

This class is never instantiated in native Crumbs, but it can be used in custom modules.

Hierarchy

Expanded class hierarchy of og_CrumbsMultiPlugin_groups_overview

File

plugins/crumbs.og.2.inc, line 102

View source
class og_CrumbsMultiPlugin_groups_overview implements crumbs_MultiPlugin {
  protected $groupsOverviewPaths;

  /**
   * @param array|string $groups_overview_paths
   *   Either
   *     just one parent path,
   *   or
   *     an array of parent paths per node type. E.g.
   *     array(
   *       'city_group' => 'city-groups',
   *       'sports_group' => 'groups/sports',
   *     )
   *     The user is responsible to make sure that these are all group types.
   */
  function __construct($groups_overview_paths) {
    $this->groupsOverviewPath = $groups_overview_paths;
  }

  /**
   * Tells Crumbs about available rules.
   *
   * @param crumbs_InjectedAPI_describeMultiPlugin $api
   *   API object with methods that allow describing the plugin.
   */
  function describe($api) {
    if (is_array($this->groupsOverviewPaths)) {
      foreach ($this->groupsOverviewPaths as $type => $parent_path) {
        $api
          ->addRule($type->type);
      }
    }
    else {
      $types = node_type_get_types();
      foreach ($types as $type) {
        if (og_is_group_type('node', $type->type)) {
          $api
            ->addRule($type->type);
        }
      }
    }
  }

  /**
   * Find a parent path for node/%, if that node is a group.
   */
  function findParent__node_x($path, $item) {
    $node = $item['map'][1];

    // Load the node if it hasn't been loaded due to a missing wildcard loader.
    $node = is_numeric($node) ? node_load($node) : $node;
    if (og_is_group('node', $node)) {
      return $this
        ->getGroupsOverviewPath($node);
    }
  }

  /**
   * Overridable helper method to actually find the parent path,
   * once we know it is a group node.
   *
   * @param stdClass $group_node
   *   The node at this path, of which we know it is a group node.
   */
  protected function getGroupsOverviewPath($group_node) {
    if (is_array($this->groupsOverviewPaths)) {
      if (isset($this->groupsOverviewPaths[$group_node->type])) {
        return array(
          $group_node->type => $this->groupsOverviewPaths[$group_node->type],
        );
      }

      // If the node type is not in the array, we return nothing!
    }
    else {
      return array(
        $node->type => $this->groupsOverviewPaths,
      );
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
og_CrumbsMultiPlugin_groups_overview::$groupsOverviewPaths protected property
og_CrumbsMultiPlugin_groups_overview::describe function Tells Crumbs about available rules. Overrides crumbs_MultiPlugin::describe
og_CrumbsMultiPlugin_groups_overview::findParent__node_x function Find a parent path for node/%, if that node is a group.
og_CrumbsMultiPlugin_groups_overview::getGroupsOverviewPath protected function Overridable helper method to actually find the parent path, once we know it is a group node.
og_CrumbsMultiPlugin_groups_overview::__construct function