You are here

class forum_CrumbsMonoPlugin_forumThreadCreate in Crumbs, the Breadcrumbs suite 7

Same name and namespace in other branches
  1. 7.2 plugins/crumbs.forum.inc \forum_CrumbsMonoPlugin_forumThreadCreate

Hierarchy

Expanded class hierarchy of forum_CrumbsMonoPlugin_forumThreadCreate

File

plugins/crumbs.forum.inc, line 109

View source
class forum_CrumbsMonoPlugin_forumThreadCreate implements crumbs_MonoPlugin {
  function describe($api) {
    return t('Let /forum/456 be the parent path of /node/789, if node 789 is a thread in this forum.');
  }

  /**
   * Set a parent path for e.g. node/add/(type)/(tid), where
   * - (type) a forum-enabled node type, e.g. "forum".
   * - (tid) is the forum term tid.
   */
  function findParent($path, $item) {
    if (substr($path, 0, 9) === 'node/add/' && preg_match('#^node/add/([^/]+)/(\\d+)$#', $path, $m)) {
      $type = $m[1];
      $tid = (int) $m[2];

      // We need to find out if the node type is forum-enabled.
      // See _forum_node_check_node_type() in forum.module.
      $field = field_info_instance('node', 'taxonomy_forums', $type);
      if (is_array($field)) {

        // That's a node/add/(type)/(tid) page for a forum-enabled node type.
        $term = taxonomy_term_load($item['original_map'][3]);
        if ($term && $term->vocabulary_machine_name === 'forums') {
          return 'forum/' . $term->tid;
        }
      }
    }
  }

  /**
   * Set a breadcrumb item title for e.g. node/add/(type)/(tid), where
   * - (type) a forum-enabled node type, e.g. "forum".
   * - (tid) is the forum term tid.
   */
  function findTitle($path, $item) {
    if (substr($path, 0, 9) === 'node/add/' && preg_match('#^node/add/([^/]+)/(\\d+)$#', $path, $m)) {
      $type = $m[1];
      $tid = (int) $m[2];

      // We need to find out if the node type is forum-enabled.
      // See _forum_node_check_node_type() in forum.module.
      $field = field_info_instance('node', 'taxonomy_forums', $type);
      if (is_array($field)) {

        // That's a node/add/(type)/(tid) page for a forum-enabled node type.
        $term = taxonomy_term_load($item['original_map'][3]);
        if ($term && $term->vocabulary_machine_name === 'forums') {
          return $this
            ->newTopicTitle($type);
        }
      }
    }
  }

  /**
   * Method that can be overwritten by subclasses.
   */
  protected function newTopicTitle($type) {
    return t('New topic');
  }

}

Members

Namesort descending Modifiers Type Description Overrides
forum_CrumbsMonoPlugin_forumThreadCreate::describe function Overrides crumbs_MonoPlugin::describe
forum_CrumbsMonoPlugin_forumThreadCreate::findParent function Set a parent path for e.g. node/add/(type)/(tid), where
forum_CrumbsMonoPlugin_forumThreadCreate::findTitle function Set a breadcrumb item title for e.g. node/add/(type)/(tid), where
forum_CrumbsMonoPlugin_forumThreadCreate::newTopicTitle protected function Method that can be overwritten by subclasses.