Commit 8d1ff0e2 authored by Cody Craven's avatar Cody Craven
Browse files

Increased functionality more towards a working release. Taxonomy associated...

Increased functionality more towards a working release. Taxonomy associated content display is now saveable, hookable, and editable. Core and hidden plugins functional.
parent 96cc034b
<?php
// $Id$
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
/**
* @todo Write class explanation
*/
?>
abstract class TaxonomyDisplayAssociatedDisplayHandler extends TaxonomyDisplayHandlerForm {
/**
* Render the output to be displayed when the user views the taxonomy term.
*
* @param termObject $term
* The taxonomy term to be displayed.
* @param mixed $options
* The data that was stored on behalf of the handler resulting from the
* return of the TaxonomyDisplayHandlerForm::formSubmit implementation.
*
* @return array
* The build the user will see for the associated content viewing the term.
*
* @see TaxonomyDisplayHandlerForm::formSubmit()
* @see taxonomy_term_page()
*/
abstract public function displayAssociated($term, $options = NULL);
}
......@@ -14,10 +14,11 @@ abstract class TaxonomyDisplayTermDisplayHandler extends TaxonomyDisplayHandlerF
* The data that was stored on behalf of the handler resulting from the
* return of the TaxonomyDisplayHandlerForm::formSubmit implementation.
*
* @return string
* The output the user will see when viewing the term.
* @return array
* The build the user will see when viewing the term.
*
* @see TaxonomyDisplayHandlerForm::formSubmit()
* @see taxonomy_term_page()
*/
abstract public function displayTerm($term, $options = NULL);
}
<?php
// $Id$
/**
* Add a display handler that will use the Drupal core method of display.
*/
class TaxonomyDisplayAssociatedDisplayHandlerCore extends TaxonomyDisplayAssociatedDisplayHandler {
/**
* Build our output to be rendered to the user.
*
* @see TaxonomyDisplayAssociatedDisplayHandler::displayAssociated()
*/
public function displayAssociated($term, $options = NULL) {
$build = array();
$number_nodes = isset($options['associated_per_page']) ? $options['associated_per_page'] : variable_get('default_nodes_main', 10);
if ($nids = taxonomy_select_nodes($term->tid, TRUE, $number_nodes)) {
$nodes = node_load_multiple($nids);
$build += node_view_multiple($nodes);
$build['pager'] = array(
'#theme' => 'pager',
'#weight' => 5,
);
}
elseif (isset($options['empty_text']) && !empty($options['empty_text'])) {
$build['no_content'] = array(
'#prefix' => '<p>',
'#markup' => t($options['empty_text']),
'#suffix' => '</p>',
);
}
return $build;
}
/**
* Build our form for the fieldset.
*
* @see TaxonomyDisplayHandlerForm::formFieldset()
*/
public function formFieldset(&$form, &$values, $options = NULL) {
$form['#description'] = t('The core Drupal functionality will be used to display the term\'s associated content.');
$form['associated_per_page'] = array(
'#default_value' => isset($options['associated_per_page']) ? $options['associated_per_page'] : variable_get('default_nodes_main', 10),
'#description' => t('Enter 0 to display all associated content for the taxonomy term.'),
'#maxlength' => 7,
'#required' => TRUE,
'#size' => 8,
'#title' => t('Number of associated content entities per page'),
'#type' => 'textfield',
);
$form['empty_text'] = array(
'#default_value' => isset($options['empty_text']) ? $options['empty_text'] : 'There is currently no content classified with this term.',
'#description' => t('Text displayed if there is no associated content, set to blank if no empty text should be displayed.'),
'#title' => t('No associated content text'),
'#type' => 'textfield',
);
}
/**
* 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;
}
/**
* Validate the form values.
*
* @see TaxonomyDisplayHandlerForm::formValidate()
*/
public function formValidate($form, &$values) {
if ($values['associated_per_page'] !== '0' &&
!preg_match('#^[1-9][0-9]*$#', $values['associated_per_page'])) {
form_set_error(implode('][', $form['associated_per_page']['#parents']), t('The number of associated content entities per page must be a whole, non-negative number.'));
}
return $this;
}
}
\ No newline at end of file
<?php
// $Id$
/**
* Add a display handler that will hide the term when viewed.
*/
class TaxonomyDisplayAssociatedDisplayHandlerHidden extends TaxonomyDisplayAssociatedDisplayHandler {
/**
* Do not display anything to the user, we return an empty string.
*
* @see TaxonomyDisplayAssociatedDisplayHandler::displayAssociated()
*/
public function displayAssociated($term, $options = NULL) {
return array();
}
/**
* Set a description when the user selects this option.
*
* @see TaxonomyDisplayHandlerForm::formFieldset()
*/
public function formFieldset(&$form, &$values, $options = NULL) {
$form['#description'] = t('The associated content for the term will not be displayed to the user when viewed. Leaving only the title and term display.');
}
/**
* Do not want anything stored, return void.
*
* @see TaxonomyDisplayHandlerForm::formSubmit()
*/
public function formSubmit($form, &$values) {}
}
\ No newline at end of file
......@@ -6,7 +6,7 @@
*/
class TaxonomyDisplayTermDisplayHandlerCore extends TaxonomyDisplayTermDisplayHandler {
/**
*
* Build our output to be rendered to the user.
*
* @see TaxonomyDisplayTermDisplayHandler::displayTerm()
*/
......@@ -38,7 +38,7 @@ class TaxonomyDisplayTermDisplayHandlerCore extends TaxonomyDisplayTermDisplayHa
}
/**
*
* Build our form for the fieldset.
*
* @see TaxonomyDisplayHandlerForm::formFieldset()
*/
......
......@@ -6,12 +6,12 @@
*/
class TaxonomyDisplayTermDisplayHandlerHidden extends TaxonomyDisplayTermDisplayHandler {
/**
* Do not display anything to the user, we return an empty string.
* Do not display anything to the user, we return an empty array.
*
* @see TaxonomyDisplayTermDisplayHandler::displayTerm()
*/
public function displayTerm($term, $options = NULL) {
return '';
return array();
}
/**
......
......@@ -12,4 +12,6 @@ files[] = classes/term_display.inc
; - For term displays
files[] = handlers/term/core.inc
files[] = handlers/term/hidden.inc
; - For associated content displays
\ No newline at end of file
; - For associated content displays
files[] = handlers/associated/core.inc
files[] = handlers/associated/hidden.inc
\ No newline at end of file
......@@ -6,6 +6,15 @@
* 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.
*
......@@ -32,6 +41,8 @@ function taxonomy_display_ajax_term_display_callback($form, $form_state) {
* WATCHDOG_NOTICE.
*
* @return void
*
* @todo test this works
*/
function taxonomy_display_delete_taxonomy_dislpay($machine_name, $watchdog_message = NULL, $watchdog_variables = array(), $watchdog_severity = WATCHDOG_NOTICE) {
// Delete our display record for the term being removed.
......@@ -116,6 +127,10 @@ function taxonomy_display_form_field_ui_display_overview_form_alter(&$form, &$fo
// 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']) &&
......@@ -156,16 +171,71 @@ function taxonomy_display_form_field_ui_display_overview_form_alter(&$form, &$fo
// Get the fieldset from the selected handler.
$term_display = new $selected;
// Set $options as null
$options = NULL;
$term_display_options = NULL;
if ($stored_settings) {
$options = unserialize($stored_settings['term_display_options']);
$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'], $options);
$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';
......@@ -183,14 +253,16 @@ function taxonomy_display_form_field_ui_display_overview_submit($form, &$form_st
$term_display = new $values['term_display_select'];
$term_display_options = $term_display->formSubmit($td_form['term_display_form'], $values['term_display_form']);
// TODO: Perform submit functions for our associated content handler.
// 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' => '',
'associated_display_options' => '',
'associated_display_plugin' => $values['associated_display_select'],
'associated_display_options' => $associated_display_options,
));
}
......@@ -205,7 +277,9 @@ function taxonomy_display_form_field_ui_display_overview_validate($form, &$form_
$term_display = new $values['term_display_select'];
$term_display->formValidate($td_form['term_display_form'], $values['term_display_form']);
// TODO: Perform validation functions for our associated content handler.
// 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']);
}
/**
......@@ -274,9 +348,13 @@ function taxonomy_display_taxonomy_display_plugins() {
// 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.
// Note: All of the class's files are in our module's .info files array.
//
// Note: All of the class's files are in our module's .info files array so
// that auto loading works.
'associated' => array(
// TODO: Add core, hidden, views
'TaxonomyDisplayAssociatedDisplayHandlerCore' => t('Core'),
'TaxonomyDisplayAssociatedDisplayHandlerHidden' => t('Hidden'),
),
'term' => array(
'TaxonomyDisplayTermDisplayHandlerCore' => t('Core'),
......@@ -304,8 +382,6 @@ function taxonomy_display_taxonomy_display_plugins() {
* WATCHDOG_NOTICE.
*
* @return void
*
* @todo test this works
*/
function taxonomy_display_save_taxonomy_display($machine_name, $save_data = array(), $watchdog_message = NULL, $watchdog_variables = array(), $watchdog_severity = WATCHDOG_NOTICE) {
// Prepare the fields to be used for the insert or update query.
......@@ -414,6 +490,7 @@ function taxonomy_display_taxonomy_term_page($term) {
$display_settings = taxonomy_display_fetch_taxonomy_display($term->vocabulary_machine_name);
// TODO: Move term display and associated display in to a helper function.
// Term display
// Set the default display handler if one is not set or the plugin is missing.
if (!$display_settings || !class_exists($display_settings['term_display_plugin'], TRUE)) {
......@@ -423,7 +500,7 @@ function taxonomy_display_taxonomy_term_page($term) {
}
// Set the term display options.
if (!$display_settings || !isset($display_settings['term_display_options'])) {
$display_settings['term_display_options'] = null;
$display_settings['term_display_options'] = NULL;
}
else {
$display_settings['term_display_options'] = unserialize($display_settings['term_display_options']);
......@@ -431,13 +508,22 @@ function taxonomy_display_taxonomy_term_page($term) {
$term_display = new $display_settings['term_display_plugin'];
$build['term_heading'] = $term_display->displayTerm($term, $display_settings['term_display_options']);
// @todo Associated content display
// Example build
// TODO: remove
if (false) {
$build = taxonomy_term_page($term);
// Associated content display
// Set the default display handler if one is not set or the plugin is missing.
if (!$display_settings || !class_exists($display_settings['associated_display_plugin'], TRUE)) {
$display_settings = array(
'term_display_plugin' => 'TaxonomyDisplayAssociatedDisplayHandlerCore',
);
}
// Set the associated display options.
if (!$display_settings || !isset($display_settings['associated_display_options'])) {
$display_settings['associated_display_options'] = NULL;
}
else {
$display_settings['associated_display_options'] = unserialize($display_settings['associated_display_options']);
}
$term_display = new $display_settings['associated_display_plugin'];
$build = array_merge($build, $term_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