Commit a88a369f authored by Cody Craven's avatar Cody Craven
Browse files

Added taxonomy_display.api.php to define the hook invocations and alters...

Added taxonomy_display.api.php to define the hook invocations and alters created by taxonomy_display. Also modified taxonomy_display_save_taxonomy_display() to make altering less resource intensive.
parent 10b86d92
......@@ -2,6 +2,9 @@
Taxonomy Display 7.x-1.x, YYYY-MM-DD
------------------------------------
Added taxonomy_display.api.php to define the hook invocations and alters created
by taxonomy_display. Also modified taxonomy_display_save_taxonomy_display() to
make altering less resource intensive.
Added missing plugin support and resolved errors when a term is viewed and the
vocabulary does not have any taxonomy_display settings.
......
<?php
// $Id$
/**
* @file
* Hooks provided by the taxonomy_display module.
*/
/**
* @addtogroup hooks
* @{
*/
/**
* Provide plugins to taxonomy_display.
*
* @return
* An associative array containing 'associated' and 'term' arrays listing
* plugins for taxonomy_display to call. Within each array another associative
* array is provided where each key is a class name of the handler and the
* value is displayed to the administrator when selecting the plugin. Note
* that any class names provided must have their file listed in the containing
* module's .info file so that the class can be auto loaded.
*
* @see taxonomy_display_plugins()
* @see taxonomy_display_taxonomy_display_plugins()
*/
function hook_taxonomy_display_plugins() {
return array(
'associated' => array(
'HookAssociatedDisplayHandlerImplementingClassName' => t('My term display handler'),
),
'term' => array(
'HookTermDisplayHandlerImplementingClassName' => t('My associated display handler'),
),
);
}
/**
* Alter plugins list used by taxonomy_display.
*
* @param array $plugins
*
* @return void
*
* @see hook_taxonomy_display_plugins()
* @see taxonomy_display_plugins()
*/
function hook_taxonomy_display_plugins_alter(&$plugins) {
// Hijack taxonomy_display's Views plugin.
if (isset($plugins['associated']['TaxonomyDisplayAssociatedDisplayHandlerViews'])) {
// Remove this from even being an option to users!
unset($plugins['associated']['TaxonomyDisplayAssociatedDisplayHandlerViews']);
// Now hijack all existing taxonomy_display settings to use my plugin that
// previously using taxonomy_display's Views plugin.
$count = (bool) db_update('taxonomy_display')
->fields(array('associated_display_plugin', 'MyViewsPluginHandler'))
->condition('associated_display_plugin', 'TaxonomyDisplayAssociatedDisplayHandlerViews')
->execute();
// Note that the plugin handler 'MyViewsPluginHandler' in the db_update()
// should be defined in hook_taxonomy_display_plugins() to allow other
// modules to overwrite it if desired.
}
}
/**
* Alter a vocabulary's taxonomy_display settings before save.
*
* @param array $save_data
* Associative array containing the values to save in the database, note that
* all associative keys listed in taxonomy_display_save_taxonomy_display() may
* not be available if plugins are missing upon save.
*
* @return void
*
* @see taxonomy_display_save_taxonomy_display()
*/
function hook_taxonomy_display_save_fields_alter(&$save_data) {
// If this is a particular vocabulary
if ($save_data['machine_name'] == 'my_vocabulary_name') {
// If a particular term display plugin was selected.
if ($save_data['term_display_plugin'] == 'HookAssociatedDisplayHandlerImplementingClassName') {
// Set an option for the display plugin, note that key/values will be
// unique to each plugin so the plugin's handler class should be
// referenced to see what values are valid to set.
// Note that after hook_taxonomy_display_save_fields_alter()
// display_options are serialized before storage.
$save_data['term_display_options']['show_feed'] = TRUE;
}
// Else set the term display to the hidden plugin.
else {
$save_data['term_display_plugin'] = 'TaxonomyDisplayTermDisplayHandlerHidden';
// Set options to customize the display, in this case we don't set any.
$save_data['term_display_options'] = NULL;
}
}
}
/**
* @} End of "addtogroup hooks".
*/
......@@ -235,6 +235,9 @@ function taxonomy_display_taxonomy_display_plugins() {
* @return void
*/
function taxonomy_display_save_taxonomy_display($machine_name, $save_data = array(), $watchdog_message = NULL, $watchdog_variables = array(), $watchdog_severity = WATCHDOG_NOTICE) {
// Allow other modules to alter our fields before they are inserted/updated.
drupal_alter('taxonomy_display_save_fields', $save_data);
// Prepare the fields to be used for the insert or update query.
$query_fields = array();
foreach($save_data as $k => $v) {
......@@ -252,8 +255,6 @@ function taxonomy_display_save_taxonomy_display($machine_name, $save_data = arra
break;
}
}
// Allow other modules to alter our fields before they are inserted/updated.
drupal_alter('taxonomy_display_save_fields', $query_fields, $save_data);
// Retrieve the machine name, tells us whether to insert or update.
$update = taxonomy_display_fetch_taxonomy_display($machine_name);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment