Commit b0f09bb6 authored by alexpott's avatar alexpott

Issue #1985528 by h3rj4n, dawehner, tim.plunkett: Convert filter_tips_long() to Controller.

parent 228a2aa3
......@@ -116,18 +116,12 @@ function filter_element_info() {
function filter_menu() {
$items['filter/tips'] = array(
'title' => 'Compose tips',
'page callback' => 'filter_tips_long',
'access callback' => TRUE,
'type' => MENU_SUGGESTED_ITEM,
'file' => 'filter.pages.inc',
'route_name' => 'filter_tips_all',
);
$items['filter/tips/%filter_format'] = array(
'title' => 'Compose tips',
'page callback' => 'filter_tips_long',
'page arguments' => array(2),
'access callback' => 'filter_access',
'access arguments' => array(2),
'file' => 'filter.pages.inc',
'route_name' => 'filter_tips',
);
$items['admin/config/content/formats'] = array(
'title' => 'Text formats',
......
......@@ -5,28 +5,6 @@
* User page callbacks for the Filter module.
*/
/**
* Page callback: Displays a page with long filter tips.
*
* @param $format
* (optional) A filter format. Defaults to NULL.
*
* @return string
* An HTML-formatted string.
*
* @see filter_menu()
* @see theme_filter_tips()
*/
function filter_tips_long($format = NULL) {
if (!empty($format)) {
$output = theme('filter_tips', array('tips' => _filter_tips($format->format, TRUE), 'long' => TRUE));
}
else {
$output = theme('filter_tips', array('tips' => _filter_tips(-1, TRUE), 'long' => TRUE));
}
return $output;
}
/**
* Returns HTML for a set of filter tips.
*
......
......@@ -4,3 +4,17 @@ filter_admin_disable:
_form: '\Drupal\filter\Form\DisableForm'
requirements:
_filter_disable_format_access: 'TRUE'
filter_tips_all:
pattern: '/filter/tips'
defaults:
_content: '\Drupal\filter\Controller\FilterController::filterTips'
requirements:
_access: 'TRUE'
filter_tips:
pattern: '/filter/tips/{filter_format}'
defaults:
_content: '\Drupal\filter\Controller\FilterController::filterTips'
requirements:
_filter_access: 'TRUE'
......@@ -10,6 +10,10 @@ services:
class: Drupal\filter\Access\FormatDisableCheck
tags:
- { name: access_check }
access_check.filter_access:
class: Drupal\filter\Access\FilterAccessCheck
tags:
- { name: access_check }
plugin.manager.filter:
class: Drupal\filter\FilterPluginManager
arguments: ['@container.namespaces']
<?php
/**
* @file
* Contains \Drupal\filter\Access\FilterAccessCheck.
*/
namespace Drupal\filter\Access;
use Drupal\Core\Access\AccessCheckInterface;
use Symfony\Component\Routing\Route;
use Symfony\Component\HttpFoundation\Request;
/**
* Checks access for text formats.
*/
class FilterAccessCheck implements AccessCheckInterface {
/**
* {@inheritdoc}
*/
public function applies(Route $route) {
return array_key_exists('_filter_access', $route->getRequirements());
}
/**
* {@inheritdoc}
*/
public function access(Route $route, Request $request) {
if ($format = $request->attributes->get('filter_format')) {
// Handle special cases up front. All users have access to the fallback
// format.
if ($format->format == filter_fallback_format()) {
return TRUE;
}
// Check the permission if one exists; otherwise, we have a non-existent
// format so we return FALSE.
$permission = filter_permission_name($format);
return !empty($permission) && user_access($permission);
}
}
}
<?php
/**
* @file
* Contains \Drupal\filter\Controller\FilterController.
*/
namespace Drupal\filter\Controller;
use Drupal\filter\FilterFormatInterface;
/**
* Controller routines for filter routes.
*/
class FilterController {
/**
* Displays a page with long filter tips.
*
* @param \Drupal\filter\FilterFormatInterface|null $format
* A filter format, or NULL to show tips for all formats. Defaults to NULL.
*
* @return array
* A renderable array.
*
* @see theme_filter_tips()
*/
function filterTips(FilterFormatInterface $filter_format = NULL) {
$tips = $filter_format ? $filter_format->format : -1;
$build = array(
'#theme' => 'filter_tips',
'#long' => TRUE,
'#tips' => _filter_tips($tips, TRUE),
);
return $build;
}
}
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