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

Added views support for associated content display.

parent 8d1ff0e2
/nbproject/private/
\ No newline at end of file
<?php
// $Id$
/**
* Ajax callback; return just the term display sub-form.
*
* @return renderable array
*/
function taxonomy_display_associated_display_handler_views_callback($form, $form_state) {
$field = taxonomy_display_form_fieldset($form, 'associated');
if ($field) {
return $field['display'];
}
}
/**
* Add a display handler that will use the Drupal core method of display.
*/
class TaxonomyDisplayAssociatedDisplayHandlerViews extends TaxonomyDisplayAssociatedDisplayHandler {
/**
* Build our output to be rendered to the user.
*
* @see TaxonomyDisplayAssociatedDisplayHandler::displayAssociated()
*/
public function displayAssociated($term, $options = NULL) {
module_load_include('module', 'views');
$build = array();
$build['view'] = array(
'#markup' => views_embed_view($options['view'], $options['display'], $term->tid),
);
return $build;
}
/**
* Build our form for the fieldset.
*
* @see TaxonomyDisplayHandlerForm::formFieldset()
*/
public function formFieldset(&$form, &$values, $options = NULL) {
module_load_include('module', 'views');
$form['#description'] = t('Use <em>Views</em> for displaying associated content.');
// Get options for the view select field.
$views = views_get_all_views();
$select_options = array();
foreach ($views as $view) {
if (!isset($view->disabled)) {
$select_options[$view->name] = $view->human_name;
}
}
$form['view'] = array(
'#ajax' => array(
'callback' => 'taxonomy_display_associated_display_handler_views_callback',
'wrapper' => 'replace-td-views-display-field',
),
'#default_value' => isset($options['view']) ? $options['view'] : FALSE,
'#description' => t('Select which view you would like to display the associated content.'),
'#options' => $select_options,
'#title' => t('View'),
'#type' => 'select',
);
// Retrieve the views displays to supply as options.
if (isset($values['view'])) {
$view = $views[$values['view']];
}
elseif (isset($options['view'])) {
$view = $views[$options['view']];
}
else {
// If the view hasn't been submitted and it's not previously saved then
// fetch it as the first view field option.
reset($select_options);
$view = $views[key($select_options)];
}
$select_options = array();
// Get options for the view's display field.
foreach ($view->display as $key => $display) {
$select_options[$key] = $display->display_title;
}
$form['display'] = array(
'#default_value' => isset($options['display']) ? $options['display'] : 'default',
'#description' => t('The display selected will have the taxonomy term ID supplied as the first argument.'),
'#options' => $select_options,
'#prefix' => '<div id="replace-td-views-display-field">',
'#suffix' => '</div>',
'#title' => 'View\'s display',
'#type' => 'select',
);
}
/**
* TODO: Add validate that ensures the display selected is part of the view, necessary for supporting no JS?
*/
/**
* We store values to access later for rendering and editing.
*
* @see TaxonomyDisplayHandlerForm::formSubmit()
*/
public function formSubmit($form, &$values) {
// We are using the exact keys that our formFieldset() implementation
// defines and we want all of the values stored, so we have no need to alter
// them before returning.
return $values;
}
}
\ No newline at end of file
......@@ -14,4 +14,5 @@ files[] = handlers/term/core.inc
files[] = handlers/term/hidden.inc
; - For associated content displays
files[] = handlers/associated/core.inc
files[] = handlers/associated/hidden.inc
\ No newline at end of file
files[] = handlers/associated/hidden.inc
files[] = handlers/associated/views.inc
\ No newline at end of file
......@@ -282,6 +282,28 @@ function taxonomy_display_form_field_ui_display_overview_validate($form, &$form_
$associated_display->formValidate($td_form['associated_display_form'], $values['associated_display_form']);
}
/**
* Helper function; retrieve the plugin fieldset from configuration form.
*
* This is set up just so we don't break implementing modules in the future if
* we change the form placement for some reason.
*
* @param array $form
* Form array.
* @param string $fetch
* String either 'term' or 'associated'.
*
* @return array|FALSE
* Returns the form fieldset if valid, otherwise boolean false.
*/
function taxonomy_display_form_fieldset(&$form, $fetch = 'term') {
if (isset($form['additional_settings']['taxonomy_display'][$fetch . '_display_form'])) {
return $form['additional_settings']['taxonomy_display'][$fetch . '_display_form'];
}
return FALSE;
}
/**
* Implements of hook_menu_alter().
*/
......@@ -344,7 +366,7 @@ function taxonomy_display_plugins($type = NULL) {
function taxonomy_display_taxonomy_display_plugins() {
// To add custom plugins in your own hook implementation return an array with
// the format below:
return array(
$plugins = array(
// In the two arrays 'associated' and 'term', provide the implementing class
// name of your handler as the keys and the text to be displayed to the user
// for display as the value.
......@@ -361,6 +383,13 @@ function taxonomy_display_taxonomy_display_plugins() {
'TaxonomyDisplayTermDisplayHandlerHidden' => t('Hidden'),
),
);
// Conditional plugins
if (module_exists('views')) {
$plugins['associated']['TaxonomyDisplayAssociatedDisplayHandlerViews'] = t('Views');
}
return $plugins;
}
/**
......
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