Commit a9b5c816 authored by alexpott's avatar alexpott

Revert "Issue #1987124 by tim.plunkett, h3rj4n, dawehner: Convert...

Revert "Issue #1987124 by tim.plunkett, h3rj4n, dawehner: Convert filter_admin_format_page() and filter_admin_overview() to a Controller."

This reverts commit af5478b8.
parent 104b4360
......@@ -162,8 +162,6 @@ protected function match(array $condition, $value) {
return $value >= $condition['value'];
case '<=':
return $value <= $condition['value'];
case '<>':
return $value != $condition['value'];
case 'IN':
return array_search($value, $condition['value']) !== FALSE;
case 'NOT IN':
......
......@@ -426,10 +426,6 @@ protected function submitEntityLanguage(array $form, array &$form_state) {
*/
public function buildEntity(array $form, array &$form_state) {
$entity = clone $this->entity;
// If you submit a form, the form state comes from caching, which forces
// the controller to be the one before caching. Ensure to have the
// controller of the current request.
$form_state['controller'] = $this;
// @todo Move entity_form_submit_build_entity() here.
// @todo Exploit the Field API to process the submitted entity field.
entity_form_submit_build_entity($entity->entityType(), $entity, $form, $form_state);
......
......@@ -51,7 +51,7 @@ function testAdmin() {
$ckeditor = $manager->createInstance('ckeditor');
$this->drupalLogin($this->admin_user);
$this->drupalGet('admin/config/content/formats/manage/filtered_html');
$this->drupalGet('admin/config/content/formats/filtered_html');
// Ensure no Editor config entity exists yet.
$editor = entity_load('editor', 'filtered_html');
......@@ -118,7 +118,7 @@ function testAdmin() {
$this->assertIdentical($expected_settings, $editor->settings, 'The Editor config entity has the correct settings.');
// Configure the Styles plugin, and ensure the updated settings are saved.
$this->drupalGet('admin/config/content/formats/manage/filtered_html');
$this->drupalGet('admin/config/content/formats/filtered_html');
$edit = array(
'editor[settings][plugins][stylescombo][styles]' => "h1.title|Title\np.callout|Callout\n\n",
);
......@@ -131,7 +131,7 @@ function testAdmin() {
// Change the buttons that appear on the toolbar (in JavaScript, this is
// done via drag and drop, but here we can only emulate the end result of
// that interaction). Test multiple toolbar rows and a divider within a row.
$this->drupalGet('admin/config/content/formats/manage/filtered_html');
$this->drupalGet('admin/config/content/formats/filtered_html');
$expected_settings['toolbar']['buttons'] = array(
array('Undo', '|', 'Redo'),
array('JustifyCenter'),
......@@ -148,7 +148,7 @@ function testAdmin() {
// CKEditor plugin — this should not affect the Editor config entity.
module_enable(array('ckeditor_test'));
drupal_container()->get('plugin.manager.ckeditor.plugin')->clearCachedDefinitions();
$this->drupalGet('admin/config/content/formats/manage/filtered_html');
$this->drupalGet('admin/config/content/formats/filtered_html');
$ultra_llama_mode_checkbox = $this->xpath('//input[@type="checkbox" and @name="editor[settings][plugins][llama_contextual_and_button][ultra_llama_mode]" and not(@checked)]');
$this->assertTrue(count($ultra_llama_mode_checkbox) === 1, 'The "Ultra llama mode" checkbox exists and is not checked.');
$editor = entity_load('editor', 'filtered_html');
......@@ -156,12 +156,12 @@ function testAdmin() {
$this->assertIdentical($expected_settings, $editor->settings, 'The Editor config entity has the correct settings.');
// Finally, check the "Ultra llama mode" checkbox.
$this->drupalGet('admin/config/content/formats/manage/filtered_html');
$this->drupalGet('admin/config/content/formats/filtered_html');
$edit = array(
'editor[settings][plugins][llama_contextual_and_button][ultra_llama_mode]' => '1',
);
$this->drupalPost(NULL, $edit, t('Save configuration'));
$this->drupalGet('admin/config/content/formats/manage/filtered_html');
$this->drupalGet('admin/config/content/formats/filtered_html');
$ultra_llama_mode_checkbox = $this->xpath('//input[@type="checkbox" and @name="editor[settings][plugins][llama_contextual_and_button][ultra_llama_mode]" and @checked="checked"]');
$this->assertTrue(count($ultra_llama_mode_checkbox) === 1, 'The "Ultra llama mode" checkbox exists and is checked.');
$expected_settings['plugins']['llama_contextual_and_button']['ultra_llama_mode'] = '1';
......
......@@ -156,11 +156,11 @@ function editor_form_filter_admin_overview_alter(&$form, $form_state) {
}
/**
* Implements hook_form_BASE_FORM_ID_alter() for 'filter_format_form'.
* Implements hook_form_FORM_ID_alter().
*/
function editor_form_filter_format_form_alter(&$form, &$form_state) {
function editor_form_filter_admin_format_form_alter(&$form, &$form_state) {
if (!isset($form_state['editor'])) {
$format_id = $form_state['controller']->getEntity()->id();
$format_id = $form['#format']->format;
$form_state['editor'] = editor_load($format_id);
$form_state['editor_manager'] = Drupal::service('plugin.manager.editor');
}
......@@ -226,15 +226,15 @@ function editor_form_filter_format_form_alter(&$form, &$form_state) {
$settings_form['#element_validate'][] = array($plugin, 'settingsFormValidate');
$form['editor']['settings']['subform'] = $plugin->settingsForm($settings_form, $form_state, $editor);
$form['editor']['settings']['subform']['#parents'] = array('editor', 'settings');
$form['actions']['submit']['#submit'][] = array($plugin, 'settingsFormSubmit');
$form['#submit'][] = array($plugin, 'settingsFormSubmit');
}
$form['#validate'][] = 'editor_form_filter_admin_format_validate';
$form['actions']['submit']['#submit'][] = 'editor_form_filter_admin_format_submit';
$form['#submit'][] = 'editor_form_filter_admin_format_submit';
}
/**
* Button submit handler for filter_format_form()'s 'editor_configure' button.
* Button submit handler for filter_admin_format_form()'s 'editor_configure' button.
*/
function editor_form_filter_admin_format_editor_configure($form, &$form_state) {
$editor = $form_state['editor'];
......@@ -244,7 +244,7 @@ function editor_form_filter_admin_format_editor_configure($form, &$form_state) {
}
elseif (empty($editor) || $form_state['values']['editor']['editor'] !== $editor->editor) {
$editor = entity_create('editor', array(
'format' => $form_state['controller']->getEntity()->id(),
'format' => $form['#format']->format,
'editor' => $form_state['values']['editor']['editor'],
));
$form_state['editor'] = $editor;
......@@ -254,14 +254,14 @@ function editor_form_filter_admin_format_editor_configure($form, &$form_state) {
}
/**
* AJAX callback handler for filter_format_form().
* AJAX callback handler for filter_admin_format_form().
*/
function editor_form_filter_admin_form_ajax($form, &$form_state) {
return $form['editor']['settings'];
}
/**
* Additional validate handler for filter_format_form().
* Additional validate handler for filter_admin_format_form().
*/
function editor_form_filter_admin_format_validate($form, &$form_state) {
// This validate handler is not applicable when using the 'Configure' button.
......@@ -279,11 +279,11 @@ function editor_form_filter_admin_format_validate($form, &$form_state) {
}
/**
* Additional submit handler for filter_format_form().
* Additional submit handler for filter_admin_format_form().
*/
function editor_form_filter_admin_format_submit($form, &$form_state) {
// Delete the existing editor if disabling or switching between editors.
$format_id = $form_state['controller']->getEntity()->id();
$format_id = $form['#format']->format;
$original_editor = editor_load($format_id);
if ($original_editor && $original_editor->editor != $form_state['values']['editor']) {
$original_editor->delete();
......@@ -293,7 +293,7 @@ function editor_form_filter_admin_format_submit($form, &$form_state) {
if ($form_state['editor'] !== FALSE) {
// Ensure the text format is set: when creating a new text format, this
// would equal the empty string.
$form_state['editor']->format = $format_id;
$form_state['editor']->format = $form['#format']->format;
$form_state['editor']->settings = $form_state['values']['editor']['settings'];
$form_state['editor']->save();
}
......
......@@ -50,7 +50,7 @@ function setUp() {
*/
function testNoEditorAvailable() {
$this->drupalLogin($this->admin_user);
$this->drupalGet('admin/config/content/formats/manage/filtered_html');
$this->drupalGet('admin/config/content/formats/filtered_html');
// Ensure the form field order is correct.
$roles_pos = strpos($this->drupalGetContent(), 'Roles');
......@@ -75,7 +75,7 @@ function testNoEditorAvailable() {
function testAddEditorToExistingFormat() {
$this->enableUnicornEditor();
$this->drupalLogin($this->admin_user);
$this->drupalGet('admin/config/content/formats/manage/filtered_html');
$this->drupalGet('admin/config/content/formats/filtered_html');
$edit = $this->selectUnicornEditor();
// Configure Unicorn Editor's setting to another value.
$edit['editor[settings][foo]'] = 'baz';
......@@ -155,7 +155,7 @@ protected function verifyUnicornEditorConfiguration($format_id, $foo = 'bar') {
$this->assertIdentical($editor->settings['ponies too'], true, 'The text editor defaults are retrieved correctly.');
$this->assertIdentical($editor->settings['rainbows'], true, 'The text editor defaults added by hook_editor_settings_defaults() are retrieved correctly.');
$this->assertIdentical($editor->settings['sparkles'], false, 'The text editor defaults modified by hook_editor_settings_defaults_alter() are retrieved correctly.');
$this->drupalGet('admin/config/content/formats/manage/'. $format_id);
$this->drupalGet('admin/config/content/formats/'. $format_id);
$select = $this->xpath('//select[@name="editor[editor]"]');
$select_is_disabled = $this->xpath('//select[@name="editor[editor]" and @disabled="disabled"]');
$options = $this->xpath('//select[@name="editor[editor]"]/option');
......
This diff is collapsed.
......@@ -65,7 +65,7 @@ function filter_help($path, $arg) {
$output .= '<p>' . t('Text formats are presented on content editing pages in the order defined on this page. The first format available to a user will be selected by default.') . '</p>';
return $output;
case 'admin/config/content/formats/manage/%':
case 'admin/config/content/formats/%':
$output = '<p>' . t('A text format contains filters that change the user input, for example stripping out malicious HTML or making URLs clickable. Filters are executed from top to bottom and the order is important, since one filter may prevent another filter from doing its job. For example, when URLs are converted into links before disallowed HTML tags are removed, all links may be removed. When this happens, the order of filters may need to be re-arranged.') . '</p>';
return $output;
}
......@@ -123,7 +123,10 @@ function filter_menu() {
$items['admin/config/content/formats'] = array(
'title' => 'Text formats',
'description' => 'Configure how content input by users is filtered, including allowed HTML tags. Also allows enabling of module-provided filters.',
'route_name' => 'filter_admin_overview',
'page callback' => 'drupal_get_form',
'page arguments' => array('filter_admin_overview'),
'access arguments' => array('administer filters'),
'file' => 'filter.admin.inc',
);
$items['admin/config/content/formats/list'] = array(
'title' => 'List',
......@@ -131,15 +134,20 @@ function filter_menu() {
);
$items['admin/config/content/formats/add'] = array(
'title' => 'Add text format',
'route_name' => 'filter_format_add',
'page callback' => 'filter_admin_format_page',
'access arguments' => array('administer filters'),
'type' => MENU_LOCAL_ACTION,
'file' => 'filter.admin.inc',
);
$items['admin/config/content/formats/manage/%'] = array(
$items['admin/config/content/formats/%filter_format'] = array(
'title callback' => 'filter_admin_format_title',
'title arguments' => array(5),
'route_name' => 'filter_format_edit',
'title arguments' => array(4),
'page callback' => 'filter_admin_format_page',
'page arguments' => array(4),
'access arguments' => array('administer filters'),
'file' => 'filter.admin.inc',
);
$items['admin/config/content/formats/manage/%/disable'] = array(
$items['admin/config/content/formats/%filter_format/disable'] = array(
'title' => 'Disable text format',
'route_name' => 'filter_admin_disable',
);
......@@ -186,16 +194,16 @@ function filter_format_exists($format_id) {
/**
* Displays a text format form title.
*
* @param string $format_id
* A format ID.
* @param object $format_id
* A format object.
*
* @return string
* The name of the format.
*
* @see filter_menu()
*/
function filter_admin_format_title($format_id) {
if ($format = filter_format_load($format_id)) {
return $format->label();
}
function filter_admin_format_title($format) {
return $format->name;
}
/**
......@@ -217,7 +225,7 @@ function filter_permission() {
if (!empty($permission)) {
// Only link to the text format configuration page if the user who is
// viewing this will have access to that page.
$format_name_replacement = user_access('administer filters') ? l($format->name, 'admin/config/content/formats/manage/' . $format->format) : drupal_placeholder($format->name);
$format_name_replacement = user_access('administer filters') ? l($format->name, 'admin/config/content/formats/' . $format->format) : drupal_placeholder($format->name);
$perms[$permission] = array(
'title' => t("Use the !text_format text format", array('!text_format' => $format_name_replacement,)),
'description' => drupal_placeholder(t('Warning: This permission may have security implications depending on how the text format is configured.')),
......
filter_admin_disable:
pattern: '/admin/config/content/formats/{filter_format}/disable'
defaults:
_entity_form: 'filter_format.disable'
requirements:
_filter_disable_format_access: 'TRUE'
filter_tips_all:
pattern: '/filter/tips'
defaults:
......@@ -11,32 +18,3 @@ filter_tips:
_content: '\Drupal\filter\Controller\FilterController::filterTips'
requirements:
_filter_access: 'TRUE'
filter_admin_overview:
pattern: '/admin/config/content/formats'
defaults:
_content: '\Drupal\Core\Entity\Controller\EntityListController::listing'
entity_type: 'filter_format'
requirements:
_permission: 'administer filters'
filter_format_add:
pattern: '/admin/config/content/formats/add'
defaults:
_entity_form: filter_format.add
requirements:
_permission: 'administer filters'
filter_format_edit:
pattern: '/admin/config/content/formats/manage/{filter_format}'
defaults:
_entity_form: filter_format.edit
requirements:
_permission: 'administer filters'
filter_admin_disable:
pattern: '/admin/config/content/formats/manage/{filter_format}/disable'
defaults:
_entity_form: 'filter_format.disable'
requirements:
_filter_disable_format_access: 'TRUE'
<?php
/**
* @file
* Contains \Drupal\filter\FilterFormatAddFormController.
*/
namespace Drupal\filter;
/**
* Provides a form controller for adding a filter format.
*/
class FilterFormatAddFormController extends FilterFormatFormControllerBase {
/**
* {@inheritdoc}
*/
public function form(array $form, array &$form_state) {
drupal_set_title('Add text format');
return parent::form($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submit(array $form, array &$form_state) {
parent::submit($form, $form_state);
drupal_set_message(t('Added text format %format.', array('%format' => $this->entity->label())));
return $this->entity;
}
}
<?php
/**
* @file
* Contains \Drupal\filter\FilterFormatEditFormController.
*/
namespace Drupal\filter;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/**
* Provides a form controller for adding a filter format.
*/
class FilterFormatEditFormController extends FilterFormatFormControllerBase {
/**
* {@inheritdoc}
*/
public function form(array $form, array &$form_state) {
if (!$this->entity->status()) {
throw new NotFoundHttpException();
}
drupal_set_title($this->entity->label());
$form = parent::form($form, $form_state);
$form['roles']['#default_value'] = array_keys(filter_get_roles_by_format($this->entity));
return $form;
}
/**
* {@inheritdoc}
*/
public function submit(array $form, array &$form_state) {
parent::submit($form, $form_state);
drupal_set_message(t('The text format %format has been updated.', array('%format' => $this->entity->label())));
return $this->entity;
}
}
<?php
/**
* @file
* Contains \Drupal\filter\FilterFormatFormControllerBase.
*/
namespace Drupal\filter;
use Drupal\Core\Config\ConfigFactory;
use Drupal\Core\Entity\EntityControllerInterface;
use Drupal\Core\Entity\EntityFormController;
use Drupal\Core\Entity\Query\QueryFactory;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Provides a base form controller for a filter format.
*/
abstract class FilterFormatFormControllerBase extends EntityFormController implements EntityControllerInterface {
/**
* The config factory.
*
* @var \Drupal\Core\Config\ConfigFactory
*/
protected $configFactory;
/**
* The entity query factory.
*
* @var \Drupal\Core\Entity\Query\QueryFactory
*/
protected $queryFactory;
/**
* Constructs a new FilterFormatFormControllerBase.
*
* @param \Drupal\Core\Config\ConfigFactory $config_factory
* The config factory.
* @param \Drupal\Core\Entity\Query\QueryFactory $query_factory
* The entity query factory.
*/
public function __construct(ConfigFactory $config_factory, QueryFactory $query_factory) {
$this->configFactory = $config_factory;
$this->queryFactory = $query_factory;
}
/**
* {@inheritdoc}
*/
public static function createInstance(ContainerInterface $container, $entity_type, array $entity_info) {
return new static(
$container->get('config.factory'),
$container->get('entity.query')
);
}
/**
* {@inheritdoc}
*/
public function form(array $form, array &$form_state) {
$format = $this->entity;
$is_fallback = ($format->id() == $this->configFactory->get('filter.settings')->get('fallback_format'));
$form['#tree'] = TRUE;
$form['#attached']['library'][] = array('filter', 'drupal.filter.admin');
$form['name'] = array(
'#type' => 'textfield',
'#title' => t('Name'),
'#default_value' => $format->label(),
'#required' => TRUE,
'#weight' => -30,
);
$form['format'] = array(
'#type' => 'machine_name',
'#required' => TRUE,
'#default_value' => $format->id(),
'#maxlength' => 255,
'#machine_name' => array(
'exists' => 'filter_format_exists',
'source' => array('name'),
),
'#disabled' => !$format->isNew(),
'#weight' => -20,
);
// Add user role access selection.
$form['roles'] = array(
'#type' => 'checkboxes',
'#title' => t('Roles'),
'#options' => array_map('\Drupal\Component\Utility\String::checkPlain', user_role_names()),
'#disabled' => $is_fallback,
'#weight' => -10,
);
if ($is_fallback) {
$form['roles']['#description'] = t('All roles for this text format must be enabled and cannot be changed.');
}
if (!$format->isNew()) {
// If editing an existing text format, pre-select its current permissions.
$form['roles']['#default_value'] = array_keys(filter_get_roles_by_format($format));
}
elseif ($admin_role = $this->configFactory->get('user.settings')->get('admin_role')) {
// If adding a new text format and the site has an administrative role,
// pre-select that role so as to grant administrators access to the new
// text format permission by default.
$form['roles']['#default_value'] = array($admin_role);
}
// Create filter plugin instances for all available filters, including both
// enabled/configured ones as well as new and not yet unconfigured ones.
$filters = $format->filters()->sort();
// Filter status.
$form['filters']['status'] = array(
'#type' => 'item',
'#title' => t('Enabled filters'),
'#prefix' => '<div id="filters-status-wrapper">',
'#suffix' => '</div>',
// 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,
);
// Filter order (tabledrag).
$form['filters']['order'] = array(
'#type' => 'table',
// For filter.admin.js
'#attributes' => array('id' => 'filter-order'),
'#title' => t('Filter processing order'),
'#tabledrag' => array(
array('order', 'sibling', 'filter-order-weight'),
),
'#tree' => FALSE,
'#input' => FALSE,
'#theme_wrappers' => array('form_element'),
);
// Filter settings.
$form['filter_settings'] = array(
'#type' => 'vertical_tabs',
'#title' => t('Filter settings'),
);
foreach ($filters as $name => $filter) {
$form['filters']['status'][$name] = array(
'#type' => 'checkbox',
'#title' => $filter->getLabel(),
'#default_value' => $filter->status,
'#parents' => array('filters', $name, 'status'),
'#description' => $filter->getDescription(),
'#weight' => $filter->weight,
);
$form['filters']['order'][$name]['#attributes']['class'][] = 'draggable';
$form['filters']['order'][$name]['#weight'] = $filter->weight;
$form['filters']['order'][$name]['filter'] = array(
'#markup' => $filter->getLabel(),
);
$form['filters']['order'][$name]['weight'] = array(
'#type' => 'weight',
'#title' => t('Weight for @title', array('@title' => $filter->getLabel())),
'#title_display' => 'invisible',
'#delta' => 50,
'#default_value' => $filter->weight,
'#parents' => array('filters', $name, 'weight'),
'#attributes' => array('class' => array('filter-order-weight')),
);
// Retrieve the settings form of the filter plugin. The plugin should not be
// aware of the text format. Therefore, it only receives a set of minimal
// base properties to allow advanced implementations to work.
$settings_form = array(
'#parents' => array('filters', $name, 'settings'),
'#tree' => TRUE,
);
$settings_form = $filter->settingsForm($settings_form, $form_state);
if (!empty($settings_form)) {
$form['filters']['settings'][$name] = array(
'#type' => 'details',
'#title' => $filter->getLabel(),
'#weight' => $filter->weight,
'#parents' => array('filters', $name, 'settings'),
'#group' => 'filter_settings',
);
$form['filters']['settings'][$name] += $settings_form;
}
}
return parent::form($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function validate(array $form, array &$form_state) {
parent::validate($form, $form_state);
// @todo Move trimming upstream.
$format_format = trim($form_state['values']['format']);
$format_name = trim($form_state['values']['name']);
// Ensure that the values to be saved later are exactly the ones validated.
form_set_value($form['format'], $format_format, $form_state);
form_set_value($form['name'], $format_name, $form_state);
$format_exists = $this->queryFactory
->get('filter_format')
->condition('format', $format_format, '<>')
->condition('name', $format_name)
->execute();
if ($format_exists) {
form_set_error('name', t('Text format names must be unique. A format named %name already exists.', array('%name' => $format_name)));
}
}
/**
* {@inheritdoc}
*/
public function submit(array $form, array &$form_state) {
parent::submit($form, $form_state);
// Add the submitted form values to the text format, and save it.
$format = $this->entity;
foreach ($form_state['values'] as $key => $value) {
if ($key != 'filters') {
$format->set($key, $value);
}
else {
foreach ($value as $instance_id => $config) {
$format->setFilterConfig($instance_id, $config);
}
}
}
$format->save();
// Save user permissions.
if ($permission = filter_permission_name($format)) {
foreach ($form_state['values']['roles'] as $rid => $enabled) {
user_role_change_permissions($rid, array($permission => $enabled));
}
}
$form_state['redirect'] = 'admin/config/content/formats';
return $this->entity;
}
/**
* {@inheritdoc}
*/
protected function actions(array $form, array &$form_state) {
$actions = parent::actions($form, $form_state);
$actions['submit']['#value'] = t('Save configuration');
unset($actions['delete']);
return $actions;
}
}
<?php
/**
* @file
* Contains \Drupal\filter\FilterFormatListController.
*/
namespace Drupal\filter;
use Drupal\Component\Utility\String;
use Drupal\Core\Config\ConfigFactory;
use Drupal\Core\Config\Entity\ConfigEntityListController;
use Drupal\Core\Entity\EntityStorageControllerInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Form\FormInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Defines the filter format list controller.
*/
class FilterFormatListController extends ConfigEntityListController implements FormInterface {
/**
* The entities being listed.
*
* @var array
*/
protected $entities;
/**
* The config factory service.
*
* @var \Drupal\Core\Config\ConfigFactory
*/
protected $configFactory;
/**
* Constructs a new FilterFormatListController.
*
* @param string $entity_type
* The type of entity to be listed.
* @param array $entity_info
* An array of entity info for the entity type.
* @param \Drupal\Core\Entity\EntityStorageControllerInterface $storage