Commit c221f346 authored by catch's avatar catch

Issue #1946410 by tim.plunkett: Convert confirm_form() in filter.admin.inc to...

Issue #1946410 by tim.plunkett: Convert confirm_form() in filter.admin.inc to the new form interface.
parent 1aa842c1
......@@ -355,35 +355,3 @@ function filter_admin_format_form_submit($form, &$form_state) {
$form_state['redirect'] = 'admin/config/content/formats';
}
/**
* Page callback: Form constructor to confirm the text format deletion.
*
* @param $format
* An object representing a text format.
*
* @see filter_menu()
* @see filter_admin_disable_submit()
* @ingroup forms
*/
function filter_admin_disable($form, &$form_state, $format) {
$form['#format'] = $format;
return confirm_form($form,
t('Are you sure you want to disable the text format %format?', array('%format' => $format->name)),
'admin/config/content/formats',
t('Disabled text formats are completely removed from the administrative interface, and any content stored with that format will not be displayed. This action cannot be undone.'),
t('Disable')
);
}
/**
* Form submission handler for filter_admin_disable().
*/
function filter_admin_disable_submit($form, &$form_state) {
$format = $form['#format'];
filter_format_disable($format);
drupal_set_message(t('Disabled text format %format.', array('%format' => $format->name)));
$form_state['redirect'] = 'admin/config/content/formats';
}
......@@ -149,32 +149,11 @@ function filter_menu() {
);
$items['admin/config/content/formats/%filter_format/disable'] = array(
'title' => 'Disable text format',
'page callback' => 'drupal_get_form',
'page arguments' => array('filter_admin_disable', 4),
'access callback' => '_filter_disable_format_access',
'access arguments' => array(4),
'file' => 'filter.admin.inc',
'route_name' => 'filter_admin_disable',
);
return $items;
}
/**
* Access callback: Checks access for disabling text formats.
*
* @param $format
* A text format object.
*
* @return
* TRUE if the text format can be disabled by the current user, FALSE
* otherwise.
*
* @see filter_menu()
*/
function _filter_disable_format_access($format) {
// The fallback format can never be disabled.
return user_access('administer filters') && ($format->format != filter_fallback_format());
}
/**
* Loads a text format object from the database.
*
......@@ -193,28 +172,6 @@ function filter_format_load($format_id) {
return isset($formats[$format_id]) ? $formats[$format_id] : FALSE;
}
/**
* Disables a text format.
*
* There is no core facility to re-enable a disabled format. It is not deleted
* to keep information for contrib and to make sure the format ID is never
* reused. As there might be content using the disabled format, this would lead
* to data corruption.
*
* @param $format
* The text format object to be disabled.
*/
function filter_format_disable($format) {
$format->disable()->save();
// Allow modules to react on text format deletion.
module_invoke_all('filter_format_disable', $format);
// Clear the filter cache whenever a text format is disabled.
filter_formats_reset();
cache('filter')->deleteTags(array('filter_format' => $format->format));
}
/**
* Determines if a text format exists.
*
......
filter_admin_disable:
pattern: '/admin/config/content/formats/{filter_format}/disable'
defaults:
_form: '\Drupal\filter\Form\DisableForm'
requirements:
_filter_disable_format_access: 'TRUE'
<?php
/**
* @file
* Contains \Drupal\filter\Access\FormatDisableCheck.
*/
namespace Drupal\filter\Access;
use Drupal\Core\Access\AccessCheckInterface;
use Symfony\Component\Routing\Route;
use Symfony\Component\HttpFoundation\Request;
/**
* Checks access for disabling text formats.
*/
class FormatDisableCheck implements AccessCheckInterface {
/**
* Implements \Drupal\Core\Access\AccessCheckInterface::applies().
*/
public function applies(Route $route) {
return array_key_exists('_filter_disable_format_access', $route->getRequirements());
}
/**
* Implements \Drupal\Core\Access\AccessCheckInterface::access().
*/
public function access(Route $route, Request $request) {
if ($format = $request->attributes->get('filter_format')) {
return user_access('administer filters') && ($format->format != filter_fallback_format());
}
return FALSE;
}
}
......@@ -21,6 +21,9 @@ class FilterBundle extends Bundle {
*/
public function build(ContainerBuilder $container) {
CacheFactory::registerBin($container, 'filter');
$container->register('access_check.filter_disable', 'Drupal\filter\Access\FormatDisableCheck')
->addTag('access_check');
}
}
<?php
/**
* @file
* Contains \Drupal\filter\Form\DisableForm.
*/
namespace Drupal\filter\Form;
use Drupal\Core\Form\ConfirmFormBase;
use Drupal\filter\Plugin\Core\Entity\FilterFormat;
/**
* Provides the filter format disable form.
*/
class DisableForm extends ConfirmFormBase {
/**
* The format being disabled.
*
* @var \Drupal\filter\Plugin\Core\Entity\FilterFormat
*/
protected $format;
/**
* Implements \Drupal\Core\Form\FormInterface::getFormID().
*/
public function getFormID() {
return 'filter_admin_disable';
}
/**
* Implements \Drupal\Core\Form\ConfirmFormBase::getQuestion().
*/
protected function getQuestion() {
return t('Are you sure you want to disable the text format %format?', array('%format' => $this->format->name));
}
/**
* Implements \Drupal\Core\Form\ConfirmFormBase::getCancelPath().
*/
protected function getCancelPath() {
return 'admin/config/content/formats';
}
/**
* Overrides \Drupal\Core\Form\ConfirmFormBase::getConfirmText().
*/
public function getConfirmText() {
return t('Disable');
}
/**
* Overrides \Drupal\Core\Form\ConfirmFormBase::getDescription().
*/
public function getDescription() {
return t('Disabled text formats are completely removed from the administrative interface, and any content stored with that format will not be displayed. This action cannot be undone.');
}
/**
* Overrides \Drupal\Core\Form\FormInterface::buildForm().
*/
public function buildForm(array $form, array &$form_state, FilterFormat $filter_format = NULL) {
$this->format = $filter_format;
return parent::buildForm($form, $form_state);
}
/**
* Implements \Drupal\Core\Form\FormInterface::submitForm().
*/
public function submitForm(array &$form, array &$form_state) {
$this->format->disable()->save();
drupal_set_message(t('Disabled text format %format.', array('%format' => $this->format->name)));
$form_state['redirect'] = 'admin/config/content/formats';
}
}
......@@ -137,4 +137,20 @@ public static function sortFilters($a, $b) {
return strnatcasecmp($a['name'], $b['name']);
}
/**
* Overrides \Drupal\Core\Config\Entity\ConfigEntityBase::disable().
*/
public function disable() {
parent::disable();
// Allow modules to react on text format deletion.
module_invoke_all('filter_format_disable', $this);
// Clear the filter cache whenever a text format is disabled.
filter_formats_reset();
cache('filter')->deleteTags(array('filter_format' => $this->format));
return $this;
}
}
......@@ -73,7 +73,7 @@ function testTextFormatCrud() {
$this->verifyFilters($format);
// Disable the text format.
filter_format_disable($format);
$format->disable()->save();
$formats = filter_formats();
$this->assertTrue(!isset($formats[$format->format]), 'filter_formats: Disabled text format no longer exists.');
......
......@@ -250,7 +250,7 @@ function testFormatWidgetPermissions() {
$this->assertFieldByXPath("//textarea[@name='$body_value_key' and @disabled='disabled']", t('This field has been disabled because you do not have sufficient permissions to edit it.'), 'Text format access denied message found.');
// Disable the text format used above.
filter_format_disable($this->disallowed_format);
$this->disallowed_format->disable()->save();
$this->resetFilterCaches();
// Log back in as the less privileged user and verify that the body field
......@@ -293,7 +293,7 @@ function testFormatWidgetPermissions() {
$this->assertUrl('node/' . $node->nid);
foreach (filter_formats() as $format) {
if ($format->format != filter_fallback_format()) {
filter_format_disable($format);
$format->disable()->save();
}
}
......
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