You are here

breadcrumb_extra_field.module in Breadcrumb Extra Field 7

Same filename and directory in other branches
  1. 8 breadcrumb_extra_field.module
  2. 2.x breadcrumb_extra_field.module

Main module file.

File

breadcrumb_extra_field.module
View source
<?php

/**
 * @file
 * Main module file.
 */
define('BREADCRUMB_EXTRA_FIELD_ALLOWED_ENTITY_TYPES', serialize(array(
  'node',
  'user',
  'taxonomy_term',
  'comment',
  'bean',
)));
define('BREADCRUMB_EXTRA_FIELD_ADMIN', 'breadcrumb_extra_field_admin');

/**
 * Implements hook_field_extra_fields().
 */
function breadcrumb_extra_field_field_extra_fields() {
  $admin = variable_get('breadcrumb_extra_field_admin', array());
  $entity_info = entity_get_info();
  $extra = [];
  foreach ($entity_info as $entity_type_key => $entity_type) {
    $bundle_options = array();

    // Add breadcrumb to configured entity types.
    foreach ($entity_type['bundles'] as $bundle_key => $bundle) {
      if (!empty($admin[$entity_type_key]) && isset($admin[$entity_type_key][$bundle_key]) && $admin[$entity_type_key][$bundle_key]) {
        $extra[$entity_type_key][$bundle_key] = array(
          'display' => array(
            'breadcrumb_extra_field' => array(
              'label' => t('Breadcrumb'),
              'description' => t('Breadcrumb'),
              'weight' => 0,
            ),
          ),
        );
      }
    }
  }
  return $extra;
}

/**
 * Implements hook_entiy_view().
 */
function breadcrumb_extra_field_entity_view($entity, $type, $view_mode, $langcode) {
  list(, , $bundle) = entity_extract_ids($type, $entity);
  $extra_fields = field_extra_fields_get_display($type, $bundle, $view_mode);
  if (!empty($extra_fields['breadcrumb_extra_field']) && $extra_fields['breadcrumb_extra_field']['visible'] == TRUE) {

    // Add extra field value only if showed.
    $entity->content['breadcrumb_extra_field'] = array(
      '#type' => 'container',
      '#attributes' => array(
        'class' => array(
          'field',
          'breadcrumb-extra-field',
        ),
      ),
      'breadcrumb' => array(
        '#theme' => 'breadcrumb',
        '#weight' => $extra_fields['breadcrumb_extra_field']['weight'],
        '#breadcrumb' => drupal_get_breadcrumb(),
      ),
    );
  }
}

/**
 * Implements hook_permission().
 */
function breadcrumb_extra_field_permission() {
  return array(
    'administer breadcrumb extra field' => array(
      'title' => t('Administer breadcrumb extra field'),
      'description' => t('Perform administration tasks for breadcrumb extra field.'),
    ),
  );
}

/**
 * Implements hook_menu().
 */
function breadcrumb_extra_field_menu() {
  $items = array();
  $items['admin/structure/breadcrumb-extra-field'] = array(
    'title' => 'Settings',
    'access callback' => 'user_access',
    'access arguments' => array(
      'administer breadcrumb extra field',
    ),
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'breadcrumb_extra_field_admin',
    ),
    'type' => MENU_LOCAL_TASK,
    'weight' => 1,
    'file' => 'breadcrumb_extra_field.admin.inc',
  );
  return $items;
}