You are here

easy_breadcrumb.module in Easy Breadcrumb 6

The Easy Breadcrumb module provides a block to be embedded in any page, typically at some place near the page's header. Easy Breadcrumb uses the URL (path alias) and the current page's title (when available) to obtain the breadcrumb's segments and its respective links. The resulting block will be something like: "Home >> Contact Us" or "Home / Contact us". Such presentation could vary depending on the configuration of the module.

File

easy_breadcrumb.module
View source
<?php

/**
 * @file
 * The Easy Breadcrumb module provides a block to be embedded in any page,
 * typically at some place near the page's header.
 * Easy Breadcrumb uses the URL (path alias) and the current page's title
 * (when available) to obtain the breadcrumb's segments and its respective
 * links. The resulting block will be something like:
 * "Home >> Contact Us" or "Home / Contact us".
 * Such presentation could vary depending on the configuration of the module.
 */

/**
 * Implements hook_perm().
 *
 * @return array
 *   An array of permission strings. The strings must not be wrapped with the
 *   t() function, since the string extractor takes care of extracting
 *   permission names defined in the perm hook for translation.
 */
function easy_breadcrumb_perm() {
  return array(
    'administer easy_breadcrumb',
  );
}

/**
 * Implements hook_init().
 */
function easy_breadcrumb_init() {
  require_once 'includes/EasyBreadcrumbConstants.inc';
  $disable_drupal_default_breadcrumb = variable_get(EasyBreadcrumbConstants::DB_VAR_DISABLE_DEFAULT_DRUPAL_BREADCRUMB, TRUE);
  if ($disable_drupal_default_breadcrumb) {

    // Sets the Drupal's default breadcrumb as an empty array to disable it.
    drupal_set_breadcrumb(array());
  }
}

/**
 * Implements hook_menu().
 *
 * @return array
 *   An array of menu items. Each menu item has a key corresponding to the
 *   Drupal path being registered. The corresponding array value is an
 *   associative array that may contain the following key-value pairs: "title":
 *   Required. The untranslated title of the menu item. "title callback":
 *   Function to generate the title; defaults to t(). If you require only the
 *   raw string to be output, set this to FALSE. "title arguments": Arguments to
 *   send to t() or your custom callback, with path component substitution as
 *   described above.
 */
function easy_breadcrumb_menu() {
  $items = array();
  $items['admin/settings/easy-breadcrumb'] = array(
    'title' => 'Easy Breadcrumb',
    'description' => "Controls settings for the module Easy Breadcrumb",
    'file' => 'includes/easy_breadcrumb.admin.inc',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      '_easy_breadcrumb_general_settings_form',
    ),
    'access arguments' => array(
      'administer easy_breadcrumb',
    ),
  );
  return $items;
}

/**
 * Implements hook_theme().
 *
 * @param array $existing
 *   An array of existing implementations that may be used for override
 *   purposes. This is primarily useful for themes that may wish to examine
 *   existing implementations to extract data (such as arguments) so that it may
 *   properly register its own, higher priority implementations.
 * @param string $type
 *   What 'type' is being processed. This is primarily useful so that themes
 *   tell if they are the actual theme being called or a parent theme. May be
 *   one of: module: A module is being checked for theme implementations.
 *   base_theme_engine: A theme engine is being checked for a theme which is a
 *   parent of the actual theme being used. theme_engine: A theme engine is
 *   being checked for the actual theme being used. base_theme: A base theme is
 *   being checked for theme implementations. theme: The actual theme in use is
 *   being checked.
 * @param string $theme
 *   The actual name of theme that is being being checked (mostly only useful
 *   for theme engine).
 * @param string $path
 *   The directory path of the theme or module, so that it doesn't need to be
 *   looked up.
 *
 * @return Assoc
 *   A keyed array of theme hooks.
 */
function easy_breadcrumb_theme($existing, $type, $theme, $path) {
  $path = drupal_get_path('module', 'easy_breadcrumb') . '/tpl';
  return array(
    'easy_breadcrumb' => array(
      'arguments' => array(
        'breadcrumb' => NULL,
        'segments_quantity' => NULL,
        'separator' => NULL,
      ),
    ),
  );
}

/**
 * Theme function for the breadcrumb.
 *
 * @param array $breadcrumb
 *   breadcrumb segments
 * @param int $segments_quantity
 *   segments number
 * @param string $separator
 *   segments separator
 *
 * @return string
 *   HTML for the themed breadcrumb.
 */
function theme_easy_breadcrumb($breadcrumb, $segments_quantity, $separator) {
  $html = '';
  if ($segments_quantity > 0) {
    $html .= '<div class="easy-breadcrumb">';
    for ($i = 0, $s = $segments_quantity - 1; $i < $segments_quantity; ++$i) {
      $html .= '<span class="easy-breadcrumb_segment-wrapper">' . $breadcrumb[$i] . '</span>';
      if ($i < $s) {
        $html .= '<span class="easy-breadcrumb_segment-separator"> ' . $separator . ' </span>';
      }
    }
    $html .= '</div>';
  }
  return $html;
}

/**
 * Implements hook_block().
 *
 * @param string $op
 *   What kind of information to retrieve about the block or blocks. Possible
 *   values: 'list': A list of all blocks defined by the module. 'configure':
 *   Configuration form for the block. 'save': Save the configuration options.
 *   'view': Process the block when enabled in a region in order to view its
 *   contents.
 * @param int $delta
 *   Which block to return (not applicable if $op is 'list'). See above for more
 *   information about delta values.
 * @param string $edit
 *   If $op is 'save', the submitted form data from the configuration form.
 *
 * @return array
 *   block.
 */
function easy_breadcrumb_block($op = 'list', $delta = 0, $edit = array()) {
  $blocks = array();
  if ($op === 'list') {
    $blocks[] = array(
      'info' => t('Easy Breadcrumb'),
      'cache' => BLOCK_CACHE_PER_PAGE,
    );
  }
  elseif ($op === 'view') {
    switch ($delta) {
      case 0:
        require_once 'includes/easy_breadcrumb.blocks.inc';
        $blocks['subject'] = NULL;
        $blocks['content'] = _easy_breadcrumb_block();
        break;
    }
  }
  return $blocks;
}

Functions

Namesort descending Description
easy_breadcrumb_block Implements hook_block().
easy_breadcrumb_init Implements hook_init().
easy_breadcrumb_menu Implements hook_menu().
easy_breadcrumb_perm Implements hook_perm().
easy_breadcrumb_theme Implements hook_theme().
theme_easy_breadcrumb Theme function for the breadcrumb.