View source
<?php
function views_term_hierarchy_weight_field_schema_alter(&$schema) {
$schema['taxonomy_term_data']['fields']['hweight'] = array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'description' => 'The weight of this term in the hierarchical tree. Added by the Views Term Hierarchy Weight Field module.',
);
$schema['taxonomy_term_data']['fields']['hdepth'] = array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'description' => 'The depth of this term in the hierarchical tree. Added by the Views Term Hierarchy Weight Field module.',
);
$schema['menu_links']['fields']['hweight'] = array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'description' => 'The weight of this menu link in the hierarchical tree. Added by the Views Term Hierarchy Weight Field module.',
);
if (module_exists('entity_menu_links')) {
$schema['menu_links_revision']['fields']['hweight'] = array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'description' => 'The weight of this menu link in the hierarchical tree. Added by the Views Term Hierarchy Weight Field module.',
);
}
}
function views_term_hierarchy_weight_field_install() {
$schema = array();
views_term_hierarchy_weight_field_schema_alter($schema);
foreach (array(
'hweight',
'hdepth',
) as $field) {
if (!db_field_exists('taxonomy_term_data', $field)) {
db_add_field('taxonomy_term_data', $field, $schema['taxonomy_term_data']['fields'][$field]);
}
}
$field = 'hweight';
if (!db_field_exists('menu_links', $field)) {
db_add_field('menu_links', $field, $schema['menu_links']['fields'][$field]);
}
if (module_exists('entity_menu_links')) {
if (!db_field_exists('menu_links_revision', $field)) {
db_add_field('menu_links_revision', $field, $schema['menu_links_revision']['fields'][$field]);
}
}
$vocabularies = taxonomy_get_vocabularies();
foreach ($vocabularies as $vid => $vocabulary) {
foreach (taxonomy_get_tree($vid) as $hweight => $term) {
$hdepth = count(taxonomy_get_parents_all($term->tid)) - 1;
views_term_hierarchy_weight_field_update($term->tid, $hweight, $hdepth);
}
}
}
function views_term_hierarchy_weight_field_uninstall() {
foreach (array(
'hweight',
'hdepth',
) as $field) {
db_drop_field('taxonomy_term_data', $field);
}
db_drop_field('menu_links', 'hweight');
if (module_exists('entity_menu_links')) {
db_drop_field('menu_links_revision', 'hweight');
}
}
function views_term_hierarchy_weight_field_update_7005() {
views_term_hierarchy_weight_field_install();
return array();
}