You are here

custom_breadcrumbs_taxonomy.install in Custom Breadcrumbs 7.2

Same filename and directory in other branches
  1. 6.2 custom_breadcrumbs_taxonomy/custom_breadcrumbs_taxonomy.install

Install file for the custom_breadcrumbs_taxonomy module.

File

custom_breadcrumbs_taxonomy/custom_breadcrumbs_taxonomy.install
View source
<?php

/**
 * @file
 * Install file for the custom_breadcrumbs_taxonomy module.
 */

/**
 * Implements hook_enable().
 */
function custom_breadcrumbs_taxonomy_enable() {

  // Sets weight of custom_breadcrumbs_taxonomy to be greater than taxonomy,
  // views, and custom_breadcrumbs.
  $max_weight = custom_breadcrumbs_taxonomy_minimum_module_weight();
  $current_weight = _custom_breadcrumbs_get_module_weight(array(
    'custom_breadcrumbs_taxonomy',
  ));
  if ($current_weight['custom_breadcrumbs_taxonomy'] < $max_weight) {
    drupal_set_message(t('Increasing the weight of custom_breadcrumbs_taxonomy for use with other modules.'));
    db_update('system')
      ->fields(array(
      'weight' => $max_weight,
    ))
      ->condition('name', 'custom_breadcrumbs_taxonomy')
      ->execute();
    variable_set('menu_rebuild_needed', TRUE);
  }
}

/**
 * Implements hook_install().
 */
function custom_breadcrumbs_taxonomy_install() {
  $t = get_t();

  // If taxonomy_breadcrumbs is installed, copy term and vocab breadcrumb to
  // custom_breadcrumbs_taxonomy tables.
  if (module_exists('taxonomy_breadcrumb')) {

    // Search for taxonomy_breadcrumb term and vocabulary breadcrumbs and copy
    // to new custom_breadcrumb_taxonomy tables.
    drupal_set_message($t('Taxonomy breadcrumb module is enabled. Copying breadcrumbs from {taxonomy_breadcrumb_term} and {taxonomy_breadcrumb_vocabulary} to custom_breadcrumbs_taxonomy ...'));
    $result = db_query("SELECT * FROM {taxonomy_breadcrumb_term}");
    $found = 0;
    foreach ($result as $breadcrumb) {
      db_insert('custom_breadcrumbs_taxonomy_term')
        ->fields(array(
        'paths' => $breadcrumb->path,
        'tid' => $breadcrumb->tid,
        'visibility_php' => '',
      ))
        ->execute();
      ++$found;
    }
    $result = db_query("SELECT * FROM {taxonomy_breadcrumb_vocabulary}");
    foreach ($result as $breadcrumb) {
      db_insert('custom_breadcrumbs_taxonomy_vocabulary')
        ->fields(array(
        'paths' => $breadcrumb->path,
        'vid' => $breadcrumb->vid,
        'visibility_php' => '',
      ))
        ->execute();
      ++$found;
    }

    // Use variable definitions already set for taxonomy_breadcrumb.
    variable_set('custom_breadcrumbs_taxonomy_home', variable_get('taxonomy_breadcrumb_home', $t('Home')));
    variable_set('custom_breadcrumbs_taxonomy_show_current_term', variable_get('taxonomy_breadcrumb_show_current_term', TRUE));
    variable_set('custom_breadcrumbs_taxonomy_include_node_title', variable_get('taxonomy_breadcrumb_include_node_title', FALSE));
    variable_set('custom_breadcrumbs_taxonomy_include_nodes', variable_get('taxonomy_breadcrumb_include_nodes', FALSE));
    variable_set('custom_breadcrumbs_taxonomy_node_types', variable_get('taxonomy_breadcrumb_node_types', TAXONOMY_BREADCRUMB_NODE_TYPES_DEFAULT));
    define('CUSTOM_BREADCRUMBS_TAXONOMY_NODE_TYPES_DEFAULT', TAXONOMY_BREADCRUMB_NODE_TYPES_DEFAULT);

    // Set custom_breadcrumbs_taxonomy to use taxonomy hierarchy in constructing
    // breadcrumb.
    variable_set('custom_breadcrumbs_taxonomy_use_hierarchy', TRUE);
    if ($found > 0) {
      drupal_set_message(format_plural($found, 'Copied 1 breadcrumb.', 'Copied @count breadcrumbs.'));
      drupal_set_message($t('You can now disable taxonomy_breadcrumb, and test custom_breadcrumbs_taxonomy.'));
    }
    else {
      drupal_set_message($t('No taxonomy_breadcrumbs were found'));
    }
  }
  drupal_set_message($t('Custom Breadcrumbs for Taxonomy Terms and Vocabularies: Taxonomy based breadcrumbs should now appear on node pages and taxonomy/term pages.  For the most common applications this module will work "out of the box" and no further configuration is necessary.  If customization is desired settings can be changed on the ') . l($t('administration page'), 'admin/config/user-interface/custom-breadcrumbs') . '.');
}

/**
 * Implements hook_uninstall().
 */
function custom_breadcrumbs_taxonomy_uninstall() {

  // Remove persistent variables.
  db_delete('variable')
    ->condition('name', 'custom_breadcrumbs_taxonomy_%', 'like')
    ->execute();
}

/**
 * Implements hook_schema().
 */
function custom_breadcrumbs_taxonomy_schema() {
  $schema['custom_breadcrumbs_taxonomy_term'] = array(
    'description' => 'Stores custom breadcrumbs for taxonomy terms',
    'fields' => array(
      'bid' => array(
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'description' => 'Unique identifier for the {custom_breadcrumbs_taxonomy} breadcrumbs.',
      ),
      'name' => array(
        'type' => 'varchar',
        'length' => 128,
        'not null' => FALSE,
        'description' => 'An optional name for the custom breadcrumb.',
      ),
      'titles' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
        'description' => 'A title for the breadcrumb link.',
      ),
      'paths' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => FALSE,
        'description' => 'A path for the breadcrumb link.',
      ),
      'tid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'description' => 'The taxonomy term id for this breadcrumb.',
      ),
      'visibility_php' => array(
        'type' => 'text',
        'not null' => TRUE,
        'size' => 'medium',
        'description' => 'An optional PHP snippet to control the {custom_breadcrumbs_views} visibility.',
      ),
      'language' => array(
        'type' => 'varchar',
        'length' => 12,
        'not null' => TRUE,
        'default' => '',
        'description' => 'The language this breadcrumb is for; if blank, the breadcrumb will be used for unknown languages.',
      ),
    ),
    'indexes' => array(
      'language' => array(
        'language',
      ),
      'tid_language' => array(
        'tid',
        'language',
      ),
    ),
    'primary key' => array(
      'bid',
    ),
  );
  $schema['custom_breadcrumbs_taxonomy_vocabulary'] = array(
    'description' => 'Stores custom breadcrumbs for taxonomy vocabularies',
    'fields' => array(
      'bid' => array(
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'description' => 'Unique identifier for the {custom_breadcrumbs_taxonomy} breadcrumbs.',
      ),
      'name' => array(
        'type' => 'varchar',
        'length' => 128,
        'not null' => FALSE,
        'description' => 'An optional name for the custom breadcrumb.',
      ),
      'titles' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
        'description' => 'A titles for the breadcrumb link.',
      ),
      'paths' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => FALSE,
        'description' => 'A paths for the breadcrumb link.',
      ),
      'vid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'description' => 'The taxonomy vocabulary id for this breadcrumb.',
      ),
      'visibility_php' => array(
        'type' => 'text',
        'not null' => TRUE,
        'size' => 'medium',
        'description' => 'An optional PHP snippet to control the {custom_breadcrumbs_views} visibility.',
      ),
      'language' => array(
        'type' => 'varchar',
        'length' => 12,
        'not null' => TRUE,
        'default' => '',
        'description' => 'The language this breadcrumb is for; if blank, the breadcrumb will be used for unknown languages.',
      ),
    ),
    'indexes' => array(
      'language' => array(
        'language',
      ),
      'vid_language' => array(
        'vid',
        'language',
      ),
    ),
    'primary key' => array(
      'bid',
    ),
  );
  return $schema;
}

/**
 * Implements hook_update_N().
 *
 * Sets weight of custom_breadcrumbs_taxonomy to be greater than taxonomy,
 * views, and custom_breadcrumbs.
 */
function custom_breadcrumbs_taxonomy_update_6000() {
  $tax_weight = (int) db_query("SELECT weight FROM {system} WHERE name = :name", array(
    ':name' => 'taxonomy',
  ))
    ->fetchField();
  $views_weight = (int) db_query("SELECT weight FROM {system} WHERE name = :name", array(
    ':name' => 'views',
  ))
    ->fetchField();
  $cb_weight = (int) db_query("SELECT weight FROM {system} WHERE name = :name", array(
    ':name' => 'custom_breadcrumbs',
  ))
    ->fetchField();
  $cb_tax_weight = max($tax_weight, $views_weight, $cb_weight) + 2;
  db_update('system')
    ->fields(array(
    'weight' => $cb_tax_weight,
  ))
    ->condition('type', 'module')
    ->condition('name', 'custom_breadcrumbs_taxonomy')
    ->execute();
  return t('Adjusted the custom_ breadcrumbs_taxonomy module weight to be greater than custom_breadcrumbs, taxonomy and views.');
}

/**
 * Implements hook_update_N().
 *
 * @codingStandardsIgnoreStart
 * Adds name fields to custom breadcrumbs taxonomy tables for improved
 * organization of custom breadcrumbs.
 * @codingStandardsIgnoreEnd
 */
function custom_breadcrumbs_taxonomy_update_6200() {
  db_add_field('custom_breadcrumbs_taxonomy_term', 'name', array(
    'type' => 'varchar',
    'length' => 128,
    'NOT NULL' => FALSE,
    'description' => 'An optional name for the custom breadcrumb.',
  ));
  db_add_field('custom_breadcrumbs_taxonomy_vocabulary', 'name', array(
    'type' => 'varchar',
    'length' => 128,
    'NOT NULL' => FALSE,
    'description' => 'An optional name for the custom breadcrumb.',
  ));
  return t('Added name fields to custom breadcrumbs taxonomy tables for improved organization of custom breadcrumbs.');
}