diff --git a/core/modules/block/lib/Drupal/block/Tests/BlockTestBase.php b/core/modules/block/lib/Drupal/block/Tests/BlockTestBase.php index c950576..5757804 100644 --- a/core/modules/block/lib/Drupal/block/Tests/BlockTestBase.php +++ b/core/modules/block/lib/Drupal/block/Tests/BlockTestBase.php @@ -53,7 +53,7 @@ function setUp() { // text format. $this->adminUser = $this->drupalCreateUser(array( 'administer blocks', - filter_permission_name($full_html_format), + $full_html_format->getPermissionName(), 'access administration pages', )); $this->drupalLogin($this->adminUser); diff --git a/core/modules/ckeditor/ckeditor.api.php b/core/modules/ckeditor/ckeditor.api.php index 0b4f343..22bd487 100644 --- a/core/modules/ckeditor/ckeditor.api.php +++ b/core/modules/ckeditor/ckeditor.api.php @@ -47,7 +47,7 @@ function hook_ckeditor_plugin_info_alter(array &$plugins) { * @param $editor * The text editor object as returned by editor_load(), for which these files * are being loaded. Based on this information, it is possible to load the - * corresponding text format object as returned by filter_format_load(). + * corresponding text format object. * * @see _ckeditor_theme_css() */ diff --git a/core/modules/editor/lib/Drupal/editor/Plugin/Core/Entity/Editor.php b/core/modules/editor/lib/Drupal/editor/Plugin/Core/Entity/Editor.php index 00eae37..5662fb3 100644 --- a/core/modules/editor/lib/Drupal/editor/Plugin/Core/Entity/Editor.php +++ b/core/modules/editor/lib/Drupal/editor/Plugin/Core/Entity/Editor.php @@ -64,7 +64,7 @@ public function id() { * Overrides Drupal\Core\Entity\Entity::label(). */ public function label($langcode = NULL) { - $format = filter_format_load($this->format); + $format = entity_load('filter_format', $this->format); return $format->name; } diff --git a/core/modules/field/field.api.php b/core/modules/field/field.api.php index 75a99df..0403cd2 100644 --- a/core/modules/field/field.api.php +++ b/core/modules/field/field.api.php @@ -644,7 +644,7 @@ function hook_field_prepare_translation(\Drupal\Core\Entity\EntityInterface $ent $field_name = $field['field_name']; $formats = filter_formats(); $format_id = $source_entity->{$field_name}[$source_langcode][0]['format']; - if (!filter_access($formats[$format_id])) { + if (!$formats[$format_id]->access('view')) { $items = array(); } } diff --git a/core/modules/filter/filter.admin.inc b/core/modules/filter/filter.admin.inc index a4493a9..58be02b 100644 --- a/core/modules/filter/filter.admin.inc +++ b/core/modules/filter/filter.admin.inc @@ -328,7 +328,7 @@ function filter_admin_format_form_submit($form, &$form_state) { $status = $format->save(); // Save user permissions. - if ($permission = filter_permission_name($format)) { + if ($permission = $format->getPermissionName()) { foreach ($form_state['values']['roles'] as $rid => $enabled) { user_role_change_permissions($rid, array($permission => $enabled)); } diff --git a/core/modules/filter/filter.module b/core/modules/filter/filter.module index 857a33b..0872f6f 100644 --- a/core/modules/filter/filter.module +++ b/core/modules/filter/filter.module @@ -116,7 +116,7 @@ function filter_menu() { 'type' => MENU_SUGGESTED_ITEM, 'route_name' => 'filter_tips_all', ); - $items['filter/tips/%filter_format'] = array( + $items['filter/tips/%'] = array( 'title' => 'Compose tips', 'route_name' => 'filter_tips', ); @@ -147,7 +147,7 @@ function filter_menu() { 'access arguments' => array('administer filters'), 'file' => 'filter.admin.inc', ); - $items['admin/config/content/formats/%filter_format/disable'] = array( + $items['admin/config/content/formats/%/disable'] = array( 'title' => 'Disable text format', 'route_name' => 'filter_admin_disable', ); @@ -155,23 +155,19 @@ function filter_menu() { } /** - * Loads a text format object from the database. + * Loads a filter format by ID. + * + * @deprecated Only used as a menu loader. Use + * entity_load('filter_format', $format_id) instead. * * @param $format_id * The format ID. * - * @return - * A fully-populated text format object, if the requested format exists and - * is enabled. If the format does not exist, or exists in the database but - * has been marked as disabled, FALSE is returned. - * - * @see filter_format_exists() - * - * @todo Use entity_load(). + * @return \Drupal\filter\FilterFormatInterface|false + * The loaded filter format, or FALSE if none exist with this ID. */ function filter_format_load($format_id) { - $formats = filter_formats(); - return isset($formats[$format_id]) ? $formats[$format_id] : FALSE; + return entity_load('filter_format', $format_id); } /** @@ -180,12 +176,8 @@ function filter_format_load($format_id) { * @param $format_id * The ID of the text format to check. * - * @return - * TRUE if the text format exists, FALSE otherwise. Note that for disabled - * formats filter_format_exists() will return TRUE while filter_format_load() - * will return FALSE. - * - * @see filter_format_load() + * @return bool + * TRUE if the text format exists, FALSE otherwise. */ function filter_format_exists($format_id) { return entity_load('filter_format', $format_id); @@ -221,7 +213,7 @@ function filter_permission() { // Generate permissions for each text format. Warn the administrator that any // of them are potentially unsafe. foreach (filter_formats() as $format) { - $permission = filter_permission_name($format); + $permission = $format->getPermissionName(); if (!empty($permission)) { // Only link to the text format configuration page if the user who is // viewing this will have access to that page. @@ -236,64 +228,32 @@ function filter_permission() { } /** - * Returns the machine-readable permission name for a provided text format. - * - * @param $format - * An object representing a text format. - * - * @return - * The machine-readable permission name, or FALSE if the provided text format - * is malformed or is the fallback format (which is available to all users). - */ -function filter_permission_name($format) { - if (isset($format->format) && $format->format != filter_fallback_format()) { - return 'use text format ' . $format->format; - } - return FALSE; -} - -/** - * Retrieves a list of text formats, ordered by weight. + * Retrieves a list of enabled text formats, ordered by weight. * * @param $account * (optional) If provided, only those formats that are allowed for this user - * account will be returned. All formats will be returned otherwise. Defaults - * to NULL. + * account will be returned. All enabled formats will be returned otherwise. + * Defaults to NULL. * - * @return + * @return array * An array of text format objects, keyed by the format ID and ordered by * weight. * * @see filter_formats_reset() */ function filter_formats($account = NULL) { - $language_interface = language(Language::TYPE_INTERFACE); $formats = &drupal_static(__FUNCTION__, array()); - // All available formats are cached for performance. if (!isset($formats['all'])) { - if ($cache = cache()->get("filter_formats:{$language_interface->langcode}")) { - $formats['all'] = $cache->data; - } - else { - $filter_formats = entity_load_multiple('filter_format'); - $formats['all'] = array(); - foreach ($filter_formats as $format_name => $filter_format) { - if ($filter_format->status()) { - $formats['all'][$format_name] = $filter_format; - } - } - uasort($formats['all'], 'Drupal\Core\Config\Entity\ConfigEntityBase::sort'); - - cache()->set("filter_formats:{$language_interface->langcode}", $formats['all'], CacheBackendInterface::CACHE_PERMANENT, array('filter_formats' => TRUE)); - } + $formats['all'] = entity_load_multiple_by_properties('filter_format', array('status' => '1')); + uasort($formats['all'], 'Drupal\Core\Config\Entity\ConfigEntityBase::sort'); } // Build a list of user-specific formats. if (isset($account) && !isset($formats['user'][$account->uid])) { $formats['user'][$account->uid] = array(); foreach ($formats['all'] as $format) { - if (filter_access($format, $account)) { + if ($format->access('view', $account)) { $formats['user'][$account->uid][$format->format] = $format; } } @@ -309,8 +269,6 @@ function filter_formats($account = NULL) { */ function filter_formats_reset() { cache()->deleteTags(array('filter_formats' => TRUE)); - cache()->delete('filter_list_format'); - drupal_static_reset('filter_list_format'); drupal_static_reset('filter_formats'); } @@ -329,7 +287,7 @@ function filter_get_roles_by_format($format) { return user_role_names(); } // Do not list any roles if the permission does not exist. - $permission = filter_permission_name($format); + $permission = $format->getPermissionName(); return !empty($permission) ? user_role_names(FALSE, $permission) : array(); } @@ -405,7 +363,7 @@ function filter_default_format($account = NULL) { function filter_get_filter_types_by_format($format_id) { $filter_types = array(); - $filters = filter_list_format($format_id); + $filters = entity_load('filter_format', $format_id)->filters(); foreach ($filters as $filter) { if ($filter->status) { $filter_types[] = $filter->getType(); @@ -461,7 +419,7 @@ function filter_fallback_format() { * The title of the fallback text format. */ function filter_fallback_format_title() { - $fallback_format = filter_format_load(filter_fallback_format()); + $fallback_format = entity_load('filter_format', filter_fallback_format()); return filter_admin_format_title($fallback_format); } @@ -479,62 +437,16 @@ function filter_fallback_format_title() { * TRUE if the given text format allows caching, FALSE otherwise. */ function filter_format_allowcache($format_id) { - $format = filter_format_load($format_id); + $format = entity_load('filter_format', $format_id); return !empty($format->cache); } /** - * Retrieves a list of filters for a given text format. - * - * Note that this function returns all associated filters regardless of whether - * they are enabled or disabled. All functions working with the filter - * information outside of filter administration should test for $filter->status - * before performing actions with the filter. - * - * @param $format_id - * The format ID to retrieve filters for. - * - * @return - * An array of filter objects associated to the given text format, keyed by - * filter name. - * - * @todo Change this function to only return enabled filters. Code that needs to - * access disabled filters is not regular runtime code and thus can work with - * the FilterFormat::filters(). - */ -function filter_list_format($format_id) { - $filters = &drupal_static(__FUNCTION__, array()); - - if (!isset($filters['all'])) { - if ($cache = cache()->get('filter_list_format')) { - $filters['all'] = $cache->data; - } - else { - $filters['all'] = array(); - $filter_formats = filter_formats(); - foreach ($filter_formats as $filter_format) { - // This loop must not instantiate the actual filter plugins, since the - // filter bag would be duplicated for each filter plugin instance upon - // unserialization of the cache item. - $filters['all'][$filter_format->id()] = $filter_format->filters(); - } - cache()->set('filter_list_format', $filters['all']); - } - } - - if (!isset($filters[$format_id]) && isset($filters['all'][$format_id])) { - $filters[$format_id] = $filters['all'][$format_id]; - } - - return isset($filters[$format_id]) ? $filters[$format_id] : array(); -} - -/** * Runs all the enabled filters on a piece of text. * * Note: Because filters can inject JavaScript or execute PHP code, security is * vital here. When a user supplies a text format, you should validate it using - * filter_access() before accepting/using it. This is normally done in the + * $format->access() before accepting/using it. This is normally done in the * validation stage of the Form API. You should for example never make a * preview of content in a disallowed format. * @@ -568,7 +480,7 @@ function check_markup($text, $format_id = NULL, $langcode = '', $cache = FALSE, $format_id = filter_fallback_format(); } // If the requested text format does not exist, the text cannot be filtered. - if (!$format = filter_format_load($format_id)) { + if (!$format = entity_load('filter_format', $format_id)) { watchdog('filter', 'Missing text format: %format.', array('%format' => $format_id), WATCHDOG_ALERT); return ''; } @@ -598,7 +510,7 @@ function check_markup($text, $format_id = NULL, $langcode = '', $cache = FALSE, $text = str_replace(array("\r\n", "\r"), "\n", $text); // Get a complete list of filters, ordered properly. - $filters = filter_list_format($format->format); + $filters = $format->filters(); // Give filters the chance to escape HTML-like data such as code or formulas. foreach ($filters as $filter) { @@ -840,34 +752,6 @@ function theme_text_format_wrapper($variables) { } /** - * Checks if a user has access to a particular text format. - * - * @param $format - * An object representing the text format. - * @param $account - * (optional) The user account to check access for; if omitted, the currently - * logged-in user is used. Defaults to NULL. - * - * @return - * Boolean TRUE if the user is allowed to access the given format. - */ -function filter_access($format, $account = NULL) { - global $user; - if (!isset($account)) { - $account = $user; - } - // 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, $account); -} - -/** * Retrieves the filter tips. * * @param $format_id @@ -896,8 +780,7 @@ function _filter_tips($format_id, $long = FALSE) { } foreach ($formats as $format) { - $filters = filter_list_format($format->format); - foreach ($filters as $name => $filter) { + foreach ($format->filters() as $name => $filter) { if ($filter->status) { $tip = $filter->tips($long); if (isset($tip)) { diff --git a/core/modules/filter/filter.routing.yml b/core/modules/filter/filter.routing.yml index a8f4186..34a711f 100644 --- a/core/modules/filter/filter.routing.yml +++ b/core/modules/filter/filter.routing.yml @@ -17,4 +17,4 @@ filter_tips: defaults: _content: '\Drupal\filter\Controller\FilterController::filterTips' requirements: - _filter_access: 'TRUE' + _entity_access: 'filter_format.view' diff --git a/core/modules/filter/filter.services.yml b/core/modules/filter/filter.services.yml index 306c6aa..98efef5 100644 --- a/core/modules/filter/filter.services.yml +++ b/core/modules/filter/filter.services.yml @@ -10,10 +10,6 @@ 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 deleted file mode 100644 index 39363ac..0000000 --- a/core/modules/filter/lib/Drupal/filter/Access/FilterAccessCheck.php +++ /dev/null @@ -1,43 +0,0 @@ -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/FilterFormatAccessController.php b/core/modules/filter/lib/Drupal/filter/FilterFormatAccessController.php new file mode 100644 index 0000000..5bb895e --- /dev/null +++ b/core/modules/filter/lib/Drupal/filter/FilterFormatAccessController.php @@ -0,0 +1,34 @@ +id() == filter_fallback_format()) { + return TRUE; + } + // Check the permission if one exists; otherwise, we have a non-existent + // format so we return FALSE. + $permission = $entity->getPermissionName(); + return !empty($permission) && user_access($permission, $account); + } + +} diff --git a/core/modules/filter/lib/Drupal/filter/FilterFormatInterface.php b/core/modules/filter/lib/Drupal/filter/FilterFormatInterface.php index beb83b3..1beee6f 100644 --- a/core/modules/filter/lib/Drupal/filter/FilterFormatInterface.php +++ b/core/modules/filter/lib/Drupal/filter/FilterFormatInterface.php @@ -39,4 +39,13 @@ public function filters($instance_id = NULL); */ public function setFilterConfig($instance_id, array $configuration); + /** + * Returns the machine-readable permission name for the text format. + * + * @return string|false + * The machine-readable permission name, or FALSE if the text format is + * malformed or is the fallback format (which is available to all users). + */ + public function getPermissionName(); + } diff --git a/core/modules/filter/lib/Drupal/filter/FilterFormatStorageController.php b/core/modules/filter/lib/Drupal/filter/FilterFormatStorageController.php index 4c19d8b..5f5b65a 100644 --- a/core/modules/filter/lib/Drupal/filter/FilterFormatStorageController.php +++ b/core/modules/filter/lib/Drupal/filter/FilterFormatStorageController.php @@ -57,7 +57,7 @@ protected function postSave(EntityInterface $entity, $update) { // Note: user_role_change_permissions() triggers a call chain back into // filter_permission() and lastly filter_formats(), so its cache must be // reset upfront. - if (($roles = $entity->get('roles')) && $permission = filter_permission_name($entity)) { + if (($roles = $entity->get('roles')) && $permission = $entity->getPermissionName()) { foreach (user_roles() as $rid => $name) { $enabled = in_array($rid, $roles, TRUE); user_role_change_permissions($rid, array($permission => $enabled)); diff --git a/core/modules/filter/lib/Drupal/filter/Plugin/Core/Entity/FilterFormat.php b/core/modules/filter/lib/Drupal/filter/Plugin/Core/Entity/FilterFormat.php index d6b1fe6..ffbef1c 100644 --- a/core/modules/filter/lib/Drupal/filter/Plugin/Core/Entity/FilterFormat.php +++ b/core/modules/filter/lib/Drupal/filter/Plugin/Core/Entity/FilterFormat.php @@ -21,7 +21,8 @@ * label = @Translation("Text format"), * module = "filter", * controllers = { - * "storage" = "Drupal\filter\FilterFormatStorageController" + * "storage" = "Drupal\filter\FilterFormatStorageController", + * "access" = "Drupal\filter\FilterFormatAccessController" * }, * config_prefix = "filter.format", * entity_keys = { @@ -179,4 +180,15 @@ public function disable() { return $this; } + /** + * {@inheritdoc} + */ + public function getPermissionName() { + $format = $this->id(); + if ($format && $format != filter_fallback_format()) { + return "use text format $format"; + } + return FALSE; + } + } diff --git a/core/modules/filter/lib/Drupal/filter/Tests/FilterAdminTest.php b/core/modules/filter/lib/Drupal/filter/Tests/FilterAdminTest.php index 6dc2f4c..790cde1 100644 --- a/core/modules/filter/lib/Drupal/filter/Tests/FilterAdminTest.php +++ b/core/modules/filter/lib/Drupal/filter/Tests/FilterAdminTest.php @@ -34,14 +34,14 @@ function setUp() { parent::setUp(); // Create users. - $basic_html_format = filter_format_load('basic_html'); - $restricted_html_format = filter_format_load('restricted_html'); - $full_html_format = filter_format_load('full_html'); + $basic_html_format = entity_load('filter_format', 'basic_html'); + $restricted_html_format = entity_load('filter_format', 'restricted_html'); + $full_html_format = entity_load('filter_format', 'full_html'); $this->admin_user = $this->drupalCreateUser(array( 'administer filters', - filter_permission_name($basic_html_format), - filter_permission_name($restricted_html_format), - filter_permission_name($full_html_format), + $basic_html_format->getPermissionName(), + $restricted_html_format->getPermissionName(), + $full_html_format->getPermissionName(), )); $this->web_user = $this->drupalCreateUser(array('create page content', 'edit own page content')); @@ -134,8 +134,9 @@ function testFilterAdmin() { $this->assertResponse(403, 'The fallback format cannot be disabled.'); // Verify access permissions to Full HTML format. - $this->assertTrue(filter_access(filter_format_load($full), $this->admin_user), 'Admin user may use Full HTML.'); - $this->assertFalse(filter_access(filter_format_load($full), $this->web_user), 'Web user may not use Full HTML.'); + $full_format = entity_load('filter_format', $full); + $this->assertTrue($full_format->access('view', $this->admin_user), 'Admin user may use Full HTML.'); + $this->assertFalse($full_format->access('view', $this->web_user), 'Web user may not use Full HTML.'); // Add an additional tag. $edit = array(); @@ -190,7 +191,7 @@ function testFilterAdmin() { $this->assertRaw(t('Added text format %format.', array('%format' => $edit['name'])), 'New filter created.'); drupal_static_reset('filter_formats'); - $format = filter_format_load($edit['format']); + $format = entity_load('filter_format', $edit['format']); $this->assertNotNull($format, 'Format found in database.'); $this->drupalGet('admin/config/content/formats/' . $format->format); $this->assertFieldByName('roles[' . DRUPAL_AUTHENTICATED_RID . ']', '', 'Role found.'); @@ -203,7 +204,7 @@ function testFilterAdmin() { $this->assertRaw(t('Disabled text format %format.', array('%format' => $edit['name'])), 'Format successfully disabled.'); // Allow authenticated users on full HTML. - $format = filter_format_load($full); + $format = entity_load('filter_format', $full); $edit = array(); $edit['roles[' . DRUPAL_ANONYMOUS_RID . ']'] = 0; $edit['roles[' . DRUPAL_AUTHENTICATED_RID . ']'] = 1; diff --git a/core/modules/filter/lib/Drupal/filter/Tests/FilterCrudTest.php b/core/modules/filter/lib/Drupal/filter/Tests/FilterCrudTest.php index 80b9dd1..77965c4 100644 --- a/core/modules/filter/lib/Drupal/filter/Tests/FilterCrudTest.php +++ b/core/modules/filter/lib/Drupal/filter/Tests/FilterCrudTest.php @@ -39,7 +39,6 @@ function testTextFormatCrud() { $format->name = 'Empty format'; $format->save(); $this->verifyTextFormat($format); - $this->verifyFilters($format); // Add another text format specifying all possible properties. $format = entity_create('filter_format', array()); @@ -53,7 +52,6 @@ function testTextFormatCrud() { )); $format->save(); $this->verifyTextFormat($format); - $this->verifyFilters($format); // Alter some text format properties and save again. $format->name = 'Altered format'; @@ -65,7 +63,6 @@ function testTextFormatCrud() { )); $format->save(); $this->verifyTextFormat($format); - $this->verifyFilters($format); // Add a uncacheable filter and save again. $format->setFilterConfig('filter_test_uncacheable', array( @@ -73,7 +70,6 @@ function testTextFormatCrud() { )); $format->save(); $this->verifyTextFormat($format); - $this->verifyFilters($format); // Disable the text format. $format->disable()->save(); @@ -86,22 +82,10 @@ function testTextFormatCrud() { * Verifies that a text format is properly stored. */ function verifyTextFormat($format) { - $t_args = array('%format' => $format->name); - $default_langcode = language_default()->langcode; - - // Verify filter_format_load(). - $filter_format = filter_format_load($format->format); - $this->assertEqual($filter_format->format, $format->format, format_string('filter_format_load: Proper format id for text format %format.', $t_args)); - $this->assertEqual($filter_format->name, $format->name, format_string('filter_format_load: Proper title for text format %format.', $t_args)); - $this->assertEqual($filter_format->cache, $format->cache, format_string('filter_format_load: Proper cache indicator for text format %format.', $t_args)); - $this->assertEqual($filter_format->weight, $format->weight, format_string('filter_format_load: Proper weight for text format %format.', $t_args)); - // Check that the filter was created in site default language. - $this->assertEqual($format->langcode, $default_langcode, format_string('filter_format_load: Proper language code for text format %format.', $t_args)); - + $filter_format = entity_load('filter_format', $format->format); // Verify the 'cache' text format property according to enabled filters. - $filters = filter_list_format($filter_format->format); $cacheable = TRUE; - foreach ($filters as $name => $filter) { + foreach ($format->filters() as $name => $filter) { // If this filter is not cacheable, update $cacheable accordingly, so we // can verify $format->cache after iterating over all filters. if ($filter->status && !$filter->cache) { @@ -112,25 +96,4 @@ function verifyTextFormat($format) { $this->assertEqual($filter_format->cache, $cacheable, 'Text format contains proper cache property.'); } - /** - * Verifies that filters are properly stored for a text format. - */ - function verifyFilters($format) { - $filters = filter_list_format($format->format); - $format_filters = $format->filters(); - foreach ($filters as $name => $filter) { - $t_args = array('%format' => $format->name, '%filter' => $name); - - // Verify that filter status is properly stored. - $this->assertEqual($filter->status, $format_filters->get($name)->status, format_string('filter_list_format: Proper status for %filter in text format %format.', $t_args)); - - // Verify that filter settings were properly stored. - $this->assertEqual($filter->settings, $format_filters->get($name)->settings, format_string('filter_list_format: Proper filter settings for %filter in text format %format.', $t_args)); - - // Verify that each filter has a module name assigned. - $this->assertTrue(!empty($filter->module), format_string('filter_list_format: Proper module name for %filter in text format %format.', $t_args)); - } - $this->assertEqual(count($filters), count($format_filters), 'filter_list_format: All filters for the format are present.'); - } - } diff --git a/core/modules/filter/lib/Drupal/filter/Tests/FilterDefaultConfigTest.php b/core/modules/filter/lib/Drupal/filter/Tests/FilterDefaultConfigTest.php index ac078e8..664ab0a 100644 --- a/core/modules/filter/lib/Drupal/filter/Tests/FilterDefaultConfigTest.php +++ b/core/modules/filter/lib/Drupal/filter/Tests/FilterDefaultConfigTest.php @@ -41,7 +41,7 @@ function setUp() { */ function testInstallation() { // Verify that the format was installed correctly. - $format = filter_format_load('filter_test'); + $format = entity_load('filter_format', 'filter_test'); $this->assertTrue((bool) $format); $this->assertEqual($format->id(), 'filter_test'); $this->assertEqual($format->label(), 'Test format'); @@ -82,7 +82,7 @@ function testInstallation() { */ function testUpdateRoles() { // Verify role permissions declared in default config. - $format = filter_format_load('filter_test'); + $format = entity_load('filter_format', 'filter_test'); $this->assertEqual(array_keys(filter_get_roles_by_format($format)), array( DRUPAL_ANONYMOUS_RID, DRUPAL_AUTHENTICATED_RID, @@ -95,7 +95,7 @@ function testUpdateRoles() { $format->save(); // Verify that roles have not been updated. - $format = filter_format_load('filter_test'); + $format = entity_load('filter_format', 'filter_test'); $this->assertEqual(array_keys(filter_get_roles_by_format($format)), array( DRUPAL_ANONYMOUS_RID, DRUPAL_AUTHENTICATED_RID, diff --git a/core/modules/filter/lib/Drupal/filter/Tests/FilterDefaultFormatTest.php b/core/modules/filter/lib/Drupal/filter/Tests/FilterDefaultFormatTest.php index 5df2a5e..fbf1a78 100644 --- a/core/modules/filter/lib/Drupal/filter/Tests/FilterDefaultFormatTest.php +++ b/core/modules/filter/lib/Drupal/filter/Tests/FilterDefaultFormatTest.php @@ -37,11 +37,12 @@ function testDefaultTextFormats() { ); $this->drupalPost('admin/config/content/formats/add', $edit, t('Save configuration')); $this->resetFilterCaches(); - $formats[] = filter_format_load($edit['format']); + $formats[] = entity_load('filter_format', $edit['format']); } list($first_format, $second_format) = $formats; - $first_user = $this->drupalCreateUser(array(filter_permission_name($first_format), filter_permission_name($second_format))); - $second_user = $this->drupalCreateUser(array(filter_permission_name($second_format))); + $second_format_permission = $second_format->getPermissionName(); + $first_user = $this->drupalCreateUser(array($first_format->getPermissionName(), $second_format_permission)); + $second_user = $this->drupalCreateUser(array($second_format_permission)); // Adjust the weights so that the first and second formats (in that order) // are the two lowest weighted formats available to any user. diff --git a/core/modules/filter/lib/Drupal/filter/Tests/FilterFormatAccessTest.php b/core/modules/filter/lib/Drupal/filter/Tests/FilterFormatAccessTest.php index c811425..20c3087 100644 --- a/core/modules/filter/lib/Drupal/filter/Tests/FilterFormatAccessTest.php +++ b/core/modules/filter/lib/Drupal/filter/Tests/FilterFormatAccessTest.php @@ -88,7 +88,7 @@ function setUp() { ); $this->drupalPost('admin/config/content/formats/add', $edit, t('Save configuration')); $this->resetFilterCaches(); - $formats[] = filter_format_load($edit['format']); + $formats[] = entity_load('filter_format', $edit['format']); } list($this->allowed_format, $this->second_allowed_format, $this->disallowed_format) = $formats; $this->drupalLogout(); @@ -97,8 +97,8 @@ function setUp() { $this->web_user = $this->drupalCreateUser(array( 'create page content', 'edit any page content', - filter_permission_name($this->allowed_format), - filter_permission_name($this->second_allowed_format), + $this->allowed_format->getPermissionName(), + $this->second_allowed_format->getPermissionName(), )); // Create an administrative user who has access to use all three formats. @@ -106,9 +106,9 @@ function setUp() { 'administer filters', 'create page content', 'edit any page content', - filter_permission_name($this->allowed_format), - filter_permission_name($this->second_allowed_format), - filter_permission_name($this->disallowed_format), + $this->allowed_format->getPermissionName(), + $this->second_allowed_format->getPermissionName(), + $this->disallowed_format->getPermissionName(), )); } @@ -118,9 +118,10 @@ function setUp() { function testFormatPermissions() { // Make sure that a regular user only has access to the text formats for // which they were granted access. - $this->assertTrue(filter_access($this->allowed_format, $this->web_user), 'A regular user has access to a text format they were granted access to.'); - $this->assertFalse(filter_access($this->disallowed_format, $this->web_user), 'A regular user does not have access to a text format they were not granted access to.'); - $this->assertTrue(filter_access(filter_format_load(filter_fallback_format()), $this->web_user), 'A regular user has access to the fallback format.'); + $fallback_format = filter_fallback_format(); + $this->assertTrue($this->allowed_format->access('view', $this->web_user), 'A regular user has access to a text format they were granted access to.'); + $this->assertFalse($this->disallowed_format->access('view', $this->web_user), 'A regular user does not have access to a text format they were not granted access to.'); + $this->assertTrue($fallback_format->access('view', $this->web_user), 'A regular user has access to the fallback format.'); // Perform similar checks as above, but now against the entire list of // available formats for this user. @@ -130,8 +131,8 @@ function testFormatPermissions() { // Make sure that a regular user only has permission to use the format // they were granted access to. - $this->assertTrue(user_access(filter_permission_name($this->allowed_format), $this->web_user), 'A regular user has permission to use the allowed text format.'); - $this->assertFalse(user_access(filter_permission_name($this->disallowed_format), $this->web_user), 'A regular user does not have permission to use the disallowed text format.'); + $this->assertTrue(user_access($this->allowed_format->getPermissionName(), $this->web_user), 'A regular user has permission to use the allowed text format.'); + $this->assertFalse(user_access($this->disallowed_format->getPermissionName(), $this->web_user), 'A regular user does not have permission to use the disallowed text format.'); // Make sure that the allowed format appears on the node form and that // the disallowed format does not. @@ -193,7 +194,7 @@ function testFormatRoles() { $this->assertFalse(in_array($this->disallowed_format->format, array_keys(filter_get_formats_by_role($rid))), 'A text format which a role does not have access to does not appear in the list of formats available to that role.'); // Check that the fallback format is always allowed. - $this->assertEqual(filter_get_roles_by_format(filter_format_load(filter_fallback_format())), user_role_names(), 'All roles have access to the fallback format.'); + $this->assertEqual(filter_get_roles_by_format(entity_load('filter_format', filter_fallback_format())), user_role_names(), 'All roles have access to the fallback format.'); $this->assertTrue(in_array(filter_fallback_format(), array_keys(filter_get_formats_by_role($rid))), 'The fallback format appears in the list of allowed formats for any role.'); } diff --git a/core/modules/filter/lib/Drupal/filter/Tests/FilterHtmlImageSecureTest.php b/core/modules/filter/lib/Drupal/filter/Tests/FilterHtmlImageSecureTest.php index 644781e..15a4ad8 100644 --- a/core/modules/filter/lib/Drupal/filter/Tests/FilterHtmlImageSecureTest.php +++ b/core/modules/filter/lib/Drupal/filter/Tests/FilterHtmlImageSecureTest.php @@ -60,7 +60,7 @@ function setUp() { 'access comments', 'post comments', 'skip comment approval', - filter_permission_name($filtered_html_format), + $filtered_html_format->getPermissionName(), )); $this->drupalLogin($this->web_user); diff --git a/core/modules/filter/lib/Drupal/filter/Tests/FilterSecurityTest.php b/core/modules/filter/lib/Drupal/filter/Tests/FilterSecurityTest.php index 9b3eea0..b1b67be 100644 --- a/core/modules/filter/lib/Drupal/filter/Tests/FilterSecurityTest.php +++ b/core/modules/filter/lib/Drupal/filter/Tests/FilterSecurityTest.php @@ -56,7 +56,7 @@ function setUp() { )); $filtered_html_format->save(); - $filtered_html_permission = filter_permission_name($filtered_html_format); + $filtered_html_permission = $filtered_html_format->getPermissionName(); user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, array($filtered_html_permission)); $this->admin_user = $this->drupalCreateUser(array('administer modules', 'administer filters', 'administer site configuration')); diff --git a/core/modules/filter/lib/Drupal/filter/Tests/FilterSettingsTest.php b/core/modules/filter/lib/Drupal/filter/Tests/FilterSettingsTest.php index 1b6c173..a11db5d 100644 --- a/core/modules/filter/lib/Drupal/filter/Tests/FilterSettingsTest.php +++ b/core/modules/filter/lib/Drupal/filter/Tests/FilterSettingsTest.php @@ -62,7 +62,7 @@ function testFilterDefaults() { filter_formats_reset(); // Verify that saved filter settings have not been changed. - foreach (filter_list_format($filter_defaults_format->format) as $name => $filter) { + foreach ($filter_defaults_format->filters() as $name => $filter) { $this->assertEqual($filter->weight, $saved_settings[$name]['weight'], format_string('@name filter weight %saved equals %previous', array( '@name' => $name, '%saved' => $filter->weight, diff --git a/core/modules/php/lib/Drupal/php/Tests/PhpFilterTest.php b/core/modules/php/lib/Drupal/php/Tests/PhpFilterTest.php index f954bdd..e5b966c 100644 --- a/core/modules/php/lib/Drupal/php/Tests/PhpFilterTest.php +++ b/core/modules/php/lib/Drupal/php/Tests/PhpFilterTest.php @@ -26,7 +26,7 @@ public static function getInfo() { */ function testPhpFilter() { // Log in as a user with permission to use the PHP code text format. - $php_code_permission = filter_permission_name(filter_format_load('php_code')); + $php_code_permission = entity_load('filter_format', 'php_code')->getPermissionName(); $web_user = $this->drupalCreateUser(array('access content', 'create page content', 'edit own page content', $php_code_permission)); $this->drupalLogin($web_user); diff --git a/core/modules/php/lib/Drupal/php/Tests/PhpTestBase.php b/core/modules/php/lib/Drupal/php/Tests/PhpTestBase.php index c18273a..20f200f 100644 --- a/core/modules/php/lib/Drupal/php/Tests/PhpTestBase.php +++ b/core/modules/php/lib/Drupal/php/Tests/PhpTestBase.php @@ -35,11 +35,11 @@ function setUp() { // Verify that the PHP code text format was inserted. $php_format_id = 'php_code'; - $this->php_code_format = filter_format_load($php_format_id); + $this->php_code_format = entity_load('filter_format', $php_format_id); $this->assertEqual($this->php_code_format->name, 'PHP code', 'PHP code text format was created.'); // Verify that the format has the PHP code filter enabled. - $filters = filter_list_format($php_format_id); + $filters = $this->php_code_format->filters(); $this->assertTrue($filters->get('php_code')->status, 'PHP code filter is enabled.'); // Verify that the format exists on the administration page. diff --git a/core/modules/search/lib/Drupal/search/Tests/SearchCommentTest.php b/core/modules/search/lib/Drupal/search/Tests/SearchCommentTest.php index 4d2a7ed..9c5e554 100644 --- a/core/modules/search/lib/Drupal/search/Tests/SearchCommentTest.php +++ b/core/modules/search/lib/Drupal/search/Tests/SearchCommentTest.php @@ -38,10 +38,10 @@ function setUp() { // Create and log in an administrative user having access to the Full HTML // text format. - $full_html_format = filter_format_load('full_html'); + $full_html_format = entity_load('filter_format', 'full_html'); $permissions = array( 'administer filters', - filter_permission_name($full_html_format), + $full_html_format->getPermissionName(), 'administer permissions', 'create page content', 'skip comment approval', diff --git a/core/modules/system/lib/Drupal/system/Tests/Form/FormTest.php b/core/modules/system/lib/Drupal/system/Tests/Form/FormTest.php index f402395..712f7a4 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Form/FormTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Form/FormTest.php @@ -35,7 +35,7 @@ function setUp() { )); $filtered_html_format->save(); - $filtered_html_permission = filter_permission_name($filtered_html_format); + $filtered_html_permission = $filtered_html_format->getPermissionName(); user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, array($filtered_html_permission)); } diff --git a/core/modules/system/lib/Drupal/system/Tests/Upgrade/FilterFormatUpgradePathTest.php b/core/modules/system/lib/Drupal/system/Tests/Upgrade/FilterFormatUpgradePathTest.php index 1a42c7f..878b86e 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Upgrade/FilterFormatUpgradePathTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Upgrade/FilterFormatUpgradePathTest.php @@ -41,16 +41,14 @@ public function testFilterFormatUpgrade() { $this->assertTrue($this->performUpgrade(), 'The upgrade was completed successfully.'); // Checks that all the formats were upgraded - $one = filter_format_load('format_one'); + $one = entity_load('filter_format', 'format_one'); $this->assertTrue(!empty($one), 'Filter Format one was successfully upgraded'); - $two = filter_format_load('format_two'); + $two = entity_load('filter_format', 'format_two'); $this->assertTrue(!empty($two), 'Filter Format two was successfully upgraded'); - // Filter format 'Three' is disabled, and filter_format_load should return - // FALSE. However the entity should be accessible using entity_load. - $three_disabled = filter_format_load('format_three'); + // Filter format 'Three' is disabled. $three_entity = entity_load('filter_format', 'format_three'); - $this->assertTrue(empty($three_disabled) && !empty($three_entity), 'Filter Format three was successfully upgraded and it is disabled'); + $this->assertFalse($three_entity->status(), 'Filter Format three was successfully upgraded and it is disabled'); // Check the access to the text formats. diff --git a/core/modules/text/lib/Drupal/text/Tests/TextFieldTest.php b/core/modules/text/lib/Drupal/text/Tests/TextFieldTest.php index 9aed6ee..9c7fbed 100644 --- a/core/modules/text/lib/Drupal/text/Tests/TextFieldTest.php +++ b/core/modules/text/lib/Drupal/text/Tests/TextFieldTest.php @@ -227,9 +227,9 @@ function _testTextfieldWidgetsFormatted($field_type, $widget_type) { $this->drupalPost('admin/config/content/formats/add', $edit, t('Save configuration')); filter_formats_reset(); $this->checkPermissions(array(), TRUE); - $format = filter_format_load($edit['format']); + $format = entity_load('filter_format', $edit['format']); $format_id = $format->format; - $permission = filter_permission_name($format); + $permission = $format->getPermissionName(); $roles = $this->web_user->roles; unset($roles[DRUPAL_AUTHENTICATED_RID]); $rid = key($roles); diff --git a/core/modules/text/lib/Drupal/text/Tests/TextTranslationTest.php b/core/modules/text/lib/Drupal/text/Tests/TextTranslationTest.php index 113c724..8cf63b3 100644 --- a/core/modules/text/lib/Drupal/text/Tests/TextTranslationTest.php +++ b/core/modules/text/lib/Drupal/text/Tests/TextTranslationTest.php @@ -35,15 +35,14 @@ public static function getInfo() { function setUp() { parent::setUp(); - $full_html_format = filter_format_load('full_html'); - $this->format = $full_html_format->format; + $full_html_format = entity_load('filter_format', 'full_html'); $this->admin = $this->drupalCreateUser(array( 'administer languages', 'administer content types', 'administer node fields', 'access administration pages', 'bypass node access', - filter_permission_name($full_html_format), + $full_html_format->getPermissionName(), )); $this->translator = $this->drupalCreateUser(array('create article content', 'edit own article content', 'translate all content')); diff --git a/core/modules/text/text.module b/core/modules/text/text.module index 4fe2115..9a5aacc 100644 --- a/core/modules/text/text.module +++ b/core/modules/text/text.module @@ -274,7 +274,7 @@ function text_summary($text, $format = NULL, $size = NULL) { // Retrieve the filters of the specified text format, if any. if (isset($format)) { - $filters = filter_list_format($format); + $filters = entity_load('filter_format', $format)->filters(); // If the specified format does not exist, return nothing. $text is already // filtered text, but the remainder of this function will not be able to // ensure a sane and secure summary. @@ -370,7 +370,7 @@ function text_field_prepare_translation(EntityInterface $entity, $field, $instan $formats = filter_formats(); foreach ($source_entity->{$field_name}[$source_langcode] as $delta => $item) { $format_id = $item['format']; - if (!empty($format_id) && !filter_access($formats[$format_id])) { + if (!empty($format_id) && !$formats[$format_id]->access('view')) { unset($items[$delta]); } } diff --git a/core/modules/user/lib/Drupal/user/Tests/UserSignatureTest.php b/core/modules/user/lib/Drupal/user/Tests/UserSignatureTest.php index 85925e7..7a18122 100644 --- a/core/modules/user/lib/Drupal/user/Tests/UserSignatureTest.php +++ b/core/modules/user/lib/Drupal/user/Tests/UserSignatureTest.php @@ -62,7 +62,7 @@ function setUp() { )); $this->full_html_format->save(); - user_role_grant_permissions(DRUPAL_AUTHENTICATED_RID, array(filter_permission_name($this->filtered_html_format))); + user_role_grant_permissions(DRUPAL_AUTHENTICATED_RID, array($this->filtered_html_format->getPermissionName())); $this->checkPermissions(array(), TRUE); // Create regular and administrative users. @@ -70,7 +70,7 @@ function setUp() { $admin_permissions = array('administer comments'); foreach (filter_formats() as $format) { - if ($permission = filter_permission_name($format)) { + if ($permission = $format->getPermissionName()) { $admin_permissions[] = $permission; } }