Commit 869c1048 authored by Cody Craven's avatar Cody Craven
Browse files

Moved admin specific functions to an admin.inc and updated views to support...

Moved admin specific functions to an admin.inc and updated views to support missing views on term page display.
parent af5bfd5a
......@@ -27,9 +27,25 @@ class TaxonomyDisplayAssociatedDisplayHandlerViews extends TaxonomyDisplayAssoci
$build = array();
$build['view'] = array(
'#markup' => views_embed_view($options['view'], $options['display'], $term->tid),
);
$embed_view = views_embed_view($options['view'], $options['display'], $term->tid);
// TODO: Test the watchdog presents how I'm expecting
if (empty($embed_view)) {
watchdog(
'taxonomy_display',
'The view and/or display settings for %vocab are missing, go to the <a href="!link">full display page</a> and reconfigure the taxonomy term\'s associated content display.',
array(
'%vocab' => $term->vocabulary_machine_name,
'!link' => url('admin/structure/taxonomy/' . $term->vocabulary_machine_name . '/display/full'),
),
WATCHDOG_ERROR
);
}
else {
$build['view'] = array(
'#markup' => $embed_view,
);
}
return $build;
}
......
<?php
// $Id$
/**
* @file
* Administration form functions for taxonomy display configuration.
*/
/**
* Helper callback; perform form alterations for taxonomy display admin form.
*
* @param array $form
* @param array $form_state
*
* @return void
*
* @see taxonomy_display_form_fieldset()
*/
function taxonomy_display_admin_form(&$form, &$form_state) {
// Only proceed if we are on taxonomy_term entity type and the user has admin
// taxonomy display.
if ($form['#entity_type'] != 'taxonomy_term' || !user_access('administer taxonomy display')) {
return;
}
// Make things easy on users getting started with the module.
// We require the 'full' #view_mode to configure the taxonomy term page.
if ($form['#view_mode'] == 'default') {
$field = array(
'#title' => 'Term page display',
'#type' => 'fieldset',
);
// TODO: There's got to be a better way to find out if 'full' is enabled,
// need to look.
foreach ($form['additional_settings']['modes']['view_modes_custom']['#default_value'] as $value) {
if ($value == 'full') {
$field['#description'] = 'To alter the term page display you need to go to the <em>Taxonomy term page</em> view mode.';
break;
}
}
if (!isset($field['#description'])) {
$field['#description'] = 'Enable the <em>Taxonomy term page</em> view mode under the <em>Custom display settings</em> tab to alter the term page display.';
}
$form['additional_settings']['taxonomy_display'] = $field;
}
// Only proceed if we are on the full display mode.
if ($form['#view_mode'] != 'full') {
return;
}
$stored_settings = taxonomy_display_fetch_taxonomy_display($form['#bundle']);
$form['additional_settings']['taxonomy_display'] = array(
'#description' => 'Configure how the taxonomy term display page should be presented when viewed for this vocabulary.',
'#title' => 'Term page display',
'#type' => 'fieldset',
);
$fieldset =& $form['additional_settings']['taxonomy_display'];
if (isset($form_state['values']['additional_settings']['taxonomy_display'])) {
$values =& $form_state['values']['additional_settings']['taxonomy_display'];
}
// Populate $options with plugins that are available.
$options = taxonomy_display_plugins('term');
// TODO: Rewrite the term and associated fieldsets to use a helper function.
// Term display fieldset
// TODO: Rewrite supporting missing plugins.
// Discover which option should be selected from term display plugins.
if (isset($values) && isset($values['term_display_select']) &&
array_key_exists($values['term_display_select'], $options)) {
$selected = $values['term_display_select'];
}
elseif (isset($stored_settings['term_display_plugin']) &&
array_key_exists($stored_settings['term_display_plugin'], $options)) {
$selected = $stored_settings['term_display_plugin'];
}
else {
$selected = 'TaxonomyDisplayTermDisplayHandlerCore';
}
$fieldset['term_display_select'] = array(
'#ajax' => array(
'callback' => 'taxonomy_display_ajax_term_display_callback',
'wrapper' => 'replace-term-display-form',
),
'#default_value' => $selected,
'#description' => t('Select which plugin you would like to display the term\'s content.'),
'#options' => $options,
'#title' => t('Term display'),
'#type' => 'select',
);
if (isset($form_state['taxonomy_display']['term_display_handler'])) {
$last_handler = $form_state['taxonomy_display']['term_display_handler'];
}
$form_state['taxonomy_display']['term_display_handler'] = $selected;
$fieldset['term_display_form'] = array(
'#prefix' => '<div id="replace-term-display-form">',
'#suffix' => '</div>',
'#title' => t('!label term display options', array('!label' => $options[$selected])),
'#type' => 'fieldset',
);
// Get the fieldset from the selected handler.
$term_display = new $selected;
// Set $options as null
$term_display_options = NULL;
if ($stored_settings) {
$term_display_options = unserialize($stored_settings['term_display_options']);
}
// If the handler wasn't the one used on the last form build then reset the
// $form_state values for it.
if (!isset($last_handler) || $last_handler != $selected) {
$values['term_display_form'] = array();
}
$term_display->formFieldset($fieldset['term_display_form'], $values['term_display_form'], $term_display_options);
// Populate $options with plugins that are available.
$options = taxonomy_display_plugins('associated');
// Associated content fieldset
// TODO: Rewrite supporting missing plugins.
// Discover which option should be selected from term display plugins.
if (isset($values) && isset($values['associated_display_select']) &&
array_key_exists($values['associated_display_select'], $options)) {
$selected = $values['associated_display_select'];
}
elseif (isset($stored_settings['associated_display_plugin']) &&
array_key_exists($stored_settings['associated_display_plugin'], $options)) {
$selected = $stored_settings['associated_display_plugin'];
}
else {
$selected = 'TaxonomyDisplayAssociatedDisplayHandlerCore';
}
$fieldset['associated_display_select'] = array(
'#ajax' => array(
'callback' => 'taxonomy_display_ajax_associated_display_callback',
'wrapper' => 'replace-associated-display-form',
),
'#default_value' => $selected,
'#description' => t('Select which plugin you would like to display the term\'s associated content.'),
'#options' => $options,
'#title' => t('Associated content display'),
'#type' => 'select',
);
if (isset($form_state['taxonomy_display']['associated_display_handler'])) {
$last_handler = $form_state['taxonomy_display']['associated_display_handler'];
}
$form_state['taxonomy_display']['associated_display_handler'] = $selected;
$fieldset['associated_display_form'] = array(
'#prefix' => '<div id="replace-associated-display-form">',
'#suffix' => '</div>',
'#title' => t('!label associated content display options', array('!label' => $options[$selected])),
'#type' => 'fieldset',
);
// Get the fieldset from the selected handler.
$associated_display = new $selected;
// Set $options as null
$associated_display_options = NULL;
if ($stored_settings) {
$associated_display_options = unserialize($stored_settings['associated_display_options']);
}
// If the handler wasn't the one used on the last form build then reset the
// $form_state values for it.
if (!isset($last_handler) || $last_handler != $selected) {
$values['associated_display_form'] = array();
}
$associated_display->formFieldset($fieldset['associated_display_form'], $values['associated_display_form'], $associated_display_options);
// Add our #validate and #submit callback which will call plugins' methods.
$form['#validate'][] = 'taxonomy_display_admin_form_validate';
$form['#submit'][] = 'taxonomy_display_admin_form_submit';
}
/**
* Form submit callback; save Taxonomy Display settings for term pages.
*/
function taxonomy_display_admin_form_submit($form, &$form_state) {
$values =& $form_state['values']['additional_settings']['taxonomy_display'];
$td_form =& $form['additional_settings']['taxonomy_display'];
// Perform submit functions for our term display handler.
$term_display = new $values['term_display_select'];
$term_display_options = $term_display->formSubmit($td_form['term_display_form'], $values['term_display_form']);
// Perform submit functions for our associated content handler.
$associated_display = new $values['associated_display_select'];
$associated_display_options = $associated_display->formSubmit($td_form['associated_display_form'], $values['associated_display_form']);
// Save data
taxonomy_display_save_taxonomy_display($form['#bundle'], array(
'term_display_plugin' => $values['term_display_select'],
'term_display_options' => $term_display_options,
'associated_display_plugin' => $values['associated_display_select'],
'associated_display_options' => $associated_display_options,
));
}
/**
* Form validate callback; validate Taxonomy Display settings for term pages.
*/
function taxonomy_display_admin_form_validate($form, &$form_state) {
$values =& $form_state['values']['additional_settings']['taxonomy_display'];
$td_form =& $form['additional_settings']['taxonomy_display'];
// Perform validation functions for our term display handler.
$term_display = new $values['term_display_select'];
$term_display->formValidate($td_form['term_display_form'], $values['term_display_form']);
// Perform validation functions for our associated content display handler.
$associated_display = new $values['associated_display_select'];
$associated_display->formValidate($td_form['associated_display_form'], $values['associated_display_form']);
}
/**
* Return just the term display sub-form.
*
* @return renderable array
*/
function taxonomy_display_ajax_associated_display_callback($form, $form_state) {
return $form['additional_settings']['taxonomy_display']['associated_display_form'];
}
/**
* Return just the term display sub-form.
*
* @return renderable array
*/
function taxonomy_display_ajax_term_display_callback($form, $form_state) {
return $form['additional_settings']['taxonomy_display']['term_display_form'];
}
......@@ -6,24 +6,6 @@
* Hooks for the taxonomy display module.
*/
/**
* Return just the term display sub-form.
*
* @return renderable array
*/
function taxonomy_display_ajax_associated_display_callback($form, $form_state) {
return $form['additional_settings']['taxonomy_display']['associated_display_form'];
}
/**
* Return just the term display sub-form.
*
* @return renderable array
*/
function taxonomy_display_ajax_term_display_callback($form, $form_state) {
return $form['additional_settings']['taxonomy_display']['term_display_form'];
}
/**
* Helper function; delete taxonomy display data.
*
......@@ -81,205 +63,8 @@ function taxonomy_display_fetch_taxonomy_display($machine_name) {
* Implements hook_form_FORM_ID_alter().
*/
function taxonomy_display_form_field_ui_display_overview_form_alter(&$form, &$form_state) {
// Only proceed if we are on taxonomy_term entity type and the user has admin
// taxonomy display.
if ($form['#entity_type'] != 'taxonomy_term' || !user_access('administer taxonomy display')) {
return;
}
// Make things easy on users getting started with the module.
// We require the 'full' #view_mode to configure the taxonomy term page.
if ($form['#view_mode'] == 'default') {
$field = array(
'#title' => 'Term page display',
'#type' => 'fieldset',
);
// TODO: There's got to be a better way to find out if 'full' is enabled,
// need to look.
foreach ($form['additional_settings']['modes']['view_modes_custom']['#default_value'] as $value) {
if ($value == 'full') {
$field['#description'] = 'To alter the term page display you need to go to the <em>Taxonomy term page</em> view mode.';
break;
}
}
if (!isset($field['#description'])) {
$field['#description'] = 'Enable the <em>Taxonomy term page</em> view mode under the <em>Custom display settings</em> tab to alter the term page display.';
}
$form['additional_settings']['taxonomy_display'] = $field;
}
// Only proceed if we are on the full display mode.
if ($form['#view_mode'] != 'full') {
return;
}
$stored_settings = taxonomy_display_fetch_taxonomy_display($form['#bundle']);
$form['additional_settings']['taxonomy_display'] = array(
'#description' => 'Configure how the taxonomy term display page should be presented when viewed for this vocabulary.',
'#title' => 'Term page display',
'#type' => 'fieldset',
);
$fieldset =& $form['additional_settings']['taxonomy_display'];
if (isset($form_state['values']['additional_settings']['taxonomy_display'])) {
$values =& $form_state['values']['additional_settings']['taxonomy_display'];
}
// Populate $options with plugins that are available.
$options = taxonomy_display_plugins('term');
// TODO: Rewrite the term and associated fieldsets to use a helper function.
// Term display fieldset
// TODO: Rewrite supporting missing plugins.
// Discover which option should be selected from term display plugins.
if (isset($values) && isset($values['term_display_select']) &&
array_key_exists($values['term_display_select'], $options)) {
$selected = $values['term_display_select'];
}
elseif (isset($stored_settings['term_display_plugin']) &&
array_key_exists($stored_settings['term_display_plugin'], $options)) {
$selected = $stored_settings['term_display_plugin'];
}
else {
$selected = 'TaxonomyDisplayTermDisplayHandlerCore';
}
$fieldset['term_display_select'] = array(
'#ajax' => array(
'callback' => 'taxonomy_display_ajax_term_display_callback',
'wrapper' => 'replace-term-display-form',
),
'#default_value' => $selected,
'#description' => t('Select which plugin you would like to display the term\'s content.'),
'#options' => $options,
'#title' => t('Term display'),
'#type' => 'select',
);
if (isset($form_state['taxonomy_display']['term_display_handler'])) {
$last_handler = $form_state['taxonomy_display']['term_display_handler'];
}
$form_state['taxonomy_display']['term_display_handler'] = $selected;
$fieldset['term_display_form'] = array(
'#prefix' => '<div id="replace-term-display-form">',
'#suffix' => '</div>',
'#title' => t('!label term display options', array('!label' => $options[$selected])),
'#type' => 'fieldset',
);
// Get the fieldset from the selected handler.
$term_display = new $selected;
// Set $options as null
$term_display_options = NULL;
if ($stored_settings) {
$term_display_options = unserialize($stored_settings['term_display_options']);
}
// If the handler wasn't the one used on the last form build then reset the
// $form_state values for it.
if (!isset($last_handler) || $last_handler != $selected) {
$values['term_display_form'] = array();
}
$term_display->formFieldset($fieldset['term_display_form'], $values['term_display_form'], $term_display_options);
// Populate $options with plugins that are available.
$options = taxonomy_display_plugins('associated');
// Associated content fieldset
// TODO: Rewrite supporting missing plugins.
// Discover which option should be selected from term display plugins.
if (isset($values) && isset($values['associated_display_select']) &&
array_key_exists($values['associated_display_select'], $options)) {
$selected = $values['associated_display_select'];
}
elseif (isset($stored_settings['associated_display_plugin']) &&
array_key_exists($stored_settings['associated_display_plugin'], $options)) {
$selected = $stored_settings['associated_display_plugin'];
}
else {
$selected = 'TaxonomyDisplayAssociatedDisplayHandlerCore';
}
$fieldset['associated_display_select'] = array(
'#ajax' => array(
'callback' => 'taxonomy_display_ajax_associated_display_callback',
'wrapper' => 'replace-associated-display-form',
),
'#default_value' => $selected,
'#description' => t('Select which plugin you would like to display the term\'s associated content.'),
'#options' => $options,
'#title' => t('Associated content display'),
'#type' => 'select',
);
if (isset($form_state['taxonomy_display']['associated_display_handler'])) {
$last_handler = $form_state['taxonomy_display']['associated_display_handler'];
}
$form_state['taxonomy_display']['associated_display_handler'] = $selected;
$fieldset['associated_display_form'] = array(
'#prefix' => '<div id="replace-associated-display-form">',
'#suffix' => '</div>',
'#title' => t('!label associated content display options', array('!label' => $options[$selected])),
'#type' => 'fieldset',
);
// Get the fieldset from the selected handler.
$associated_display = new $selected;
// Set $options as null
$associated_display_options = NULL;
if ($stored_settings) {
$associated_display_options = unserialize($stored_settings['associated_display_options']);
}
// If the handler wasn't the one used on the last form build then reset the
// $form_state values for it.
if (!isset($last_handler) || $last_handler != $selected) {
$values['associated_display_form'] = array();
}
$associated_display->formFieldset($fieldset['associated_display_form'], $values['associated_display_form'], $associated_display_options);
// Add our #validate and #submit callback which will call plugins' methods.
$form['#validate'][] = 'taxonomy_display_form_field_ui_display_overview_validate';
$form['#submit'][] = 'taxonomy_display_form_field_ui_display_overview_submit';
}
/**
* Form submit callback; save Taxonomy Display settings for term pages.
*/
function taxonomy_display_form_field_ui_display_overview_submit($form, &$form_state) {
$values =& $form_state['values']['additional_settings']['taxonomy_display'];
$td_form =& $form['additional_settings']['taxonomy_display'];
// Perform submit functions for our term display handler.
$term_display = new $values['term_display_select'];
$term_display_options = $term_display->formSubmit($td_form['term_display_form'], $values['term_display_form']);
// Perform submit functions for our associated content handler.
$associated_display = new $values['associated_display_select'];
$associated_display_options = $associated_display->formSubmit($td_form['associated_display_form'], $values['associated_display_form']);
// Save data
taxonomy_display_save_taxonomy_display($form['#bundle'], array(
'term_display_plugin' => $values['term_display_select'],
'term_display_options' => $term_display_options,
'associated_display_plugin' => $values['associated_display_select'],
'associated_display_options' => $associated_display_options,
));
}
/**
* Form validate callback; validate Taxonomy Display settings for term pages.
*/
function taxonomy_display_form_field_ui_display_overview_validate($form, &$form_state) {
$values =& $form_state['values']['additional_settings']['taxonomy_display'];
$td_form =& $form['additional_settings']['taxonomy_display'];
// Perform validation functions for our term display handler.
$term_display = new $values['term_display_select'];
$term_display->formValidate($td_form['term_display_form'], $values['term_display_form']);
// Perform validation functions for our associated content display handler.
$associated_display = new $values['associated_display_select'];
$associated_display->formValidate($td_form['associated_display_form'], $values['associated_display_form']);
form_load_include($form_state, 'inc', 'taxonomy_display', 'taxonomy_display.admin');
taxonomy_display_admin_form($form, $form_state);
}
/**
......
Supports Markdown
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