Commit fdc92c16 authored by codycraven's avatar codycraven
Browse files

Issue #1410576 by jonhattan: Added Features export integration.

parent a29b2a78
Taxonomy Display 7.x-1.x, YYYY-MM-DD
------------------------------------
Issue #1410576 by jonhattan: Added Features export integration.
Issue #1693978 by Saxxing: Fix ability for breadcrumbs to be translated.
Issue #1425648 by codycraven: Added README.txt per user request.
Issue #1507632 by codycraven, hass: Display select option for views that do not
......
......@@ -68,7 +68,7 @@ function taxonomy_display_admin_form(&$form, &$form_state) {
// Add selection for adding taxonomy term core feed to page
$fieldset['add_feed'] = array(
'#default_value' => $stored_settings['add_feed'],
'#default_value' => $stored_settings->add_feed,
'#description' => t('Drupal, by default, includes a feed of content referencing the term, by unchecking this you can prevent the feed from being added.'),
'#title' => t('Include feed'),
'#type' => 'checkbox',
......@@ -204,7 +204,7 @@ function taxonomy_display_field_ui_layouts_validate($form, &$form_state) {
* @param array|null $form_state
* The form state array.
* @param $stored_settings
* Associated array from taxonomy_display_fetch_taxonomy_display().
* Object from taxonomy_display_fetch_taxonomy_display().
*
* @return void
*
......@@ -230,7 +230,7 @@ function _taxonomy_display_admin_form_build_plugin_form($type, &$fieldset, &$for
$options = taxonomy_display_plugins($type);
// Add support for missing plugins.
if (isset($stored_settings[$type . '_plugin_missing'])) {
if (isset($stored_settings->{$type . '_plugin_missing'})) {
$options = array_merge(array('missing' => t('- Missing plugin -')), $options);
}
......@@ -244,7 +244,7 @@ function _taxonomy_display_admin_form_build_plugin_form($type, &$fieldset, &$for
$selected = 'missing';
}
else {
$selected = $stored_settings[$type . '_display_plugin'];
$selected = $stored_settings->{$type . '_display_plugin'};
}
$fieldset[$type . '_display_select'] = array(
'#ajax' => array(
......@@ -284,8 +284,8 @@ function _taxonomy_display_admin_form_build_plugin_form($type, &$fieldset, &$for
$plugin_class = new $selected;
// Set $options as null
$display_options = NULL;
if (!isset($stored_settings['no_record'])) {
$display_options = $stored_settings[$type . '_display_options'];
if (!isset($stored_settings->no_record)) {
$display_options = $stored_settings->{$type . '_display_options'};
}
// If the handler wasn't the one used on the last form build then reset the
// $form_state values for it.
......
......@@ -15,7 +15,7 @@ function taxonomy_display_enable() {
// 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'))
......@@ -37,6 +37,22 @@ function taxonomy_display_enable() {
function taxonomy_display_schema() {
$schema['taxonomy_display'] = array(
'description' => 'Per vocabulary configuration for term pages.',
// CTools export definitions.
'export' => array(
'key' => 'machine_name',
'primary key' => 'machine_name',
'default hook' => 'taxonomy_display_default_displays',
'load callback' => 'taxonomy_display_fetch_taxonomy_display',
'can disable' => FALSE,
'api' => array(
'owner' => 'taxonomy_display',
'api' => 'taxonomy_display',
'minimum_version' => 1,
'current_version' => 1,
),
),
'fields' => array(
'machine_name' => array(
'type' => 'varchar',
......
......@@ -49,13 +49,13 @@ function taxonomy_display_delete_taxonomy_display($machine_name, $watchdog_messa
}
/**
* Helper function; retrieve taxonomy display settings from the database.
* Helper function; retrieve taxonomy display settings.
*
* @param string $machine_name
* The machine name of the vocabulary's taxonomy display data to fetch.
*
* @return array
* Return associated array.
* @return object
* Return ctools export object with taxonomy display settings.
*/
function taxonomy_display_fetch_taxonomy_display($machine_name) {
// Attempt to fetch cached settings for the machine name.
......@@ -64,41 +64,37 @@ function taxonomy_display_fetch_taxonomy_display($machine_name) {
return $cache->data;
}
$result = db_select('taxonomy_display', 'td')
->fields('td')
->condition('machine_name', $machine_name)
->execute()
->fetchAssoc();
$plugin_types = _taxonomy_display_plugin_types();
// Set defaults if a result was not found
if (!$result) {
$defaults = array(
'machine_name' => $machine_name,
'add_feed' => 1,
'no_record' => TRUE,
);
ctools_include('export');
$result = ctools_export_load_object('taxonomy_display', 'names', array($machine_name));
// Set defaults if a result was not found.
if (!isset($result[$machine_name])) {
$defaults = new stdClass();
$defaults->machine_name = $machine_name;
$defaults->add_feed = TRUE;
$defaults->no_record = TRUE;
foreach($plugin_types as $k => $v) {
$defaults[$k . '_display_plugin'] = 'TaxonomyDisplay' . ucfirst($k) . 'DisplayHandlerCore';
$defaults[$k . '_display_options'] = NULL;
$defaults->{$k . '_display_plugin'} = 'TaxonomyDisplay' . ucfirst($k) . 'DisplayHandlerCore';
$defaults->{$k . '_display_options'} = NULL;
}
return $defaults;
}
$result = $result[$machine_name];
// Prepare plugins' data for use.
foreach ($plugin_types as $k => $v) {
if (!class_exists($result[$k . '_display_plugin'])) {
if (!class_exists($result->{$k . '_display_plugin'})) {
// Note that if providing translations for this module you must provide a
// translation for this watchdog warning for each $value.
watchdog('taxonomy_display', 'The taxonomy ' . $v['short'] . ' plugin assigned to the %name vocabulary is missing, Drupal default settings were used instead.', array('%name' => $machine_name), WATCHDOG_WARNING);
$result[$k . '_display_plugin'] = 'TaxonomyDisplay' . ucfirst($k) . 'DisplayHandlerCore';
$result[$k . '_display_options'] = NULL;
$result[$k . '_plugin_missing'] = TRUE;
}
else {
$result[$k . '_display_options'] = unserialize($result[$k . '_display_options']);
$result->{$k . '_display_plugin'} = 'TaxonomyDisplay' . ucfirst($k) . 'DisplayHandlerCore';
$result->{$k . '_display_options'} = NULL;
$result->{$k . '_plugin_missing'} = TRUE;
}
}
......@@ -284,7 +280,7 @@ function taxonomy_display_save_taxonomy_display($machine_name, $save_data = arra
// Perform our save
try {
// If update
if (!isset($update['no_record'])) {
if (!isset($update->no_record) && ($update->export_type & EXPORT_IN_DATABASE)) {
// Do not proceed if there are no fields to update.
if (empty($query_fields)) {
return;
......@@ -356,11 +352,11 @@ function taxonomy_display_taxonomy_term_page($term) {
$display_settings = taxonomy_display_fetch_taxonomy_display($term->vocabulary_machine_name);
// Breadcrumb display
$breadcrumb_display = new $display_settings['breadcrumb_display_plugin'];
$breadcrumb_display = new $display_settings->breadcrumb_display_plugin;
$breadcrumb_display->buildBreadcrumb($term);
// Conditionally add core Drupal feed to page
if ($display_settings['add_feed']) {
if ($display_settings->add_feed) {
drupal_add_feed('taxonomy/term/' . $term->tid . '/feed', 'RSS - ' . $term->name);
}
......@@ -368,12 +364,12 @@ function taxonomy_display_taxonomy_term_page($term) {
$build = array();
// Term display
$term_display = new $display_settings['term_display_plugin'];
$build['term_heading'] = $term_display->displayTerm($term, $display_settings['term_display_options']);
$term_display = new $display_settings->term_display_plugin;
$build['term_heading'] = $term_display->displayTerm($term, $display_settings->term_display_options);
// Associated content display
$associated_display = new $display_settings['associated_display_plugin'];
$build = array_merge($build, $associated_display->displayAssociated($term, $display_settings['associated_display_options']));
$associated_display = new $display_settings->associated_display_plugin;
$build = array_merge($build, $associated_display->displayAssociated($term, $display_settings->associated_display_options));
return $build;
}
......
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