diff --git a/core/modules/filter/filter.admin.inc b/core/modules/filter/filter.admin.inc
index 806c1d7..48ee96c 100644
--- a/core/modules/filter/filter.admin.inc
+++ b/core/modules/filter/filter.admin.inc
@@ -236,15 +236,19 @@ function filter_admin_format_form($form, &$form_state, $format) {
// Filter order (tabledrag).
$form['filters']['order'] = array(
- '#type' => 'item',
+ '#type' => 'table',
+ // For filter.admin.js
+ '#attributes' => array('id' => 'filter-order'),
'#title' => t('Filter processing order'),
- '#theme' => 'filter_admin_format_filter_order',
- // This item is used as a pure wrapping container with heading. Ignore its
- // value, since 'filters' should only contain filter definitions.
- // @see http://drupal.org/node/1829202
- '#input' => FALSE,
+ '#tabledrag' => array(
+ array('order', 'sibling', 'filter-order-weight'),
+ ),
+ '#tree' => FALSE,
+ '#theme_wrappers' => array('form_element'),
);
foreach ($filter_info as $name => $filter) {
+ $form['filters']['order'][$name]['#attributes']['class'][] = 'draggable';
+ $form['filters']['order'][$name]['#weight'] = $filters[$name]->weight;
$form['filters']['order'][$name]['filter'] = array(
'#markup' => $filter['title'],
);
@@ -255,9 +259,12 @@ function filter_admin_format_form($form, &$form_state, $format) {
'#delta' => 50,
'#default_value' => $filters[$name]->weight,
'#parents' => array('filters', $name, 'weight'),
+ '#attributes' => array('class' => array('filter-order-weight')),
);
- $form['filters']['order'][$name]['#weight'] = $filters[$name]->weight;
}
+ // Make sure filters are in the correct order, since filter_get_filters()
+ // doesn't return sorted filters.
+ uasort($form['filters']['order'], 'element_sort');
// Filter settings.
$form['filter_settings'] = array(
@@ -291,37 +298,6 @@ function filter_admin_format_form($form, &$form_state, $format) {
}
/**
- * Returns HTML for a text format's filter order form.
- *
- * @param array $variables
- * An associative array containing:
- * - element: A render element representing the form.
- *
- * @ingroup themeable
- */
-function theme_filter_admin_format_filter_order($variables) {
- $element = $variables['element'];
-
- // Filter order (tabledrag).
- $rows = array();
- foreach (element_children($element, TRUE) as $name) {
- $element[$name]['weight']['#attributes']['class'][] = 'filter-order-weight';
- $rows[] = array(
- 'data' => array(
- drupal_render($element[$name]['filter']),
- drupal_render($element[$name]['weight']),
- ),
- 'class' => array('draggable'),
- );
- }
- $output = drupal_render_children($element);
- $output .= theme('table', array('rows' => $rows, 'attributes' => array('id' => 'filter-order')));
- drupal_add_tabledrag('filter-order', 'order', 'sibling', 'filter-order-weight', NULL, NULL, TRUE);
-
- return $output;
-}
-
-/**
* Form validation handler for filter_admin_format_form().
*
* @see filter_admin_format_form_submit()
diff --git a/core/modules/filter/filter.admin.js b/core/modules/filter/filter.admin.js
index f55159a..123576a 100644
--- a/core/modules/filter/filter.admin.js
+++ b/core/modules/filter/filter.admin.js
@@ -33,7 +33,7 @@ Drupal.behaviors.filterStatus = {
}
}
// Restripe table after toggling visibility of table row.
- Drupal.tableDrag['filter-order'].restripeTable();
+ Drupal.tableDrag['edit-filters-order'].restripeTable();
});
// Attach summary for configurable filters (only for screen-readers).
diff --git a/core/modules/filter/filter.module b/core/modules/filter/filter.module
index 725d931..5345335 100644
--- a/core/modules/filter/filter.module
+++ b/core/modules/filter/filter.module
@@ -74,22 +74,18 @@ function filter_help($path, $arg) {
*/
function filter_theme() {
return array(
- 'filter_admin_format_filter_order' => array(
- 'render element' => 'element',
- 'file' => 'filter.admin.inc',
- ),
'filter_tips' => array(
'variables' => array('tips' => NULL, 'long' => FALSE),
'file' => 'filter.pages.inc',
+ 'template' => 'filter-tips',
),
'text_format_wrapper' => array(
'render element' => 'element',
- ),
- 'filter_tips_more_info' => array(
- 'variables' => array(),
+ 'template' => 'text-format-wrapper',
),
'filter_guidelines' => array(
'variables' => array('format' => NULL),
+ 'template' => 'filter-guidelines',
),
'filter_html_image_secure_image' => array(
'variables' => array('image' => NULL),
@@ -919,11 +915,23 @@ function filter_process_format($element) {
'#parents' => array_merge($element['#parents'], array('format')),
);
+ $filter_tips_link = array(
+ '#theme' => 'link',
+ '#text' => t('More information about text formats'),
+ '#path' => 'filter/tips',
+ '#options' => array(
+ 'attributes' => array('target' => '_blank'),
+ 'html' => FALSE,
+ ),
+ '#prefix' => '
',
+ '#suffix' => '
',
+ );
+
$element['format']['help'] = array(
'#type' => 'container',
- '#theme' => 'filter_tips_more_info',
'#attributes' => array('class' => array('filter-help')),
'#weight' => 0,
+ $filter_tips_link,
);
$all_formats = filter_formats();
@@ -989,24 +997,20 @@ function filter_form_access_denied($element) {
}
/**
- * Returns HTML for a text format-enabled form element.
+ * Prepares variables for the text-format-wrapper template.
+ *
+ * Default template: text-format-wrapper.html.twig.
*
* @param array $variables
* An associative array containing:
* - element: A render element containing #children and #description.
- *
- * @ingroup themeable
*/
-function theme_text_format_wrapper($variables) {
+function template_preprocess_text_format_wrapper(&$variables) {
$element = $variables['element'];
- $output = '';
- $output .= $element['#children'];
+ $variables['children'] = $element['#children'];
if (!empty($element['#description'])) {
- $output .= '
' . $element['#description'] . '
';
+ $variables['description'] = $element['#description'];
}
- $output .= "
\n";
-
- return $output;
}
/**
@@ -1180,32 +1184,79 @@ function filter_dom_serialize_escape_cdata_element($dom_document, $dom_element,
}
/**
- * Returns HTML for a link to the more extensive filter tips.
+ * Prepares variables for guidelines for a text format.
+ *
+ * Default template: filter-guidelines.html.twig.
*
- * @ingroup themeable
+ * @param array $variables
+ * An associative array containing:
+ * - format: An object representing a text format.
*/
-function theme_filter_tips_more_info() {
- return '' . l(t('More information about text formats'), 'filter/tips', array('attributes' => array('target' => '_blank'))) . '
';
+function template_preprocess_filter_guidelines(&$variables) {
+ $format = $variables['format'];
+ $variables['attributes']['class'][] = 'filter-guidelines-item';
+ $variables['attributes']['class'][] = 'filter-guidelines-' . $format->format;
+ $variables['tips'] = array(
+ '#theme' => 'filter_tips',
+ '#tips' => _filter_tips($format->format, FALSE),
+ );
}
/**
- * Returns HTML for guidelines for a text format.
+ * Prepares variables for a set of filter tips
+ *
+ * Default template: filter-tips.html.twig.
*
* @param array $variables
* An associative array containing:
- * - format: An object representing a text format.
- *
- * @ingroup themeable
- */
-function theme_filter_guidelines($variables) {
- $format = $variables['format'];
- $attributes['class'][] = 'filter-guidelines-item';
- $attributes['class'][] = 'filter-guidelines-' . $format->format;
- $output = '';
- $output .= '
' . check_plain($format->name) . '
';
- $output .= theme('filter_tips', array('tips' => _filter_tips($format->format, FALSE)));
- $output .= '';
- return $output;
+ * - tips: An array containing descriptions and a CSS ID in the form of
+ * 'module-name/filter-id' (only used when $long is TRUE) for each
+ * filter in one or more text formats. Example:
+ * @code
+ * array(
+ * 'Full HTML' => array(
+ * 0 => array(
+ * 'tip' => 'Web page addresses and e-mail addresses turn into links automatically.',
+ * 'id' => 'filter/2',
+ * ),
+ * ),
+ * );
+ * @endcode
+ * - long: (optional) Whether the passed-in filter tips contain extended
+ * explanations, i.e. intended to be output on the path 'filter/tips'
+ * (TRUE), or are in a short format, i.e. suitable to be displayed below a
+ * form element. Defaults to FALSE.
+ */
+function template_preprocess_filter_tips(&$variables) {
+ $tips = $variables['tips'];
+ $long = $variables['long'];
+ $output = '';
+
+ $multiple = count($tips) > 1;
+
+ foreach ($variables['tips'] as $name => $tiplist) {
+ foreach ($tiplist as $tip_key => $tip) {
+ $tiplist[$tip_key]['attributes'] = new Attribute(array());
+ if ($long) {
+ $tiplist[$tip_key]['attributes']['class'] = array('filter-' . str_replace("/", "-", $tip['id']));
+ }
+ }
+
+ $attributes = array(
+ 'class' => array(
+ 'filter-type',
+ 'filter-' . drupal_html_class($name),
+ ),
+ );
+
+ $variables['tips'][$name] = array(
+ 'attributes' => new Attribute($attributes),
+ 'name' => check_plain($name),
+ 'list' => $tiplist,
+ );
+ }
+
+ $variables['multiple'] = $multiple;
}
/**
@@ -1818,18 +1869,15 @@ function _filter_html_image_secure_process($text) {
}
/**
- * Formats an image DOM element that has an invalid source.
- *
- * @param DOMElement $image
- * An IMG node to format, parsed from the filtered text.
+ * Prepares variables for Formats an image DOM element that has an invalid source.
*
- * @return void
- * Unlike other theme functions, the passed in $image is altered by reference.
+ * @param array $variables
+ * An associative array containing:
+ * - image: A DOMElement IMG node to format, parsed from the filtered text.
*
* @see _filter_html_image_secure_process()
- * @ingroup themeable
*/
-function theme_filter_html_image_secure_image(&$variables) {
+function template_preprocess_filter_html_image_secure_image(&$variables) {
$image = $variables['image'];
// Turn an invalid image into an error indicator.
diff --git a/core/modules/filter/filter.pages.inc b/core/modules/filter/filter.pages.inc
index 5b20d4f..f0ac5d6 100644
--- a/core/modules/filter/filter.pages.inc
+++ b/core/modules/filter/filter.pages.inc
@@ -19,76 +19,18 @@
*/
function filter_tips_long($format = NULL) {
if (!empty($format)) {
- $output = theme('filter_tips', array('tips' => _filter_tips($format->format, TRUE), 'long' => TRUE));
+ $filter_tips = array(
+ '#theme' => 'filter_tips',
+ '#tips' => _filter_tips($format->format, TRUE),
+ '#long' => TRUE,
+ );
}
else {
- $output = theme('filter_tips', array('tips' => _filter_tips(-1, TRUE), 'long' => TRUE));
+ $filter_tips = array(
+ '#theme' => 'filter_tips',
+ '#tips' => _filter_tips(-1, TRUE),
+ '#long' => TRUE,
+ );
}
- return $output;
-}
-
-/**
- * Returns HTML for a set of filter tips.
- *
- * @param array $variables
- * An associative array containing:
- * - tips: An array containing descriptions and a CSS ID in the form of
- * 'module-name/filter-id' (only used when $long is TRUE) for each
- * filter in one or more text formats. Example:
- * @code
- * array(
- * 'Full HTML' => array(
- * 0 => array(
- * 'tip' => 'Web page addresses and e-mail addresses turn into links automatically.',
- * 'id' => 'filter/2',
- * ),
- * ),
- * );
- * @endcode
- * - long: (optional) Whether the passed-in filter tips contain extended
- * explanations, i.e. intended to be output on the path 'filter/tips'
- * (TRUE), or are in a short format, i.e. suitable to be displayed below a
- * form element. Defaults to FALSE.
- *
- * @see _filter_tips()
- * @ingroup themeable
- */
-function theme_filter_tips($variables) {
- $tips = $variables['tips'];
- $long = $variables['long'];
- $output = '';
-
- $multiple = count($tips) > 1;
- if ($multiple) {
- $output = '' . t('Text Formats') . '
';
- }
-
- if (count($tips)) {
- if ($multiple) {
- $output .= '';
- }
- foreach ($tips as $name => $tiplist) {
- if ($multiple) {
- $output .= '
';
- $output .= '
' . $name . '
';
- }
-
- if (count($tiplist) > 0) {
- $output .= '
';
- foreach ($tiplist as $tip) {
- $output .= '- ' : '>') . $tip['tip'] . '
';
- }
- $output .= '
';
- }
-
- if ($multiple) {
- $output .= '
';
- }
- }
- if ($multiple) {
- $output .= '
';
- }
- }
-
- return $output;
+ return $filter_tips;
}
diff --git a/core/modules/filter/templates/filter-guidelines.html.twig b/core/modules/filter/templates/filter-guidelines.html.twig
new file mode 100644
index 0000000..c028aaa
--- /dev/null
+++ b/core/modules/filter/templates/filter-guidelines.html.twig
@@ -0,0 +1,24 @@
+{#
+/**
+ * @file
+ * Default theme implementation for guidelines for a text format.
+ *
+ * Available variables:
+ * - format: An object representing a text format.
+ * - attributes: Remaining html attributes for the containing element.
+ * - tips: Descriptions and a CSS id in the form of 'module-name/filter-id'
+ * (only used when $long is TRUE) for each filter in one or more text
+ * formats.
+ *
+ * @todo Remove striptags when auto_escape is resolved http://drupal.org/node/1712444.
+ *
+ * @see template_preprocess()
+ * @see template_preprocess_filter_tips()
+ *
+ * @ingroup themeable
+ */
+ #}
+
+
{{ format.name|striptags }}
+ {{ tips }}
+
diff --git a/core/modules/filter/templates/filter-tips.html.twig b/core/modules/filter/templates/filter-tips.html.twig
new file mode 100644
index 0000000..367730a
--- /dev/null
+++ b/core/modules/filter/templates/filter-tips.html.twig
@@ -0,0 +1,55 @@
+{#
+/**
+ * @file
+ * Default theme implementation for a set of filter tips.
+ *
+ * Available variables:
+ * - tips: Descriptions and a CSS id in the form of 'module-name/filter-id'
+ * (only used when $long is TRUE) for each filter in one or more text
+ * formats.
+ * - long: (optional) Whether the passed-in filter tips contain extended
+ * explanations, i.e. intended to be output on the path 'filter/tips'
+ * (TRUE), or are in a short format, i.e. suitable to be displayed below a
+ * form element. Defaults to FALSE.
+ *
+ * @todo reimplement once http://drupal.org/node/1778624 gets resolved.
+ *
+ * @see template_preprocess()
+ * @see template_preprocess_filter_tips()
+ *
+ * @ingroup themeable
+ */
+#}
+{% if multiple %}
+ {{ 'Text Formats'|t }}
+{% endif %}
+
+{% if tips|length %}
+ {% if multiple %}
+
+ {% endif %}
+
+ {% for tip in tips %}
+ {% if multiple %}
+
+
{{ tip.name }}
+ {% endif %}
+
+ {% if tip.list|length %}
+
+ {% for item in tip.list %}
+ {# Only set the class if the type is long #}
+ - {{ item.tip }}
+ {% endfor %}
+
+ {% endif %}
+
+ {% if multiple %}
+
+ {% endif %}
+ {% endfor %}
+
+ {% if multiple %}
+
+ {% endif %}
+{% endif %}
diff --git a/core/modules/filter/templates/text-format-wrapper.html.twig b/core/modules/filter/templates/text-format-wrapper.html.twig
new file mode 100644
index 0000000..013d899
--- /dev/null
+++ b/core/modules/filter/templates/text-format-wrapper.html.twig
@@ -0,0 +1,22 @@
+{#
+/**
+ * @file
+ * Default theme implementation for a text format-enabled form element.
+ *
+ * Available variables:
+ * - children: Text format element children.
+ * - description: Text format element description.
+ *
+ * @see template_preprocess()
+ * @see template_preprocess_text_format_wrapper()
+ *
+ * @ingroup themeable
+ */
+#}
+
+ {{ children }}
+ {% if description %}
+
{{ description }}
+ {% endif %}
+
+