|
@@ -72,7 +72,10 @@ function _url_replace_filter_settings($format) {
|
|
|
'#theme' => 'url_replace_filter_settings_form',
|
|
|
'#tree' => TRUE,
|
|
|
);
|
|
|
+ $form['#submit'][] = '_url_replace_filter_settings_form_submit';
|
|
|
+
|
|
|
$settings = _url_replace_filter_get_settings($format);
|
|
|
+ $index = 0;
|
|
|
foreach ($settings as $index => $setting) {
|
|
|
_url_replace_filter_row_form($form, $format, $index, $setting['original'], $setting['replacement']);
|
|
|
if (!$setting['original']) {
|
|
@@ -88,6 +91,32 @@ function _url_replace_filter_settings($format) {
|
|
|
return $form;
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * Submit handler for _url_replace_filter_settings() form.
|
|
|
+ *
|
|
|
+ * - Remove useless empty settings to keep variable as small as possible.
|
|
|
+ */
|
|
|
+function _url_replace_filter_settings_form_submit($form, &$form_state) {
|
|
|
+ $format = $form_state['values']['format'];
|
|
|
+ $format_id = 'url_replace_filter_' . $format;
|
|
|
+ if (!isset($form_state['values'][$format_id])) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // Remove empty sets.
|
|
|
+ foreach ($form_state['values'][$format_id] as $key => $value) {
|
|
|
+ if (empty($value['original']) && empty($value['replacement'])) {
|
|
|
+ unset($form_state['values'][$format_id][$key]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (empty($form_state['values'][$format_id])) {
|
|
|
+ drupal_set_message(t('URL Replace filter configuration is empty : you could <a href="!edit">remove it</a> from this input format.', array(
|
|
|
+ '!edit' => check_url(url('admin/settings/filters/1')),
|
|
|
+ )), 'warning');
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
function _url_replace_filter_row_form(&$form, $format, $index, $original, $replacement) {
|
|
|
$form['url_replace_filter_'. $format][$index]['original'] = array(
|
|
|
'#type' => 'textfield',
|