Commit 3429379c authored by Nicholas Thompson's avatar Nicholas Thompson
Browse files

Fixes to the Views handling side of things. Also managed to get a form alter...

Fixes to the Views handling side of things. Also managed to get a form alter to work on the Argument config ui. Basic testing is promising
parent e1f8c2d8
......@@ -25,20 +25,20 @@ function views_page_title_pattern_alter(&$pattern, &$types) {
if (!$view) return;
// If there are args for this view, process to see if this argument has a SPECIFIC page title pattern
if (!empty($args) && !empty($view->handlers['argument'])) {
if (!empty($args) && !empty($view->argument)) {
// Grab the argument handlers
$h = $view->handlers['argument'];
$h = $view->argument;
// Splice the arguments and get the key for the current arg.
$h = array_shift(array_splice($h, count($args)-1, 1));
// Get the Page Title Pattern from the options array for this handler
$pattern = isset($h->options['page_title_pattern']) ? $h->options['page_title_pattern'] : '';
$pattern = isset($h->options['page_title_pattern']) ? $h->options['page_title_pattern'] : $pattern;
// If a page title pattern was found AND it contains a "%", assume there are placeholders and apply the %1, %2 type placeholder replacement.
if (strpos($pattern, '%') !== FALSE) {
// Grab the pre-built substitutions
$subs = $view->view->build_info['substitutions'];
$subs = $view->build_info['substitutions'];
// Apply any subs to the pattern
$pattern = str_replace(array_keys($subs), $subs, $pattern);
......@@ -536,59 +536,70 @@ function page_title_init() {
* Form Alter handler for the views ui config form (used for filters and args)
TODO: Views 3.x uses the unpack function on arguments. This is clobbering any attempts to sneak a setting in on an argument
function page_title_form_views_ui_config_item_form_alter(&$form, &$form_state) {
// Don't bother altering non-argument forms
if ($form_state['type'] != 'argument') return;
$view = &$form_state['view'];
$display_handler = &$view->display_handler;
// Check the display handler is a page - if not, dont bother altering.
$type = get_class($form_state['view']->display_handler);
if ($type != 'page_title_plugin_display_page_with_page_title') return;
if ($display_handler->display->display_plugin != 'page_with_page_title') return;
// Now check the display is overriding the default - this is necessary as we cannot assign a page title to the default display.
if (!isset($form_state['view']->display_handler->options['arguments'])) return;
// Now check the display has arguments. This ensures we are on an overidden Contextual Filter
if (empty($display_handler->options['arguments'])) return;
list($display_id, $section, $section_id) = explode('-', $form['#secton']);
$argument_handler = &$form_state['handler'];
// Build a page title options fieldset wrapper
$temp_form['page_title_pattern'] = array(
$form['options']['page_title_pattern'] = array(
'#type' => 'fieldset',
'#title' => t('Page Title'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#weight' => 120,
// Add the Page Title field
$temp_form['page_title_pattern']['page_title_pattern'] = array(
$form['options']['page_title_pattern']['page_title_pattern'] = array(
'#type' => 'textfield',
'#title' => t('Page Title Pattern'),
'#description' => t('Optionally enter a Page Title Pattern for this argument. This will override the main view Page Title Pattern. You can also use the tokens below.'),
'#default_value' => $form_state['handler']->options['page_title_pattern'],
'#default_value' => $argument_handler->options['page_title_pattern'],
'#parents' => array('options', 'page_title_pattern'),
'#element_validate' => array('token_element_validate_token_context'),
'#token_types' => array(),
// Add the token help to a collapsed fieldset at the end of the configuration page.
$temp_form['page_title_pattern']['token_help'] = array(
$form['options']['page_title_pattern']['token_help'] = array(
'#type' => 'fieldset',
'#title' => t('Available Tokens List'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
$temp_form['page_title_pattern']['token_help']['content'] = array(
$form['options']['page_title_pattern']['token_help']['content'] = array(
'#theme' => 'token_tree',
'#token_types' => array(),
$form['buttons']['submit']['#submit'][] = 'page_title_form_views_ui_config_item_form_alter_submit';
// Splice the temp form into the main form. We do this because there are no weights in the views form meaning Page Title can either be top or bottom (-1 or 1).
$offset = array_search('title', array_keys($form['options']));
$spliced_form = array_splice($form['options'], 0, $offset);
$form['options'] = array_merge($spliced_form, $temp_form, $form['options']);
* Submit handler for the above Argument handling code
function page_title_form_views_ui_config_item_form_alter_submit($form, &$form_state) {
$options = &$form_state['values']['options'];
$page_title_pattern = isset($options['page_title_pattern']) ? $options['page_title_pattern'] : '';
$view = &$form_state['view'];
$view->set_item_option($form_state['display_id'], $form_state['type'], $form_state['id'], 'page_title_pattern', $page_title_pattern);
* Implementation of hook_views_api().
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