diff --git a/media_gallery.info b/media_gallery.info index c7b045c..135693e 100644 --- a/media_gallery.info +++ b/media_gallery.info @@ -13,5 +13,6 @@ files[] = media_gallery.module files[] = media_gallery.admin.inc files[] = media_gallery.fields.inc files[] = media_gallery.theme.inc +files[] = media_gallery_taxonomy_display_handlers.inc configure = admin/config/media/galleries diff --git a/media_gallery.module b/media_gallery.module index 2f1e7d7..a2e0cfd 100644 --- a/media_gallery.module +++ b/media_gallery.module @@ -183,12 +183,16 @@ function media_gallery_mg_item_load($fid, $nid) { * Implements hook_menu_alter(). */ function media_gallery_menu_alter(&$items) { - // Take over taxonomy term list pages by substituting our own callback. - // TODO: Use hook_entity_info_alter() to change the entity uri callback for - // gallery collections only. - $items['taxonomy/term/%taxonomy_term']['page callback'] = 'media_gallery_list_galleries'; - $items['taxonomy/term/%taxonomy_term']['file'] = 'media_gallery.pages.inc'; - $items['taxonomy/term/%taxonomy_term']['module'] = 'media_gallery'; + // Prevent overwriting page callback if there is a module which provides a + // API to modify the display of a taxonomy term. + if (_media_gallery_overwrite_menu_path_taxonomy_display()) { + // Take over taxonomy term list pages by substituting our own callback. + // TODO: Use hook_entity_info_alter() to change the entity uri callback for + // gallery collections only. + $items['taxonomy/term/%taxonomy_term']['page callback'] = 'media_gallery_list_galleries'; + $items['taxonomy/term/%taxonomy_term']['file'] = 'media_gallery.pages.inc'; + $items['taxonomy/term/%taxonomy_term']['module'] = 'media_gallery'; + } // If you're viewing a media item in context somewhere (which we do inside // media gallery nodes), that means it's being used on your site, which means @@ -199,6 +203,52 @@ function media_gallery_menu_alter(&$items) { } /** + * This function checks, whether we are allowed to hijack the taxonomy term + * page callback function or not. If the module taxonomy_display is enabled, + * we will provide a class to taxonomy_display for building the taxonomy + * term page in media_gallery style. + * + * @return + * FALSE if taxonomy_display is enabled, otherwise TRUE. + */ +function _media_gallery_overwrite_menu_path_taxonomy_display() { + if (module_exists('taxonomy_display')) { + _media_gallery_init_taxonomy_display(); + return FALSE; + } + return TRUE; +} + +/** + * Initializes the configuration for taxonomy_display to display media_gallery + * vocabularies in the context of a gallery. If it is already initializes, we + * do not change any settings. + */ +function _media_gallery_init_taxonomy_display() { + $voc = taxonomy_vocabulary_load(variable_get('media_gallery_collection_vid')); + if ($voc === FALSE) { + return; + } + + $display_options = taxonomy_display_fetch_taxonomy_display($voc->machine_name); + if (!empty($display_options->no_record)) { + // There are no settings for media_gallery vocabularies in + // taxonomy_display. Therefore we assume this to be the first time + // media_gallery and taxonomy_display are enabled at the same time. + + // Set media_gallery default settings in the taxonomy_display view mode. + $display_options->associated_display_plugin = 'MediaGalleryAssociatedDisplayHandler'; + taxonomy_display_save_taxonomy_display($voc->machine_name, (array) $display_options); + + // Activate taxonomy_display view mode. + $bundle_settings = field_bundle_settings('taxonomy_term', $voc->machine_name); + $bundle_settings['view_modes'] += array('full' => array()); + $bundle_settings['view_modes']['full']['custom_settings'] = TRUE; + field_bundle_settings('taxonomy_term', $voc->machine_name, $bundle_settings); + } +} + +/** * Implements hook_admin_paths(). */ function media_gallery_admin_paths() { @@ -1830,3 +1880,14 @@ function media_gallery_lightbox_delivery_callback($page_content) { } media_gallery_lightbox_page_deliver($page_content); } + +/** + * Implements hook_taxonomy_display_plugins(). + */ +function media_gallery_taxonomy_display_plugins() { + return array( + 'associated' => array( + 'MediaGalleryAssociatedDisplayHandler' => t('Media Gallery'), + ), + ); +} diff --git a/media_gallery.pages.inc b/media_gallery.pages.inc index 1316814..af6bc02 100644 --- a/media_gallery.pages.inc +++ b/media_gallery.pages.inc @@ -11,16 +11,7 @@ function media_gallery_list_galleries($term) { module_load_include('inc', 'taxonomy', 'taxonomy.pages'); return taxonomy_term_page($term); } - - // Add front-end resources for drag-and-drop sorting. - if (user_access('administer media galleries')) { - drupal_add_library('system', 'ui.sortable'); - drupal_add_library('system', 'jquery.bbq'); - drupal_add_js(drupal_get_path('module', 'media_gallery') . '/media_gallery.dragdrop.js'); - drupal_add_css(drupal_get_path('module', 'media_gallery') . '/media_gallery.dragdrop.css'); - $sort_collection_url = url('media-gallery/sort/collection/' . $term->tid . '/' . drupal_get_token('media_gallery')); - drupal_add_js(array('mediaGallerySortCollectionUrl' => $sort_collection_url), array('type' => 'setting')); - } + // Assign the term name as the page title. drupal_set_title($term->name); @@ -38,12 +29,35 @@ function media_gallery_list_galleries($term) { drupal_set_breadcrumb($breadcrumb); drupal_add_feed('taxonomy/term/' . $term->tid . '/feed', 'RSS - ' . $term->name); + $build = array(); + $build['term_heading'] = array( '#prefix' => '
', '#suffix' => '
', 'term' => taxonomy_term_view($term, 'full'), ); + $build += media_gallery_list_galleries_associated($term); + + return $build; +} + +/** + * Build the associated galleries of a term. + */ +function media_gallery_list_galleries_associated($term) { + $build = array(); + + // Add front-end resources for drag-and-drop sorting. + if (user_access('administer media galleries')) { + drupal_add_library('system', 'ui.sortable'); + drupal_add_library('system', 'jquery.bbq'); + drupal_add_js(drupal_get_path('module', 'media_gallery') . '/media_gallery.dragdrop.js'); + drupal_add_css(drupal_get_path('module', 'media_gallery') . '/media_gallery.dragdrop.css'); + $sort_collection_url = url('media-gallery/sort/collection/' . $term->tid . '/' . drupal_get_token('media_gallery')); + drupal_add_js(array('mediaGallerySortCollectionUrl' => $sort_collection_url), array('type' => 'setting')); + } + // There is a small bug here with the "entity" $term_entity = new FieldsRSIPreventor($term); $limit = $term_entity->getValue('media_gallery_columns') * $term_entity->getValue('media_gallery_rows'); diff --git a/media_gallery_taxonomy_display_handlers.inc b/media_gallery_taxonomy_display_handlers.inc new file mode 100644 index 0000000..bce3d19 --- /dev/null +++ b/media_gallery_taxonomy_display_handlers.inc @@ -0,0 +1,24 @@ +