Commit 933b67c4 authored by webchick's avatar webchick
Browse files

Issue #1808648 by damiankloip, fastangel: Move tokenization form code into AreaPluginBase.

parent 17abb703
......@@ -81,7 +81,6 @@ public function buildOptionsForm(&$form, &$form_state) {
'#description' => t('The label for this area that will be displayed only administratively.'),
);
if ($form_state['type'] != 'empty') {
$form['empty'] = array(
'#type' => 'checkbox',
......@@ -91,6 +90,59 @@ public function buildOptionsForm(&$form, &$form_state) {
}
}
/**
* Form helper function to add tokenization form elements.
*/
public function tokenForm(&$form, &$form_state) {
$form['tokenize'] = array(
'#type' => 'checkbox',
'#title' => t('Use replacement tokens from the first row'),
'#default_value' => $this->options['tokenize'],
);
// Get a list of the available fields and arguments for token replacement.
$options = array();
foreach ($this->view->display_handler->getHandlers('field') as $field => $handler) {
$options[t('Fields')]["[$field]"] = $handler->adminLabel();
}
$count = 0; // This lets us prepare the key as we want it printed.
foreach ($this->view->display_handler->getHandlers('argument') as $arg => $handler) {
$options[t('Arguments')]['%' . ++$count] = t('@argument title', array('@argument' => $handler->adminLabel()));
$options[t('Arguments')]['!' . $count] = t('@argument input', array('@argument' => $handler->adminLabel()));
}
if (!empty($options)) {
$form['tokens'] = array(
'#type' => 'fieldset',
'#title' => t('Replacement patterns'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#id' => 'edit-options-token-help',
'#states' => array(
'visible' => array(
':input[name="options[tokenize]"]' => array('checked' => TRUE),
),
),
);
$form['tokens']['help'] = array(
'#markup' => '<p>' . t('The following tokens are available. If you would like to have the characters \'[\' and \']\' please use the html entity codes \'%5B\' or \'%5D\' or they will get replaced with empty space.') . '</p>',
);
foreach (array_keys($options) as $type) {
if (!empty($options[$type])) {
$items = array();
foreach ($options[$type] as $key => $value) {
$items[] = $key . ' == ' . $value;
}
$form['tokens']['tokens'] = array(
'#theme' => 'item_list',
'#items' => $items,
);
}
}
}
}
/**
* Don't run a query
*/
......
......@@ -39,55 +39,8 @@ public function buildOptionsForm(&$form, &$form_state) {
'#wysiwyg' => FALSE,
);
$form['tokenize'] = array(
'#type' => 'checkbox',
'#title' => t('Use replacement tokens from the first row'),
'#default_value' => $this->options['tokenize'],
);
// Get a list of the available fields and arguments for token replacement.
$options = array();
foreach ($this->view->display_handler->getHandlers('field') as $field => $handler) {
$options[t('Fields')]["[$field]"] = $handler->adminLabel();
}
$count = 0; // This lets us prepare the key as we want it printed.
foreach ($this->view->display_handler->getHandlers('argument') as $arg => $handler) {
$options[t('Arguments')]['%' . ++$count] = t('@argument title', array('@argument' => $handler->adminLabel()));
$options[t('Arguments')]['!' . $count] = t('@argument input', array('@argument' => $handler->adminLabel()));
}
if (!empty($options)) {
$output = '<p>' . t('The following tokens are available. If you would like to have the characters \'[\' and \']\' please use the html entity codes \'%5B\' or \'%5D\' or they will get replaced with empty space.' . '</p>');
foreach (array_keys($options) as $type) {
if (!empty($options[$type])) {
$items = array();
foreach ($options[$type] as $key => $value) {
$items[] = $key . ' == ' . $value;
}
$output .= theme('item_list',
array(
'items' => $items,
'type' => $type
));
}
}
$form['token_help'] = array(
'#type' => 'fieldset',
'#title' => t('Replacement patterns'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#value' => $output,
'#id' => 'edit-options-token-help',
'#states' => array(
'visible' => array(
':input[name="options[tokenize]"]' => array('checked' => TRUE),
),
),
);
}
// Add tokenization form elements.
$this->tokenForm($form, $form_state);
}
public function submitOptionsForm(&$form, &$form_state) {
......
......@@ -18,21 +18,26 @@
* id = "text_custom"
* )
*/
class TextCustom extends Text {
class TextCustom extends AreaPluginBase {
protected function defineOptions() {
$options = parent::defineOptions();
unset($options['format']);
$options['content'] = array('default' => '', 'translatable' => TRUE);
$options['tokenize'] = array('default' => FALSE, 'bool' => TRUE);
return $options;
}
public function buildOptionsForm(&$form, &$form_state) {
parent::buildOptionsForm($form, $form_state);
// Alter the form element, to be a regular text area.
$form['content']['#type'] = 'textarea';
unset($form['content']['#format']);
unset($form['content']['#wysiwyg']);
$form['content'] = array(
'#type' => 'textarea',
'#default_value' => $this->options['content'],
'#rows' => 6,
);
// Add tokenization form elements.
$this->tokenForm($form, $form_state);
}
// Empty, so we don't inherit submitOptionsForm from the parent.
......@@ -41,7 +46,7 @@ public function submitOptionsForm(&$form, &$form_state) {
function render($empty = FALSE) {
if (!$empty || !empty($this->options['empty'])) {
return $this->render_textarea_custom($this->options['content']);
return $this->render_textarea($this->options['content']);
}
return '';
......@@ -50,7 +55,7 @@ function render($empty = FALSE) {
/**
* Render a text area with filter_xss_admin.
*/
function render_textarea_custom($value) {
function render_textarea($value) {
if ($value) {
if ($this->options['tokenize']) {
$value = $this->view->style_plugin->tokenize_value($value, 0);
......
......@@ -26,7 +26,6 @@ class Title extends AreaPluginBase {
protected function defineOptions() {
$options = parent::defineOptions();
$options['title'] = array('default' => '', 'translatable' => TRUE);
return $options;
}
......@@ -42,7 +41,6 @@ public function buildOptionsForm(&$form, &$form_state) {
'#default_value' => $this->options['title'],
'#description' => t('Override the title of this view when it is empty.'),
);
}
/**
......@@ -50,7 +48,7 @@ public function buildOptionsForm(&$form, &$form_state) {
*/
function render($empty = FALSE) {
if (!empty($this->options['title'])) {
$this->view->setTitle(filter_xss_admin($this->options['title']), PASS_THROUGH);
$this->view->setTitle($this->sanitizeValue($this->options['title'], 'xss_admin'), PASS_THROUGH);
}
return '';
......
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