diff --git a/core/modules/ckeditor/src/Tests/CKEditorAdminTest.php b/core/modules/ckeditor/src/Tests/CKEditorAdminTest.php index d10180d..f10080a 100644 --- a/core/modules/ckeditor/src/Tests/CKEditorAdminTest.php +++ b/core/modules/ckeditor/src/Tests/CKEditorAdminTest.php @@ -245,7 +245,7 @@ function testNewFormat() { 'editor[editor]' => 'ckeditor', ); $this->drupalPostAjaxForm(NULL, $edit, 'editor_configure'); - $filter_format = FilterFormat::load('amazing_format'); + $filter_format = entity_load('filter_format', '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 @@ function testNewFormat() { $this->drupalPostForm(NULL, $edit, t('Save configuration')); // Ensure a FilterFormat object exists now. - $filter_format = FilterFormat::load('amazing_format'); + $filter_format = entity_load('filter_format', 'amazing_format'); $this->assertTrue($filter_format instanceof FilterFormatInterface, 'A FilterFormat config entity exists now.'); // Ensure an Editor object exists now, with the proper settings. diff --git a/core/modules/config_translation/src/Tests/ConfigTranslationUiTest.php b/core/modules/config_translation/src/Tests/ConfigTranslationUiTest.php index b69357e..7d0af41 100644 --- a/core/modules/config_translation/src/Tests/ConfigTranslationUiTest.php +++ b/core/modules/config_translation/src/Tests/ConfigTranslationUiTest.php @@ -10,7 +10,6 @@ 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; @@ -78,11 +77,11 @@ protected function setUp() { ]; /** @var \Drupal\filter\FilterFormatInterface $filter_test_format */ - $filter_test_format = FilterFormat::load('filter_test'); + $filter_test_format = entity_load('filter_format', 'filter_test'); /** @var \Drupal\filter\FilterFormatInterface $filtered_html_format */ - $filtered_html_format = FilterFormat::load('filtered_html'); + $filtered_html_format = entity_load('filter_format', 'filtered_html'); /** @var \Drupal\filter\FilterFormatInterface $full_html_format */ - $full_html_format = FilterFormat::load('full_html'); + $full_html_format = entity_load('filter_format', 'full_html'); $admin_permissions = array_merge( $translator_permissions, diff --git a/core/modules/editor/src/Plugin/InPlaceEditor/Editor.php b/core/modules/editor/src/Plugin/InPlaceEditor/Editor.php index 56158f5..24b43ea 100644 --- a/core/modules/editor/src/Plugin/InPlaceEditor/Editor.php +++ b/core/modules/editor/src/Plugin/InPlaceEditor/Editor.php @@ -4,7 +4,6 @@ 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; @@ -62,7 +61,7 @@ function getMetadata(FieldItemListInterface $items) { * @return bool */ protected function textFormatHasTransformationFilters($format_id) { - $format = FilterFormat::load($format_id); + $format = entity_load('filter_format', $format_id); return (bool) count(array_intersect(array(FilterInterface::TYPE_TRANSFORM_REVERSIBLE, FilterInterface::TYPE_TRANSFORM_IRREVERSIBLE), $format->getFiltertypes())); } diff --git a/core/modules/filter/src/Tests/FilterAdminTest.php b/core/modules/filter/src/Tests/FilterAdminTest.php index 8d28465..86d5ce7 100644 --- a/core/modules/filter/src/Tests/FilterAdminTest.php +++ b/core/modules/filter/src/Tests/FilterAdminTest.php @@ -202,7 +202,7 @@ function testFilterAdmin() { $this->assertResponse(403, 'The fallback format cannot be disabled.'); // Verify access permissions to Full HTML format. - $full_format = FilterFormat::load($full); + $full_format = entity_load('filter_format', $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 @@ function testFilterAdmin() { )); $this->assertTrue(!empty($elements), 'Reorder confirmed in admin interface.'); - $filter_format = FilterFormat::load($restricted); + $filter_format = entity_load('filter_format', $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 @@ function testFilterAdmin() { $this->assertRaw(t('Added text format %format.', array('%format' => $edit['name'])), 'New filter created.'); filter_formats_reset(); - $format = FilterFormat::load($edit['format']); + $format = entity_load('filter_format', $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 @@ function testFilterAdmin() { $this->assertRaw(t('Disabled text format %format.', array('%format' => $edit['name'])), 'Format successfully disabled.'); // Allow authenticated users on full HTML. - $format = FilterFormat::load($full); + $format = entity_load('filter_format', $full); $edit = array(); $edit['roles[' . RoleInterface::ANONYMOUS_ID . ']'] = 0; $edit['roles[' . RoleInterface::AUTHENTICATED_ID . ']'] = 1; diff --git a/core/modules/filter/src/Tests/FilterDefaultFormatTest.php b/core/modules/filter/src/Tests/FilterDefaultFormatTest.php index 879119e..800d706 100644 --- a/core/modules/filter/src/Tests/FilterDefaultFormatTest.php +++ b/core/modules/filter/src/Tests/FilterDefaultFormatTest.php @@ -3,7 +3,6 @@ namespace Drupal\filter\Tests; use Drupal\Component\Utility\Unicode; -use Drupal\filter\Entity\FilterFormat; use Drupal\simpletest\WebTestBase; /** @@ -36,7 +35,7 @@ function testDefaultTextFormats() { ); $this->drupalPostForm('admin/config/content/formats/add', $edit, t('Save configuration')); $this->resetFilterCaches(); - $formats[] = FilterFormat::load($edit['format']); + $formats[] = entity_load('filter_format', $edit['format']); } list($first_format, $second_format) = $formats; $second_format_permission = $second_format->getPermissionName(); diff --git a/core/modules/filter/src/Tests/FilterFormTest.php b/core/modules/filter/src/Tests/FilterFormTest.php index 24bbc15..022d2bf 100644 --- a/core/modules/filter/src/Tests/FilterFormTest.php +++ b/core/modules/filter/src/Tests/FilterFormTest.php @@ -3,7 +3,6 @@ namespace Drupal\filter\Tests; use Drupal\Component\Utility\SafeMarkup; -use Drupal\filter\Entity\FilterFormat; use Drupal\simpletest\WebTestBase; /** @@ -41,11 +40,11 @@ protected function setUp() { parent::setUp(); /** @var \Drupal\filter\FilterFormatInterface $filter_test_format */ - $filter_test_format = FilterFormat::load('filter_test'); + $filter_test_format = entity_load('filter_format', 'filter_test'); /** @var \Drupal\filter\FilterFormatInterface $filtered_html_format */ - $filtered_html_format = FilterFormat::load('filtered_html'); + $filtered_html_format = entity_load('filter_format', 'filtered_html'); /** @var \Drupal\filter\FilterFormatInterface $full_html_format */ - $full_html_format = FilterFormat::load('full_html'); + $full_html_format = entity_load('filter_format', 'full_html'); // Create users. $this->adminUser = $this->drupalCreateUser(array( diff --git a/core/modules/filter/src/Tests/FilterFormatAccessTest.php b/core/modules/filter/src/Tests/FilterFormatAccessTest.php index 496cfb8..ed41db0 100644 --- a/core/modules/filter/src/Tests/FilterFormatAccessTest.php +++ b/core/modules/filter/src/Tests/FilterFormatAccessTest.php @@ -4,7 +4,6 @@ use Drupal\Component\Utility\Unicode; use Drupal\Core\Access\AccessResult; -use Drupal\filter\Entity\FilterFormat; use Drupal\simpletest\WebTestBase; /** @@ -90,7 +89,7 @@ protected function setUp() { ); $this->drupalPostForm('admin/config/content/formats/add', $edit, t('Save configuration')); $this->resetFilterCaches(); - $formats[] = FilterFormat::load($edit['format']); + $formats[] = entity_load('filter_format', $edit['format']); } list($this->allowedFormat, $this->secondAllowedFormat, $this->disallowedFormat) = $formats; $this->drupalLogout(); @@ -121,7 +120,7 @@ protected function setUp() { function testFormatPermissions() { // Make sure that a regular user only has access to the text formats for // which they were granted access. - $fallback_format = FilterFormat::load(filter_fallback_format()); + $fallback_format = entity_load('filter_format', 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.'); @@ -198,7 +197,7 @@ function testFormatRoles() { $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(FilterFormat::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/src/Tests/FilterSecurityTest.php b/core/modules/filter/src/Tests/FilterSecurityTest.php index 12cd97a..b86e072 100644 --- a/core/modules/filter/src/Tests/FilterSecurityTest.php +++ b/core/modules/filter/src/Tests/FilterSecurityTest.php @@ -2,7 +2,6 @@ namespace Drupal\filter\Tests; -use Drupal\filter\Entity\FilterFormat; use Drupal\simpletest\WebTestBase; use Drupal\filter\Plugin\FilterInterface; use Drupal\user\RoleInterface; @@ -37,7 +36,7 @@ protected function setUp() { $this->drupalCreateContentType(array('type' => 'page', 'name' => 'Basic page')); /** @var \Drupal\filter\Entity\FilterFormat $filtered_html_format */ - $filtered_html_format = FilterFormat::load('filtered_html'); + $filtered_html_format = entity_load('filter_format', 'filtered_html'); $filtered_html_permission = $filtered_html_format->getPermissionName(); user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, array($filtered_html_permission)); diff --git a/core/modules/filter/tests/src/Kernel/FilterAPITest.php b/core/modules/filter/tests/src/Kernel/FilterAPITest.php index 50189a6..0f9feff 100644 --- a/core/modules/filter/tests/src/Kernel/FilterAPITest.php +++ b/core/modules/filter/tests/src/Kernel/FilterAPITest.php @@ -100,7 +100,7 @@ function testCheckMarkupFilterSubset() { */ function testFilterFormatAPI() { // Test on filtered_html. - $filtered_html_format = FilterFormat::load('filtered_html'); + $filtered_html_format = entity_load('filter_format', 'filtered_html'); $this->assertIdentical( $filtered_html_format->getHtmlRestrictions(), array( @@ -121,7 +121,7 @@ function testFilterFormatAPI() { ); // Test on full_html. - $full_html_format = FilterFormat::load('full_html'); + $full_html_format = entity_load('filter_format', 'full_html'); $this->assertIdentical( $full_html_format->getHtmlRestrictions(), FALSE, // Every tag is allowed. @@ -334,7 +334,7 @@ function testTypedDataAPI() { $this->assertTrue($data instanceof OptionsProviderInterface, 'Typed data object implements \Drupal\Core\TypedData\OptionsProviderInterface'); $filtered_html_user = $this->createUser(array('uid' => 2), array( - FilterFormat::load('filtered_html')->getPermissionName(), + entity_load('filter_format', 'filtered_html')->getPermissionName(), )); // Test with anonymous user. diff --git a/core/modules/filter/tests/src/Kernel/FilterCrudTest.php b/core/modules/filter/tests/src/Kernel/FilterCrudTest.php index 0a9be18..35e181c 100644 --- a/core/modules/filter/tests/src/Kernel/FilterCrudTest.php +++ b/core/modules/filter/tests/src/Kernel/FilterCrudTest.php @@ -93,7 +93,7 @@ function verifyTextFormat($format) { $default_langcode = \Drupal::languageManager()->getDefaultLanguage()->getId(); // Verify the loaded filter has all properties. - $filter_format = FilterFormat::load($format->id()); + $filter_format = entity_load('filter_format', $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)); diff --git a/core/modules/filter/tests/src/Kernel/FilterDefaultConfigTest.php b/core/modules/filter/tests/src/Kernel/FilterDefaultConfigTest.php index b4ce50c..4b3684b 100644 --- a/core/modules/filter/tests/src/Kernel/FilterDefaultConfigTest.php +++ b/core/modules/filter/tests/src/Kernel/FilterDefaultConfigTest.php @@ -2,7 +2,6 @@ namespace Drupal\Tests\filter\Kernel; -use Drupal\filter\Entity\FilterFormat; use Drupal\KernelTests\KernelTestBase; use Drupal\user\RoleInterface; @@ -32,7 +31,7 @@ protected function setUp() { */ function testInstallation() { // Verify that the format was installed correctly. - $format = FilterFormat::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'); @@ -72,7 +71,7 @@ function testInstallation() { */ function testUpdateRoles() { // Verify role permissions declared in default config. - $format = FilterFormat::load('filter_test'); + $format = entity_load('filter_format', 'filter_test'); $this->assertEqual(array_keys(filter_get_roles_by_format($format)), array( RoleInterface::ANONYMOUS_ID, RoleInterface::AUTHENTICATED_ID, @@ -85,7 +84,7 @@ function testUpdateRoles() { $format->save(); // Verify that roles have not been updated. - $format = FilterFormat::load('filter_test'); + $format = entity_load('filter_format', 'filter_test'); $this->assertEqual(array_keys(filter_get_roles_by_format($format)), array( RoleInterface::ANONYMOUS_ID, RoleInterface::AUTHENTICATED_ID, diff --git a/core/modules/system/src/EntitySchemaUpdater.php b/core/modules/system/src/EntitySchemaUpdater.php new file mode 100644 index 0000000..9adfd84 --- /dev/null +++ b/core/modules/system/src/EntitySchemaUpdater.php @@ -0,0 +1,72 @@ +getStorage($entity_type->id()); + if ($storage instanceof SqlEntityStorageInterface) { + $storage->onEntityTypeCreate($entity_type); + } + } + + public function addRevisionField(EntityTypeInterface $entity_type) { + $revision_id = BaseFieldDefinition::create('integer') + ->setLabel(new TranslatableMarkup('Revision ID')) + ->setReadOnly(TRUE) + ->setSetting('unsigned', TRUE); + \Drupal::entityDefinitionUpdateManager() + ->installFieldStorageDefinition($entity_type->getKey('revision'), $entity_type->id(), $entity_type->id(), $revision_id); + + $revision_created = BaseFieldDefinition::create('created') + ->setLabel(t('Revision create time')) + ->setDescription(t('The time that the current revision was created.')) + ->setRevisionable(TRUE); + \Drupal::entityDefinitionUpdateManager() + ->installFieldStorageDefinition("revision_created", $entity_type->id(), $entity_type->id(), $revision_created); + + + $revision_user = BaseFieldDefinition::create('entity_reference') + ->setLabel(t('Revision user')) + ->setDescription(t('The user ID of the author of the current revision.')) + ->setSetting('target_type', 'user') + ->setRevisionable(TRUE); + \Drupal::entityDefinitionUpdateManager() + ->installFieldStorageDefinition("revision_user", $entity_type->id(), $entity_type->id(), $revision_user); + + + $revision_log_message = BaseFieldDefinition::create('string_long') + ->setLabel(t('Revision log message')) + ->setDescription(t('Briefly describe the changes you have made.')) + ->setRevisionable(TRUE) + ->setDefaultValue('') + ->setDisplayOptions('form', [ + 'type' => 'string_textarea', + 'weight' => 25, + 'settings' => [ + 'rows' => 4, + ], + ]); + \Drupal::entityDefinitionUpdateManager() + ->installFieldStorageDefinition("revision_log_message", $entity_type->id(), $entity_type->id(), $revision_log_message); + + $entity_field_manager = \Drupal::service('entity_field.manager'); + /** @var \Drupal\Core\Field\FieldStorageDefinitionInterface[] $definitions */ + $entity_field_manager->clearCachedFieldDefinitions(); + + \Drupal::service('entity.last_installed_schema.repository')->setLastInstalledDefinition($entity_type); + } + +} diff --git a/core/modules/system/src/EntitySchemaUpdaterInterface.php b/core/modules/system/src/EntitySchemaUpdaterInterface.php new file mode 100644 index 0000000..65f7c23 --- /dev/null +++ b/core/modules/system/src/EntitySchemaUpdaterInterface.php @@ -0,0 +1,19 @@ +getPluginCollections()['filters']; $filters = $entity->get('filters'); diff --git a/core/modules/system/system.services.yml b/core/modules/system/system.services.yml index c70889d..739564b 100644 --- a/core/modules/system/system.services.yml +++ b/core/modules/system/system.services.yml @@ -43,3 +43,6 @@ services: arguments: ['@theme_handler', '@cache_tags.invalidator'] tags: - { name: event_subscriber } + system.entity_schema_updater: + class: Drupal\system\EntitySchemaUpdater + arguments: [] diff --git a/core/modules/text/src/Tests/TextFieldTest.php b/core/modules/text/src/Tests/TextFieldTest.php index 993346a..53a369b 100644 --- a/core/modules/text/src/Tests/TextFieldTest.php +++ b/core/modules/text/src/Tests/TextFieldTest.php @@ -7,7 +7,6 @@ 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. @@ -212,7 +211,7 @@ function _testTextfieldWidgetsFormatted($field_type, $widget_type) { ); $this->drupalPostForm('admin/config/content/formats/add', $edit, t('Save configuration')); filter_formats_reset(); - $format = FilterFormat::load($edit['format']); + $format = entity_load('filter_format', $edit['format']); $format_id = $format->id(); $permission = $format->getPermissionName(); $roles = $this->webUser->getRoles(); diff --git a/core/modules/text/text.module b/core/modules/text/text.module index 906b461..a3dbcec 100644 --- a/core/modules/text/text.module +++ b/core/modules/text/text.module @@ -8,7 +8,6 @@ use Drupal\Component\Utility\Html; use Drupal\Component\Utility\Unicode; use Drupal\Core\Routing\RouteMatchInterface; -use Drupal\filter\Entity\FilterFormat; /** * Implements hook_help(). @@ -81,7 +80,7 @@ function text_summary($text, $format = NULL, $size = NULL) { // Retrieve the filters of the specified text format, if any. if (isset($format)) { - $filters = FilterFormat::load($format)->filters(); + $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.