taxonomy_display.install 4.96 KB
Newer Older
Cody Craven's avatar
Cody Craven committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
<?php
// $Id$

/**
 * @file
 * Install, update and uninstall functions for the taxonomy display module.
 */

/**
 * Implements hook_enable().
 *
 * Perform cleanup from while taxonomy_display was disabled.
 */
function taxonomy_display_enable() {
  watchdog('taxonomy_display', 'Taxonomy display is performing cleanup in response to being enabled, any changes made will be subsequently logged.', array(), WATCHDOG_INFO);

  // Retrieve all the existing vocabularies.
  $vocabularies = taxonomy_vocabulary_get_names();
  
  // Select taxonomy displays we have in the DB.
  $taxonomy_displays = db_select('taxonomy_display', 'td')
      ->fields('td', array('machine_name'))
      ->execute();

  // Loop through each display
  foreach ($taxonomy_displays as $taxonomy_display) {
    // If the vocabulary does not exist delete the taxonomy_display as it is now
    // an orphan.
    if (!isset($vocabularies[$taxonomy_display->machine_name])) {
30
      taxonomy_display_delete_taxonomy_dislpay($taxonomy_display->machine_name);
Cody Craven's avatar
Cody Craven committed
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
    }
  }
}

/**
 * Implements hook_schema().
 */
function taxonomy_display_schema() {
  $schema['taxonomy_display'] = array(
    'description' => 'Per vocabulary configuration for term pages.',
    'fields' => array(
      'machine_name' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
        'description' => 'The vocabulary machine name.',
      ),
      'term_display_plugin' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
        'description' => 'The plugin used to display the term.',
      ),
      'term_display_options' => array(
        'type' => 'blob',
        'not null' => FALSE,
        'size' => 'big',
        'serialize' => TRUE,
        'description' => 'The plugin data for the term display.',
      ),
      'associated_display_plugin' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
        'description' => 'The plugin used to display the associated content.',
      ),
      'associated_display_options' => array(
        'type' => 'blob',
        'not null' => FALSE,
        'size' => 'big',
        'serialize' => TRUE,
        'description' => 'The plugin data for the associated content display.',
      ),
77 78 79 80 81 82 83
      'add_feed' => array(
        'type' => 'int',
        'not null' => TRUE,
        'size' => 'tiny',
        'default' => 1,
        'description' => 'Whether to add Drupal\'s core feed.',
      ),
84 85 86 87 88 89 90 91 92 93 94 95 96 97
      'breadcrumb_display_plugin' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
        'description' => 'The plugin used to display the breadcrumb.',
      ),
      'breadcrumb_display_options' => array(
        'type' => 'blob',
        'not null' => FALSE,
        'size' => 'big',
        'serialize' => TRUE,
        'description' => 'The plugin data for the breadcrumb display.',
      ),
Cody Craven's avatar
Cody Craven committed
98 99 100 101 102 103 104 105 106 107
    ),
    'primary key' => array('machine_name'),
  );

  return $schema;
}

/**
 * Implements hook_uninstall().
 */
108
function taxonomy_display_uninstall() {}
109 110 111 112 113 114 115 116 117 118 119 120 121

/**
 * Implements hook_update_N().
 */
function taxonomy_display_update_7001() {
  // Weight taxonomy display to run after display suite for manipulation of
  // taxonomy display forms, see taxonomy_display_admin_form() and
  // http://drupal.org/node/1124346
  db_update('system')
    ->fields(array('weight' => 2))
    ->condition('name', 'taxonomy_display')
    ->execute();
}
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136

/**
 * Implements hook_update_N().
 */
function taxonomy_display_update_7002() {
  // Add feed field on taxonomy_display records in the storage system to give
  // administrative control of whether the feed should be added to term pages
  // see http://drupal.org/node/1126052
  db_add_field('taxonomy_display', 'add_feed', array(
    'type' => 'int',
    'not null' => TRUE,
    'size' => 'tiny',
    'default' => 1,
    'description' => 'Whether to add Drupal\'s core feed.',
  ));
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
}

/**
 * Implements hook_update_N().
 */
function taxonomy_display_update_7003() {
  // Add fields on taxonomy_display records in the storage system to add support
  // for our new breadcrumb plugin type.
  // See http://drupal.org/node/1247802

  // Add field with a default value for the core breadcrumb type.
  db_add_field('taxonomy_display', 'breadcrumb_display_plugin', array(
    'type' => 'varchar',
    'length' => 255,
    'not null' => TRUE,
    'default' => 'TaxonomyDisplayBreadcrumbDisplayHandlerCore',
    'description' => 'The plugin used to display the breadcrumb.',
  ));
  // Remove the default value now that existing records have been updated with
  // the core value.
  db_field_set_default('taxonomy_display', 'breadcrumb_display_plugin', '');

  db_add_field('taxonomy_display', 'breadcrumb_display_options', array(
    'type' => 'blob',
    'not null' => FALSE,
    'size' => 'big',
    'serialize' => TRUE,
    'description' => 'The plugin data for the breadcrumb display.',
  ));
}