diff --git a/core/modules/filter/filter.module b/core/modules/filter/filter.module index 06d3fff..42999ac 100644 --- a/core/modules/filter/filter.module +++ b/core/modules/filter/filter.module @@ -115,18 +115,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', diff --git a/core/modules/filter/filter.pages.inc b/core/modules/filter/filter.pages.inc index 5b20d4f..8f2e298 100644 --- a/core/modules/filter/filter.pages.inc +++ b/core/modules/filter/filter.pages.inc @@ -6,28 +6,6 @@ */ /** - * 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. * * @param array $variables diff --git a/core/modules/filter/filter.routing.yml b/core/modules/filter/filter.routing.yml index de9e9cb..a8f4186 100644 --- a/core/modules/filter/filter.routing.yml +++ b/core/modules/filter/filter.routing.yml @@ -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' diff --git a/core/modules/filter/filter.services.yml b/core/modules/filter/filter.services.yml index 98efef5..3f08404 100644 --- a/core/modules/filter/filter.services.yml +++ b/core/modules/filter/filter.services.yml @@ -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'] diff --git a/core/modules/filter/lib/Drupal/filter/Access/FilterAccessCheck.php b/core/modules/filter/lib/Drupal/filter/Access/FilterAccessCheck.php new file mode 100644 index 0000000..39363ac --- /dev/null +++ b/core/modules/filter/lib/Drupal/filter/Access/FilterAccessCheck.php @@ -0,0 +1,43 @@ +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); + } + } +} diff --git a/core/modules/filter/lib/Drupal/filter/Controller/FilterController.php b/core/modules/filter/lib/Drupal/filter/Controller/FilterController.php new file mode 100644 index 0000000..ca4e733 --- /dev/null +++ b/core/modules/filter/lib/Drupal/filter/Controller/FilterController.php @@ -0,0 +1,40 @@ +format : -1; + + $build = array( + '#theme' => 'filter_tips', + '#long' => TRUE, + '#tips' => _filter_tips($tips, TRUE), + ); + + return $build; + } + +}