Issue #2723589 by Ashish.Dalvi, gaurav.pahuja, marvin_B8, valthebald: Remove entity_load* usage for filter_format entity type

8.2.x
xjm 2016-05-23 09:20:51 -05:00
parent 4ca088c25d
commit 918f6b545b
14 changed files with 38 additions and 28 deletions

View File

@ -245,7 +245,7 @@ class CKEditorAdminTest extends WebTestBase {
'editor[editor]' => 'ckeditor',
);
$this->drupalPostAjaxForm(NULL, $edit, 'editor_configure');
$filter_format = entity_load('filter_format', 'amazing_format');
$filter_format = FilterFormat::load('amazing_format');
$this->assertFalse($filter_format, 'No FilterFormat config entity exists yet.');
$editor = Editor::load('amazing_format');
$this->assertFalse($editor, 'No Editor config entity exists yet.');
@ -270,7 +270,7 @@ class CKEditorAdminTest extends WebTestBase {
$this->drupalPostForm(NULL, $edit, t('Save configuration'));
// Ensure a FilterFormat object exists now.
$filter_format = entity_load('filter_format', 'amazing_format');
$filter_format = FilterFormat::load('amazing_format');
$this->assertTrue($filter_format instanceof FilterFormatInterface, 'A FilterFormat config entity exists now.');
// Ensure an Editor object exists now, with the proper settings.

View File

@ -10,6 +10,7 @@ use Drupal\Core\Language\Language;
use Drupal\Core\Language\LanguageInterface;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\filter\Entity\FilterFormat;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\simpletest\WebTestBase;
@ -77,11 +78,11 @@ class ConfigTranslationUiTest extends WebTestBase {
];
/** @var \Drupal\filter\FilterFormatInterface $filter_test_format */
$filter_test_format = entity_load('filter_format', 'filter_test');
$filter_test_format = FilterFormat::load('filter_test');
/** @var \Drupal\filter\FilterFormatInterface $filtered_html_format */
$filtered_html_format = entity_load('filter_format', 'filtered_html');
$filtered_html_format = FilterFormat::load('filtered_html');
/** @var \Drupal\filter\FilterFormatInterface $full_html_format */
$full_html_format = entity_load('filter_format', 'full_html');
$full_html_format = FilterFormat::load('full_html');
$admin_permissions = array_merge(
$translator_permissions,

View File

@ -4,6 +4,7 @@ namespace Drupal\editor\Plugin\InPlaceEditor;
use Drupal\Component\Plugin\PluginBase;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\filter\Entity\FilterFormat;
use Drupal\quickedit\Plugin\InPlaceEditorInterface;
use Drupal\filter\Plugin\FilterInterface;
@ -61,7 +62,7 @@ class Editor extends PluginBase implements InPlaceEditorInterface {
* @return bool
*/
protected function textFormatHasTransformationFilters($format_id) {
$format = entity_load('filter_format', $format_id);
$format = FilterFormat::load($format_id);
return (bool) count(array_intersect(array(FilterInterface::TYPE_TRANSFORM_REVERSIBLE, FilterInterface::TYPE_TRANSFORM_IRREVERSIBLE), $format->getFiltertypes()));
}

View File

@ -202,7 +202,7 @@ class FilterAdminTest extends WebTestBase {
$this->assertResponse(403, 'The fallback format cannot be disabled.');
// Verify access permissions to Full HTML format.
$full_format = entity_load('filter_format', $full);
$full_format = FilterFormat::load($full);
$this->assertTrue($full_format->access('use', $this->adminUser), 'Admin user may use Full HTML.');
$this->assertFalse($full_format->access('use', $this->webUser), 'Web user may not use Full HTML.');
@ -236,7 +236,7 @@ class FilterAdminTest extends WebTestBase {
));
$this->assertTrue(!empty($elements), 'Reorder confirmed in admin interface.');
$filter_format = entity_load('filter_format', $restricted);
$filter_format = FilterFormat::load($restricted);
foreach ($filter_format->filters() as $filter_name => $filter) {
if ($filter_name == $second_filter || $filter_name == $first_filter) {
$filters[] = $filter_name;
@ -257,7 +257,7 @@ class FilterAdminTest extends WebTestBase {
$this->assertRaw(t('Added text format %format.', array('%format' => $edit['name'])), 'New filter created.');
filter_formats_reset();
$format = entity_load('filter_format', $edit['format']);
$format = FilterFormat::load($edit['format']);
$this->assertNotNull($format, 'Format found in database.');
$this->drupalGet('admin/config/content/formats/manage/' . $format->id());
$this->assertFieldByName('roles[' . RoleInterface::AUTHENTICATED_ID . ']', '', 'Role found.');
@ -270,7 +270,7 @@ class FilterAdminTest extends WebTestBase {
$this->assertRaw(t('Disabled text format %format.', array('%format' => $edit['name'])), 'Format successfully disabled.');
// Allow authenticated users on full HTML.
$format = entity_load('filter_format', $full);
$format = FilterFormat::load($full);
$edit = array();
$edit['roles[' . RoleInterface::ANONYMOUS_ID . ']'] = 0;
$edit['roles[' . RoleInterface::AUTHENTICATED_ID . ']'] = 1;

View File

@ -3,6 +3,7 @@
namespace Drupal\filter\Tests;
use Drupal\Component\Utility\Unicode;
use Drupal\filter\Entity\FilterFormat;
use Drupal\simpletest\WebTestBase;
/**
@ -35,7 +36,7 @@ class FilterDefaultFormatTest extends WebTestBase {
);
$this->drupalPostForm('admin/config/content/formats/add', $edit, t('Save configuration'));
$this->resetFilterCaches();
$formats[] = entity_load('filter_format', $edit['format']);
$formats[] = FilterFormat::load($edit['format']);
}
list($first_format, $second_format) = $formats;
$second_format_permission = $second_format->getPermissionName();

View File

@ -3,6 +3,7 @@
namespace Drupal\filter\Tests;
use Drupal\Component\Utility\SafeMarkup;
use Drupal\filter\Entity\FilterFormat;
use Drupal\simpletest\WebTestBase;
/**
@ -40,11 +41,11 @@ class FilterFormTest extends WebTestBase {
parent::setUp();
/** @var \Drupal\filter\FilterFormatInterface $filter_test_format */
$filter_test_format = entity_load('filter_format', 'filter_test');
$filter_test_format = FilterFormat::load('filter_test');
/** @var \Drupal\filter\FilterFormatInterface $filtered_html_format */
$filtered_html_format = entity_load('filter_format', 'filtered_html');
$filtered_html_format = FilterFormat::load('filtered_html');
/** @var \Drupal\filter\FilterFormatInterface $full_html_format */
$full_html_format = entity_load('filter_format', 'full_html');
$full_html_format = FilterFormat::load('full_html');
// Create users.
$this->adminUser = $this->drupalCreateUser(array(

View File

@ -4,6 +4,7 @@ namespace Drupal\filter\Tests;
use Drupal\Component\Utility\Unicode;
use Drupal\Core\Access\AccessResult;
use Drupal\filter\Entity\FilterFormat;
use Drupal\simpletest\WebTestBase;
/**
@ -89,7 +90,7 @@ class FilterFormatAccessTest extends WebTestBase {
);
$this->drupalPostForm('admin/config/content/formats/add', $edit, t('Save configuration'));
$this->resetFilterCaches();
$formats[] = entity_load('filter_format', $edit['format']);
$formats[] = FilterFormat::load($edit['format']);
}
list($this->allowedFormat, $this->secondAllowedFormat, $this->disallowedFormat) = $formats;
$this->drupalLogout();
@ -120,7 +121,7 @@ class FilterFormatAccessTest extends WebTestBase {
function testFormatPermissions() {
// Make sure that a regular user only has access to the text formats for
// which they were granted access.
$fallback_format = entity_load('filter_format', filter_fallback_format());
$fallback_format = FilterFormat::load(filter_fallback_format());
$this->assertTrue($this->allowedFormat->access('use', $this->webUser), 'A regular user has access to use a text format they were granted access to.');
$this->assertEqual(AccessResult::allowed()->addCacheContexts(['user.permissions']), $this->allowedFormat->access('use', $this->webUser, TRUE), 'A regular user has access to use a text format they were granted access to.');
$this->assertFalse($this->disallowedFormat->access('use', $this->webUser), 'A regular user does not have access to use a text format they were not granted access to.');
@ -197,7 +198,7 @@ class FilterFormatAccessTest extends WebTestBase {
$this->assertFalse(in_array($this->disallowedFormat->id(), 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(entity_load('filter_format', filter_fallback_format())), user_role_names(), 'All roles have access to the fallback format.');
$this->assertEqual(filter_get_roles_by_format(FilterFormat::load(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.');
}

View File

@ -2,6 +2,7 @@
namespace Drupal\filter\Tests;
use Drupal\filter\Entity\FilterFormat;
use Drupal\simpletest\WebTestBase;
use Drupal\filter\Plugin\FilterInterface;
use Drupal\user\RoleInterface;
@ -36,7 +37,7 @@ class FilterSecurityTest extends WebTestBase {
$this->drupalCreateContentType(array('type' => 'page', 'name' => 'Basic page'));
/** @var \Drupal\filter\Entity\FilterFormat $filtered_html_format */
$filtered_html_format = entity_load('filter_format', 'filtered_html');
$filtered_html_format = FilterFormat::load('filtered_html');
$filtered_html_permission = $filtered_html_format->getPermissionName();
user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, array($filtered_html_permission));

View File

@ -100,7 +100,7 @@ class FilterAPITest extends EntityKernelTestBase {
*/
function testFilterFormatAPI() {
// Test on filtered_html.
$filtered_html_format = entity_load('filter_format', 'filtered_html');
$filtered_html_format = FilterFormat::load('filtered_html');
$this->assertIdentical(
$filtered_html_format->getHtmlRestrictions(),
array(
@ -121,7 +121,7 @@ class FilterAPITest extends EntityKernelTestBase {
);
// Test on full_html.
$full_html_format = entity_load('filter_format', 'full_html');
$full_html_format = FilterFormat::load('full_html');
$this->assertIdentical(
$full_html_format->getHtmlRestrictions(),
FALSE, // Every tag is allowed.
@ -334,7 +334,7 @@ class FilterAPITest extends EntityKernelTestBase {
$this->assertTrue($data instanceof OptionsProviderInterface, 'Typed data object implements \Drupal\Core\TypedData\OptionsProviderInterface');
$filtered_html_user = $this->createUser(array('uid' => 2), array(
entity_load('filter_format', 'filtered_html')->getPermissionName(),
FilterFormat::load('filtered_html')->getPermissionName(),
));
// Test with anonymous user.

View File

@ -93,7 +93,7 @@ class FilterCrudTest extends KernelTestBase {
$default_langcode = \Drupal::languageManager()->getDefaultLanguage()->getId();
// Verify the loaded filter has all properties.
$filter_format = entity_load('filter_format', $format->id());
$filter_format = FilterFormat::load($format->id());
$this->assertEqual($filter_format->id(), $format->id(), format_string('filter_format_load: Proper format id for text format %format.', $t_args));
$this->assertEqual($filter_format->label(), $format->label(), format_string('filter_format_load: Proper title for text format %format.', $t_args));
$this->assertEqual($filter_format->get('weight'), $format->get('weight'), format_string('filter_format_load: Proper weight for text format %format.', $t_args));

View File

@ -2,6 +2,7 @@
namespace Drupal\Tests\filter\Kernel;
use Drupal\filter\Entity\FilterFormat;
use Drupal\KernelTests\KernelTestBase;
use Drupal\user\RoleInterface;
@ -31,7 +32,7 @@ class FilterDefaultConfigTest extends KernelTestBase {
*/
function testInstallation() {
// Verify that the format was installed correctly.
$format = entity_load('filter_format', 'filter_test');
$format = FilterFormat::load('filter_test');
$this->assertTrue((bool) $format);
$this->assertEqual($format->id(), 'filter_test');
$this->assertEqual($format->label(), 'Test format');
@ -71,7 +72,7 @@ class FilterDefaultConfigTest extends KernelTestBase {
*/
function testUpdateRoles() {
// Verify role permissions declared in default config.
$format = entity_load('filter_format', 'filter_test');
$format = FilterFormat::load('filter_test');
$this->assertEqual(array_keys(filter_get_roles_by_format($format)), array(
RoleInterface::ANONYMOUS_ID,
RoleInterface::AUTHENTICATED_ID,
@ -84,7 +85,7 @@ class FilterDefaultConfigTest extends KernelTestBase {
$format->save();
// Verify that roles have not been updated.
$format = entity_load('filter_format', 'filter_test');
$format = FilterFormat::load('filter_test');
$this->assertEqual(array_keys(filter_get_roles_by_format($format)), array(
RoleInterface::ANONYMOUS_ID,
RoleInterface::AUTHENTICATED_ID,

View File

@ -3,6 +3,7 @@
namespace Drupal\system\Tests\Entity;
use Drupal\Core\Entity\EntityWithPluginCollectionInterface;
use Drupal\filter\Entity\FilterFormat;
use Drupal\image\Entity\ImageStyle;
use Drupal\search\Entity\SearchPage;
use Drupal\simpletest\WebTestBase;
@ -89,7 +90,7 @@ class ConfigEntityImportTest extends WebTestBase {
$name = 'filter.format.plain_text';
/** @var $entity \Drupal\filter\Entity\FilterFormat */
$entity = entity_load('filter_format', 'plain_text');
$entity = FilterFormat::load('plain_text');
$plugin_collection = $entity->getPluginCollections()['filters'];
$filters = $entity->get('filters');

View File

@ -7,6 +7,7 @@ use Drupal\entity_test\Entity\EntityTest;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Tests\String\StringFieldTest;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\filter\Entity\FilterFormat;
/**
* Tests the creation of text fields.
@ -211,7 +212,7 @@ class TextFieldTest extends StringFieldTest {
);
$this->drupalPostForm('admin/config/content/formats/add', $edit, t('Save configuration'));
filter_formats_reset();
$format = entity_load('filter_format', $edit['format']);
$format = FilterFormat::load($edit['format']);
$format_id = $format->id();
$permission = $format->getPermissionName();
$roles = $this->webUser->getRoles();

View File

@ -8,6 +8,7 @@
use Drupal\Component\Utility\Html;
use Drupal\Component\Utility\Unicode;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\filter\Entity\FilterFormat;
/**
* Implements hook_help().
@ -80,7 +81,7 @@ function text_summary($text, $format = NULL, $size = NULL) {
// Retrieve the filters of the specified text format, if any.
if (isset($format)) {
$filters = entity_load('filter_format', $format)->filters();
$filters = FilterFormat::load($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.