function media_gallery_create_taxonomy_term in Media Gallery 7
Same name and namespace in other branches
- 7.2 media_gallery.install \media_gallery_create_taxonomy_term()
Helper function to create required taxonomy term.
1 call to media_gallery_create_taxonomy_term()
- media_gallery_install in ./
media_gallery.install - Implements hook_install().
File
- ./
media_gallery.install, line 893 - Install file for media_gallery. Includes field and instance definitions.
Code
function media_gallery_create_taxonomy_term($vocabulary) {
// Create a taxonomy term for the "All Galleries" collection.
$term = new stdClass();
$term->vid = $vocabulary->vid;
$term->name = 'Galleries';
$term->description = '';
// Choose a text format that will prevent WYSIWYGs from appearing by default.
// When we allow people to create new gallery collections we'll have to
// (carefully) modify the form for adding new ones also.
$term->format = filter_fallback_format();
$term->path = array(
'alias' => 'galleries',
);
// Save the term, preventing Pathauto from aliasing it incorrectly.
_media_gallery_prevent_unwanted_pathauto_aliases();
taxonomy_term_save($term);
_media_gallery_allow_all_pathauto_aliases();
// Create a menu link for this taxonomy term. We set the link title to
// 'Taxonomy term' in order to match the title of the corresponding router
// item, since this is what triggers the menu system to display a dynamic
// title for the link.
$menu_item = array(
'menu_name' => 'main-menu',
'weight' => 10,
'link_title' => 'Taxonomy term',
'link_path' => 'taxonomy/term/' . $term->tid,
);
// If the router item doesn't exist yet (for example, if we are installing
// either the Taxonomy module or Drupal itself at the same time as Media
// Gallery), rebuild the menu before saving, to avoid errors.
$router_item_exists = (bool) db_query_range('SELECT 1 FROM {menu_router} WHERE path = :path', 0, 1, array(
':path' => 'taxonomy/term/%',
))
->fetchField();
if (!$router_item_exists) {
menu_rebuild();
}
menu_link_save($menu_item);
// Save the term ID for future use.
variable_set('media_gallery_default_collection_tid', $term->tid);
}