diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc index 499f5527d2..b5be219ef9 100644 --- a/core/includes/bootstrap.inc +++ b/core/includes/bootstrap.inc @@ -950,6 +950,12 @@ function &drupal_static($name, $default_value = NULL, $reset = FALSE) { * unit tests with a clean environment. */ function drupal_static_reset($name = NULL) { + switch ($name) { + case 'filter_formats': + @trigger_error("Using drupal_static_reset() with 'filter_formats' as parameter is deprecated in Drupal 8.8.0 and will be removed before Drupal 9.0.0. Use \\Drupal\\filter\\FilterFormatRepositoryInterface::resetFormats() instead. See https://www.drupal.org/node/3035368.", E_USER_DEPRECATED); + \Drupal::service('filter.format_repository')->resetFormats(); + return; + } drupal_static($name, NULL, TRUE); } diff --git a/core/modules/comment/src/Plugin/migrate/source/d6/Comment.php b/core/modules/comment/src/Plugin/migrate/source/d6/Comment.php index 0031179b4b..5671d4f156 100644 --- a/core/modules/comment/src/Plugin/migrate/source/d6/Comment.php +++ b/core/modules/comment/src/Plugin/migrate/source/d6/Comment.php @@ -85,7 +85,7 @@ public function fields() { 'hostname' => $this->t("The author's host name."), 'timestamp' => $this->t('The time that the comment was created, or last edited by its author, as a Unix timestamp.'), 'status' => $this->t('The published status of a comment. (0 = Published, 1 = Not Published)'), - 'format' => $this->t('The {filter_format}.format of the comment body.'), + 'format' => $this->t('The {filter_formats}.format of the comment body.'), 'thread' => $this->t("The vancode representation of the comment's place in a thread."), 'name' => $this->t("The comment author's name. Uses {users}.name if the user is logged in, otherwise uses the value typed into the comment form."), 'mail' => $this->t("The comment author's email address from the comment form, if user is anonymous, and the 'Anonymous users may/must leave their contact information' setting is turned on."), diff --git a/core/modules/comment/src/Plugin/migrate/source/d7/Comment.php b/core/modules/comment/src/Plugin/migrate/source/d7/Comment.php index f835f5891d..73c2d8f4f7 100644 --- a/core/modules/comment/src/Plugin/migrate/source/d7/Comment.php +++ b/core/modules/comment/src/Plugin/migrate/source/d7/Comment.php @@ -79,7 +79,7 @@ public function fields() { 'created' => $this->t('The time that the comment was created, as a Unix timestamp.'), 'changed' => $this->t('The time that the comment was edited by its author, as a Unix timestamp.'), 'status' => $this->t('The published status of a comment. (0 = Published, 1 = Not Published)'), - 'format' => $this->t('The {filter_format}.format of the comment body.'), + 'format' => $this->t('The {filter_formats}.format of the comment body.'), 'thread' => $this->t("The vancode representation of the comment's place in a thread."), 'name' => $this->t("The comment author's name. Uses {users}.name if the user is logged in, otherwise uses the value typed into the comment form."), 'mail' => $this->t("The comment author's email address from the comment form, if user is anonymous, and the 'Anonymous users may/must leave their contact information' setting is turned on."), diff --git a/core/modules/filter/filter.module b/core/modules/filter/filter.module index 6004d432e6..e47b904063 100644 --- a/core/modules/filter/filter.module +++ b/core/modules/filter/filter.module @@ -89,7 +89,7 @@ function filter_theme() { * An array of text format objects, keyed by the format ID and ordered by * weight. * - * @deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. Use the + * @deprecated in Drupal 8.8.0 and will be removed before Drupal 9.0.0. Use the * 'filter.format_repository' service with ::getAllFormats() to get all * formats or with ::getFormatsForAccount() to get all formats that a user is * able to access. @@ -97,7 +97,7 @@ function filter_theme() { * @see https://www.drupal.org/node/3035368 */ function filter_formats(AccountInterface $account = NULL) { - @trigger_error('filter_formats() is deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. Use the "filter.format_repository" service with ::getAllFormats() to get all formats or with ::getFormatsForAccount() to get all formats that a user is able to access. See https://www.drupal.org/node/3035368.', E_USER_DEPRECATED); + @trigger_error('filter_formats() is deprecated in Drupal 8.8.0 and will be removed before Drupal 9.0.0. Use the "filter.format_repository" service with ::getAllFormats() to get all formats or with ::getFormatsForAccount() to get all formats that a user is able to access. See https://www.drupal.org/node/3035368.', E_USER_DEPRECATED); $filter_format_repository = \Drupal::service('filter.format_repository'); // If no user was specified, return all formats. @@ -111,13 +111,13 @@ function filter_formats(AccountInterface $account = NULL) { /** * Resets the text format caches. * - * @deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. Use the + * @deprecated in Drupal 8.8.0 and will be removed before Drupal 9.0.0. Use the * 'filter.format_repository' service with ::resetFormats() method. * * @see https://www.drupal.org/node/3035368 */ function filter_formats_reset() { - @trigger_error('filter_formats_reset() is deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. Use the "filter.format_repository" service with ::resetFormats() method. See https://www.drupal.org/node/3035368.', E_USER_DEPRECATED); + @trigger_error('filter_formats_reset() is deprecated in Drupal 8.8.0 and will be removed before Drupal 9.0.0. Use the "filter.format_repository" service with ::resetFormats() method. See https://www.drupal.org/node/3035368.', E_USER_DEPRECATED); \Drupal::service('filter.format_repository')->resetFormats(); } @@ -130,13 +130,13 @@ function filter_formats_reset() { * @return array * An array of role names, keyed by role ID. * - * @deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. Use the + * @deprecated in Drupal 8.8.0 and will be removed before Drupal 9.0.0. Use the * \Drupal\filter\FilterFormatInterface::getRoles() method. * * @see https://www.drupal.org/node/3035368 */ function filter_get_roles_by_format(FilterFormatInterface $format) { - @trigger_error('filter_get_roles_by_format() is deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. Use the \Drupal\filter\FilterFormatInterface::getRoles() method. See https://www.drupal.org/node/3035368.', E_USER_DEPRECATED); + @trigger_error('filter_get_roles_by_format() is deprecated in Drupal 8.8.0 and will be removed before Drupal 9.0.0. Use the \Drupal\filter\FilterFormatInterface::getRoles() method. See https://www.drupal.org/node/3035368.', E_USER_DEPRECATED); return $format->getRoles(); } @@ -150,13 +150,13 @@ function filter_get_roles_by_format(FilterFormatInterface $format) { * An array of text format objects that are allowed for the role, keyed by * the text format ID and ordered by weight. * - * @deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. Use the + * @deprecated in Drupal 8.8.0 and will be removed before Drupal 9.0.0. Use the * 'filter.format_repository' service with ::getFormatsByRole() method. * * @see https://www.drupal.org/node/3035368 */ function filter_get_formats_by_role($rid) { - @trigger_error('filter_get_formats_by_role() is deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. Use the "filter.format_repository" service with ::getFormatsByRole() method. See https://www.drupal.org/node/3035368.', E_USER_DEPRECATED); + @trigger_error('filter_get_formats_by_role() is deprecated in Drupal 8.8.0 and will be removed before Drupal 9.0.0. Use the "filter.format_repository" service with ::getFormatsByRole() method. See https://www.drupal.org/node/3035368.', E_USER_DEPRECATED); return \Drupal::service('filter.format_repository')->getFormatsByRole($rid); } @@ -183,13 +183,13 @@ function filter_get_formats_by_role($rid) { * @return string * The ID of the user's default text format. * - * @deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. Use the + * @deprecated in Drupal 8.8.0 and will be removed before Drupal 9.0.0. Use the * 'filter.format_repository' service with ::getDefaultFormat() method. * * @see https://www.drupal.org/node/3035368 */ function filter_default_format(AccountInterface $account = NULL) { - @trigger_error('filter_default_format() is deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. Use the "filter.format_repository" service with ::getDefaultFormat() method. See https://www.drupal.org/node/3035368.', E_USER_DEPRECATED); + @trigger_error('filter_default_format() is deprecated in Drupal 8.8.0 and will be removed before Drupal 9.0.0. Use the "filter.format_repository" service with ::getDefaultFormat() method. See https://www.drupal.org/node/3035368.', E_USER_DEPRECATED); return \Drupal::service('filter.format_repository')->getDefaultFormat($account)->id(); } @@ -219,7 +219,7 @@ function filter_default_format(AccountInterface $account = NULL) { * @return string|null * The ID of the fallback text format. * - * @deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. Use the + * @deprecated in Drupal 8.8.0 and will be removed before Drupal 9.0.0. Use the * 'filter.format_repository' service with ::getFallbackFormatId() * method. * @@ -227,7 +227,7 @@ function filter_default_format(AccountInterface $account = NULL) { * @see hook_filter_format_disable() */ function filter_fallback_format() { - @trigger_error('filter_fallback_format() is deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. Use the "filter.format_repository" service with ::getFallbackFormatId() method. See https://www.drupal.org/node/3035368.', E_USER_DEPRECATED); + @trigger_error('filter_fallback_format() is deprecated in Drupal 8.8.0 and will be removed before Drupal 9.0.0. Use the "filter.format_repository" service with ::getFallbackFormatId() method. See https://www.drupal.org/node/3035368.', E_USER_DEPRECATED); return \Drupal::service('filter.format_repository')->getFallbackFormatId(); } diff --git a/core/modules/filter/src/Entity/FilterFormat.php b/core/modules/filter/src/Entity/FilterFormat.php index 66f533cd8a..9c0d7a4e48 100644 --- a/core/modules/filter/src/Entity/FilterFormat.php +++ b/core/modules/filter/src/Entity/FilterFormat.php @@ -414,7 +414,7 @@ public function removeFilter($instance_id) { * {@inheritdoc} */ public function getRoles() { - // Handle the fallback format upfront (all roles have access to this format). + // Handle the fallback format: all roles have access to this format. if ($this->isFallbackFormat()) { return user_role_names(); } diff --git a/core/modules/filter/src/FilterFormatListBuilder.php b/core/modules/filter/src/FilterFormatListBuilder.php index c1fd387e1e..d0ff5ecd85 100644 --- a/core/modules/filter/src/FilterFormatListBuilder.php +++ b/core/modules/filter/src/FilterFormatListBuilder.php @@ -58,11 +58,15 @@ class FilterFormatListBuilder extends DraggableListBuilder { * @param \Drupal\filter\FilterFormatRepositoryInterface $format_repository * The filter format repository service. */ - public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage, ConfigFactoryInterface $config_factory, MessengerInterface $messenger, FilterFormatRepositoryInterface $format_repository) { + public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage, ConfigFactoryInterface $config_factory, MessengerInterface $messenger, FilterFormatRepositoryInterface $format_repository = NULL) { parent::__construct($entity_type, $storage); $this->configFactory = $config_factory; $this->messenger = $messenger; + if (!$format_repository) { + @trigger_error('The $format_repository parameter will become mandatory before Drupal 9.0.0. See https://www.drupal.org/node/3035368.', E_USER_DEPRECATED); + $format_repository = \Drupal::service('filter.format_repository'); + } $this->formatRepository = $format_repository; } diff --git a/core/modules/filter/tests/src/Functional/FilterAdminTest.php b/core/modules/filter/tests/src/Functional/FilterAdminTest.php index d81cae222c..39ba69ca67 100644 --- a/core/modules/filter/tests/src/Functional/FilterAdminTest.php +++ b/core/modules/filter/tests/src/Functional/FilterAdminTest.php @@ -187,7 +187,7 @@ public function testFilterAdmin() { $full = 'full_html'; $plain = 'plain_text'; - $format_repository = $this->container->get('filter.format_repository'); + $format_repository = \Drupal::service('filter.format_repository'); // Check that the fallback format exists and cannot be disabled. $this->assertTrue($plain == $format_repository->getFallbackFormatId(), 'The fallback format is set to plain text.'); $this->drupalGet('admin/config/content/formats'); diff --git a/core/modules/filter/tests/src/Functional/FilterDefaultFormatTest.php b/core/modules/filter/tests/src/Functional/FilterDefaultFormatTest.php index 27fea8645b..93a2a8ca9b 100644 --- a/core/modules/filter/tests/src/Functional/FilterDefaultFormatTest.php +++ b/core/modules/filter/tests/src/Functional/FilterDefaultFormatTest.php @@ -50,7 +50,7 @@ public function testDefaultTextFormats() { $this->drupalPostForm('admin/config/content/formats', $edit, t('Save')); $this->resetFilterCaches(); - $format_repository = $this->container->get('filter.format_repository'); + $format_repository = \Drupal::service('filter.format_repository'); // Check that each user's default format is the lowest weighted format that // the user has access to. $actual = $format_repository->getDefaultFormat($first_user)->id(); @@ -73,7 +73,7 @@ public function testDefaultTextFormats() { * Rebuilds text format and permission caches in the thread running the tests. */ protected function resetFilterCaches() { - $this->container->get('filter.format_repository')->resetFormats(); + \Drupal::service('filter.format_repository')->resetFormats(); } } diff --git a/core/modules/filter/tests/src/Functional/FilterFormatAccessTest.php b/core/modules/filter/tests/src/Functional/FilterFormatAccessTest.php index 2bd1e6282a..99d51a221b 100644 --- a/core/modules/filter/tests/src/Functional/FilterFormatAccessTest.php +++ b/core/modules/filter/tests/src/Functional/FilterFormatAccessTest.php @@ -118,7 +118,7 @@ protected function setUp() { * Tests the Filter format access permissions functionality. */ public function testFormatPermissions() { - $format_repository = $this->container->get('filter.format_repository'); + $format_repository = \Drupal::service('filter.format_repository'); // Make sure that a regular user only has access to the text formats for // which they were granted access. $fallback_format = FilterFormat::load($format_repository->getFallbackFormatId()); @@ -193,7 +193,7 @@ public function testFormatRoles() { $this->assertTrue(in_array($rid, array_keys($this->allowedFormat->getRoles())), 'A role which has access to a text format appears in the list of roles that have access to that format.'); $this->assertFalse(in_array($rid, array_keys($this->disallowedFormat->getRoles())), 'A role which does not have access to a text format does not appear in the list of roles that have access to that format.'); - $format_repository = $this->container->get('filter.format_repository'); + $format_repository = \Drupal::service('filter.format_repository'); // Check that the correct text format appears in the list of formats // available to that role. $this->assertTrue(in_array($this->allowedFormat->id(), array_keys($format_repository->getFormatsByRole($rid))), 'A text format which a role has access to appears in the list of formats available to that role.'); @@ -285,7 +285,7 @@ public function testFormatWidgetPermissions() { $this->assertText($old_title, 'Old title found.'); $this->assertNoText($new_title, 'New title not found.'); - $format_repository = $this->container->get('filter.format_repository'); + $format_repository = \Drupal::service('filter.format_repository'); // Now select a new text format and make sure the node can be saved. $edit[$body_format_key] = $format_repository->getFallbackFormatId(); @@ -300,7 +300,7 @@ public function testFormatWidgetPermissions() { $edit = [$body_format_key => $this->allowedFormat->id()]; $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save')); $this->assertUrl('node/' . $node->id()); - foreach ($this->container->get('filter.format_repository')->getAllFormats() as $format) { + foreach (\Drupal::service('filter.format_repository')->getAllFormats() as $format) { if (!$format->isFallbackFormat()) { $format->disable()->save(); } @@ -332,7 +332,7 @@ public function testFormatWidgetPermissions() { * Rebuilds text format and permission caches in the thread running the tests. */ protected function resetFilterCaches() { - $this->container->get('filter.format_repository')->resetFormats(); + \Drupal::service('filter.format_repository')->resetFormats(); } } diff --git a/core/modules/filter/tests/src/Functional/FilterNoFormatTest.php b/core/modules/filter/tests/src/Functional/FilterNoFormatTest.php index 86b5274d5f..42a966d36e 100644 --- a/core/modules/filter/tests/src/Functional/FilterNoFormatTest.php +++ b/core/modules/filter/tests/src/Functional/FilterNoFormatTest.php @@ -31,7 +31,7 @@ public function testCheckMarkupNoFormat() { // Make sure that when this text is run through check_markup() with no text // format, it is filtered as though it is in the fallback format. - $this->assertEqual(check_markup($text), check_markup($text, $this->container->get('filter.format_repository')->getFallbackFormatId()), 'Text with no format is filtered the same as text in the fallback format.'); + $this->assertEqual(check_markup($text), check_markup($text, \Drupal::service('filter.format_repository')->getFallbackFormatId()), 'Text with no format is filtered the same as text in the fallback format.'); } } diff --git a/core/modules/filter/tests/src/Kernel/FilterCrudTest.php b/core/modules/filter/tests/src/Kernel/FilterCrudTest.php index 8f81cf3f9e..32c5b2bf8f 100644 --- a/core/modules/filter/tests/src/Kernel/FilterCrudTest.php +++ b/core/modules/filter/tests/src/Kernel/FilterCrudTest.php @@ -66,7 +66,7 @@ public function testTextFormatCrud() { // Disable the text format. $format->disable()->save(); - $formats = $this->container->get('filter.format_repository')->getAllFormats(); + $formats = \Drupal::service('filter.format_repository')->getAllFormats(); $this->assertTrue(!isset($formats[$format->id()]), 'Disabled text format no longer exists.'); } diff --git a/core/modules/filter/tests/src/Kernel/FilterSettingsTest.php b/core/modules/filter/tests/src/Kernel/FilterSettingsTest.php index 0984426f97..3e17f74cf3 100644 --- a/core/modules/filter/tests/src/Kernel/FilterSettingsTest.php +++ b/core/modules/filter/tests/src/Kernel/FilterSettingsTest.php @@ -47,7 +47,7 @@ public function testFilterDefaults() { // Re-save the text format. $filter_defaults_format->save(); // Reload it from scratch. - $this->container->get('filter.format_repository')->resetFormats(); + \Drupal::service('filter.format_repository')->resetFormats(); // Verify that saved filter settings have not been changed. foreach ($filter_defaults_format->filters() as $name => $filter) { diff --git a/core/modules/filter/tests/src/Unit/FilterFormatDeprecationTest.php b/core/modules/filter/tests/src/Unit/FilterFormatDeprecationTest.php index da989d3c3c..6b8735fd87 100644 --- a/core/modules/filter/tests/src/Unit/FilterFormatDeprecationTest.php +++ b/core/modules/filter/tests/src/Unit/FilterFormatDeprecationTest.php @@ -2,9 +2,14 @@ namespace Drupal\Tests\filter\Unit; +use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\DependencyInjection\ContainerBuilder; +use Drupal\Core\Entity\EntityStorageInterface; +use Drupal\Core\Entity\EntityTypeInterface; +use Drupal\Core\Messenger\MessengerInterface; use Drupal\filter\Entity\FilterFormat; use Drupal\filter\FilterFormatInterface; +use Drupal\filter\FilterFormatListBuilder; use Drupal\filter\FilterFormatRepositoryInterface; use Drupal\Tests\UnitTestCase; use Drupal\user\Entity\Role; @@ -33,56 +38,82 @@ protected function setUp() { $format_repository->getFallbackFormatId(Argument::any())->willReturn('foo'); $container->set('filter.format_repository', $format_repository->reveal()); \Drupal::setContainer($container); - - include_once __DIR__ . '/../../../filter.module'; } /** - * @expectedDeprecation filter_formats() is deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. Use the "filter.format_repository" service with ::getAllFormats() to get all formats or with ::getFormatsForAccount() to get all formats that a user is able to access. See https://www.drupal.org/node/3035368. + * @expectedDeprecation filter_formats() is deprecated in Drupal 8.8.0 and will be removed before Drupal 9.0.0. Use the "filter.format_repository" service with ::getAllFormats() to get all formats or with ::getFormatsForAccount() to get all formats that a user is able to access. See https://www.drupal.org/node/3035368. * @see filter_formats() */ public function testFilterFormatsDeprecation() { + include_once __DIR__ . '/../../../filter.module'; filter_formats(); } /** - * @expectedDeprecation filter_formats_reset() is deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. Use the "filter.format_repository" service with ::resetFormats() method. See https://www.drupal.org/node/3035368. + * @expectedDeprecation filter_formats_reset() is deprecated in Drupal 8.8.0 and will be removed before Drupal 9.0.0. Use the "filter.format_repository" service with ::resetFormats() method. See https://www.drupal.org/node/3035368. * @see filter_formats_reset() */ public function testFilterFormatsResetDeprecation() { + include_once __DIR__ . '/../../../filter.module'; filter_formats_reset(); } /** - * @expectedDeprecation filter_get_roles_by_format() is deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. Use the \Drupal\filter\FilterFormatInterface::getRoles() method. See https://www.drupal.org/node/3035368. + * @expectedDeprecation filter_get_roles_by_format() is deprecated in Drupal 8.8.0 and will be removed before Drupal 9.0.0. Use the \Drupal\filter\FilterFormatInterface::getRoles() method. See https://www.drupal.org/node/3035368. * @see filter_formats_reset() */ public function testFilterGetRolesByFormatDeprecation() { + include_once __DIR__ . '/../../../filter.module'; filter_get_roles_by_format($this->prophesize(FilterFormat::class)->reveal()); } /** - * @expectedDeprecation filter_get_formats_by_role() is deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. Use the "filter.format_repository" service with ::getFormatsByRole() method. See https://www.drupal.org/node/3035368. + * @expectedDeprecation filter_get_formats_by_role() is deprecated in Drupal 8.8.0 and will be removed before Drupal 9.0.0. Use the "filter.format_repository" service with ::getFormatsByRole() method. See https://www.drupal.org/node/3035368. * @see filter_get_formats_by_role() */ public function testFilterGetFormatsByRoleDeprecation() { + include_once __DIR__ . '/../../../filter.module'; filter_get_formats_by_role($this->prophesize(Role::class)->reveal()); } /** - * @expectedDeprecation filter_default_format() is deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. Use the "filter.format_repository" service with ::getDefaultFormat() method. See https://www.drupal.org/node/3035368. + * @expectedDeprecation filter_default_format() is deprecated in Drupal 8.8.0 and will be removed before Drupal 9.0.0. Use the "filter.format_repository" service with ::getDefaultFormat() method. See https://www.drupal.org/node/3035368. * @see filter_default_format() */ public function testFilterDefaultFormatDeprecation() { + include_once __DIR__ . '/../../../filter.module'; filter_default_format(); } /** - * @expectedDeprecation filter_fallback_format() is deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. Use the "filter.format_repository" service with ::getFallbackFormatId() method. See https://www.drupal.org/node/3035368. + * @expectedDeprecation filter_fallback_format() is deprecated in Drupal 8.8.0 and will be removed before Drupal 9.0.0. Use the "filter.format_repository" service with ::getFallbackFormatId() method. See https://www.drupal.org/node/3035368. * @see filter_fallback_format() */ public function testFilterFallbackFormatDeprecation() { + include_once __DIR__ . '/../../../filter.module'; filter_fallback_format(); } + /** + * @covers \Drupal\filter\FilterFormatListBuilder::__construct + * @expectedDeprecation The $format_repository parameter will become mandatory before Drupal 9.0.0. See https://www.drupal.org/node/3035368. + */ + public function testFilterFormatListBuilderConstructorParameterOptional() { + new FilterFormatListBuilder( + $this->prophesize(EntityTypeInterface::class)->reveal(), + $this->prophesize(EntityStorageInterface::class)->reveal(), + $this->prophesize(ConfigFactoryInterface::class)->reveal(), + $this->prophesize(MessengerInterface::class)->reveal() + ); + } + + /** + * @expectedDeprecation Using drupal_static_reset() with 'filter_formats' as parameter is deprecated in Drupal 8.8.0 and will be removed before Drupal 9.0.0. Use \Drupal\filter\FilterFormatRepositoryInterface::resetFormats() instead. See https://www.drupal.org/node/3035368. + * @see drupal_static_reset() + */ + public function testFilterFormatsDrupalStaticResetDeprecation() { + require_once $this->root . '/core/includes/bootstrap.inc'; + drupal_static_reset('filter_formats'); + } + } diff --git a/core/modules/layout_builder/tests/src/FunctionalJavascript/LayoutBuilderTest.php b/core/modules/layout_builder/tests/src/FunctionalJavascript/LayoutBuilderTest.php index 99dcb77f36..eb62fbf4b0 100644 --- a/core/modules/layout_builder/tests/src/FunctionalJavascript/LayoutBuilderTest.php +++ b/core/modules/layout_builder/tests/src/FunctionalJavascript/LayoutBuilderTest.php @@ -64,7 +64,7 @@ protected function setUp() { 'body' => [ [ 'value' => 'This is the block content', - 'format' => $this->container->get('filter.format_repository')->getDefaultFormat()->id(), + 'format' => \Drupal::service('filter.format_repository')->getDefaultFormat()->id(), ], ], ])->save(); diff --git a/core/modules/node/tests/src/Functional/NodeRevisionsAllTest.php b/core/modules/node/tests/src/Functional/NodeRevisionsAllTest.php index d29e49385a..9be8cf68d8 100644 --- a/core/modules/node/tests/src/Functional/NodeRevisionsAllTest.php +++ b/core/modules/node/tests/src/Functional/NodeRevisionsAllTest.php @@ -95,7 +95,7 @@ protected function createNodeRevision(NodeInterface $node) { $node->title = $this->randomMachineName(); $node->body = [ 'value' => $this->randomMachineName(32), - 'format' => $this->container->get('filter.format_repository')->getDefaultFormat()->id(), + 'format' => \Drupal::service('filter.format_repository')->getDefaultFormat()->id(), ]; $node->setNewRevision(); // Ensure the revision author is a different user. diff --git a/core/modules/node/tests/src/Functional/NodeRevisionsTest.php b/core/modules/node/tests/src/Functional/NodeRevisionsTest.php index 49864f0305..b93dac2e31 100644 --- a/core/modules/node/tests/src/Functional/NodeRevisionsTest.php +++ b/core/modules/node/tests/src/Functional/NodeRevisionsTest.php @@ -105,7 +105,7 @@ protected function setUp() { $node->title = $this->randomMachineName(); $node->body = [ 'value' => $this->randomMachineName(32), - 'format' => $this->container->get('filter.format_repository')->getDefaultFormat()->id(), + 'format' => \Drupal::service('filter.format_repository')->getDefaultFormat()->id(), ]; $node->untranslatable_string_field->value = $this->randomString(); $node->setNewRevision(); diff --git a/core/modules/node/tests/src/Functional/NodeRevisionsUiTest.php b/core/modules/node/tests/src/Functional/NodeRevisionsUiTest.php index f5b145be1b..f3aceb3c78 100644 --- a/core/modules/node/tests/src/Functional/NodeRevisionsUiTest.php +++ b/core/modules/node/tests/src/Functional/NodeRevisionsUiTest.php @@ -99,7 +99,7 @@ public function testNodeRevisionDoubleEscapeFix() { $node->title = $this->randomMachineName(); $node->body = [ 'value' => $this->randomMachineName(32), - 'format' => $this->container->get('filter.format_repository')->getDefaultFormat()->id(), + 'format' => \Drupal::service('filter.format_repository')->getDefaultFormat()->id(), ]; $node->setNewRevision(); $revision_log = 'Revision message with markup.'; diff --git a/core/modules/node/tests/src/Functional/Views/FilterNodeAccessTest.php b/core/modules/node/tests/src/Functional/Views/FilterNodeAccessTest.php index f9001ea2e6..55c8a187ec 100644 --- a/core/modules/node/tests/src/Functional/Views/FilterNodeAccessTest.php +++ b/core/modules/node/tests/src/Functional/Views/FilterNodeAccessTest.php @@ -57,7 +57,7 @@ protected function setUp($import_test_views = TRUE) { 'body' => [ [ 'value' => $type . ' node', - 'format' => $this->container->get('filter.format_repository')->getDefaultFormat()->id(), + 'format' => \Drupal::service('filter.format_repository')->getDefaultFormat()->id(), ], ], 'title' => t('@private_public Article created by @user', ['@private_public' => $type, '@user' => $web_user->getAccountName()]), diff --git a/core/modules/node/tests/src/Functional/Views/FrontPageTest.php b/core/modules/node/tests/src/Functional/Views/FrontPageTest.php index 490c713d0c..0cdc61ca30 100644 --- a/core/modules/node/tests/src/Functional/Views/FrontPageTest.php +++ b/core/modules/node/tests/src/Functional/Views/FrontPageTest.php @@ -283,7 +283,7 @@ protected function doTestFrontPageViewCacheTags($do_assert_views_caches) { 'body' => [ [ 'value' => $this->randomMachineName(32), - 'format' => $this->container->get('filter.format_repository')->getDefaultFormat()->id(), + 'format' => \Drupal::service('filter.format_repository')->getDefaultFormat()->id(), ], ], 'type' => 'article', diff --git a/core/modules/node/tests/src/Functional/Views/PathPluginTest.php b/core/modules/node/tests/src/Functional/Views/PathPluginTest.php index 2a5e07dad9..e37f6c8f51 100644 --- a/core/modules/node/tests/src/Functional/Views/PathPluginTest.php +++ b/core/modules/node/tests/src/Functional/Views/PathPluginTest.php @@ -48,7 +48,7 @@ protected function setUp($import_test_views = TRUE) { 'body' => [ [ 'value' => $this->randomMachineName(42), - 'format' => $this->container->get('filter.format_repository')->getDefaultFormat()->id(), + 'format' => \Drupal::service('filter.format_repository')->getDefaultFormat()->id(), 'summary' => $this->randomMachineName(), ], ], diff --git a/core/modules/node/tests/src/Functional/Views/RowPluginTest.php b/core/modules/node/tests/src/Functional/Views/RowPluginTest.php index f61c79a2d4..01fbb59df4 100644 --- a/core/modules/node/tests/src/Functional/Views/RowPluginTest.php +++ b/core/modules/node/tests/src/Functional/Views/RowPluginTest.php @@ -49,7 +49,7 @@ protected function setUp($import_test_views = TRUE) { 'body' => [ [ 'value' => $this->randomMachineName(42), - 'format' => $this->container->get('filter.format_repository')->getDefaultFormat()->id(), + 'format' => \Drupal::service('filter.format_repository')->getDefaultFormat()->id(), 'summary' => $this->randomMachineName(), ], ], diff --git a/core/modules/node/tests/src/FunctionalJavascript/ContextualLinksTest.php b/core/modules/node/tests/src/FunctionalJavascript/ContextualLinksTest.php index ff2efd1876..d794bc9822 100644 --- a/core/modules/node/tests/src/FunctionalJavascript/ContextualLinksTest.php +++ b/core/modules/node/tests/src/FunctionalJavascript/ContextualLinksTest.php @@ -56,7 +56,7 @@ protected function setUp() { $node->title = $this->randomMachineName(); $node->body = [ 'value' => $this->randomMachineName(32), - 'format' => $this->container->get('filter.format_repository')->getDefaultFormat()->id(), + 'format' => \Drupal::service('filter.format_repository')->getDefaultFormat()->id(), ]; $node->setNewRevision(); diff --git a/core/modules/quickedit/tests/src/FunctionalJavascript/QuickEditAutocompleteTermTest.php b/core/modules/quickedit/tests/src/FunctionalJavascript/QuickEditAutocompleteTermTest.php index 49b6070827..6cf77b055e 100644 --- a/core/modules/quickedit/tests/src/FunctionalJavascript/QuickEditAutocompleteTermTest.php +++ b/core/modules/quickedit/tests/src/FunctionalJavascript/QuickEditAutocompleteTermTest.php @@ -187,7 +187,7 @@ public function testAutocompleteQuickEdit() { * @throws \Drupal\Core\Entity\EntityStorageException */ protected function createTerm() { - $filter_formats = $this->container->get('filter.format_repository')->getAllFormats(); + $filter_formats = \Drupal::service('filter.format_repository')->getAllFormats(); $format = array_pop($filter_formats); $term = Term::create([ 'name' => $this->randomMachineName(), diff --git a/core/modules/rest/tests/src/Functional/Views/StyleSerializerTest.php b/core/modules/rest/tests/src/Functional/Views/StyleSerializerTest.php index eb09ba2845..325d9ec091 100644 --- a/core/modules/rest/tests/src/Functional/Views/StyleSerializerTest.php +++ b/core/modules/rest/tests/src/Functional/Views/StyleSerializerTest.php @@ -632,7 +632,7 @@ public function testFieldapiField() { // Make sure that serialized fields are not exposed to XSS. $node = $this->drupalCreateNode(); - $format_repository = $this->container->get('filter.format_repository'); + $format_repository = \Drupal::service('filter.format_repository'); $node->body = [ 'value' => '' . $this->randomMachineName(32), 'format' => $format_repository->getDefaultFormat()->id(), diff --git a/core/modules/search/tests/src/Functional/SearchDateIntervalTest.php b/core/modules/search/tests/src/Functional/SearchDateIntervalTest.php index 32b1ccaee2..993b265aaa 100644 --- a/core/modules/search/tests/src/Functional/SearchDateIntervalTest.php +++ b/core/modules/search/tests/src/Functional/SearchDateIntervalTest.php @@ -34,7 +34,7 @@ protected function setUp() { // search_date_query_alter test module. $created_time_en = new \DateTime('February 10 2016 10PM'); $created_time_es = new \DateTime('March 19 2016 10PM'); - $default_format = $this->container->get('filter.format_repository')->getDefaultFormat()->id(); + $default_format = \Drupal::service('filter.format_repository')->getDefaultFormat()->id(); $node = $this->drupalCreateNode([ 'title' => 'Node EN', diff --git a/core/modules/search/tests/src/Functional/SearchLanguageTest.php b/core/modules/search/tests/src/Functional/SearchLanguageTest.php index 59a3439b24..90dfed4b32 100644 --- a/core/modules/search/tests/src/Functional/SearchLanguageTest.php +++ b/core/modules/search/tests/src/Functional/SearchLanguageTest.php @@ -45,7 +45,7 @@ protected function setUp() { $field_storage->save(); // Create a few page nodes with multilingual body values. - $default_format = $this->container->get('filter.format_repository')->getDefaultFormat()->id(); + $default_format = \Drupal::service('filter.format_repository')->getDefaultFormat()->id(); $nodes = [ [ 'title' => 'First node en', diff --git a/core/modules/search/tests/src/Functional/SearchMultilingualEntityTest.php b/core/modules/search/tests/src/Functional/SearchMultilingualEntityTest.php index 0371faf8f8..381d8960ea 100644 --- a/core/modules/search/tests/src/Functional/SearchMultilingualEntityTest.php +++ b/core/modules/search/tests/src/Functional/SearchMultilingualEntityTest.php @@ -62,7 +62,7 @@ protected function setUp() { $field_storage->save(); // Create a few page nodes with multilingual body values. - $default_format = $this->container->get('filter.format_repository')->getDefaultFormat()->id(); + $default_format = \Drupal::service('filter.format_repository')->getDefaultFormat()->id(); $nodes = [ [ 'title' => 'First node en', diff --git a/core/modules/system/tests/src/Functional/Menu/BreadcrumbTest.php b/core/modules/system/tests/src/Functional/Menu/BreadcrumbTest.php index ee33759e5a..c6855dcc8d 100644 --- a/core/modules/system/tests/src/Functional/Menu/BreadcrumbTest.php +++ b/core/modules/system/tests/src/Functional/Menu/BreadcrumbTest.php @@ -127,7 +127,7 @@ public function testBreadCrumbs() { $this->assertBreadcrumb("admin/structure/types/manage/$type/fields/node.$type.body", $trail); // Verify Filter text format administration breadcrumbs. - $filter_formats = $this->container->get('filter.format_repository')->getAllFormats(); + $filter_formats = \Drupal::service('filter.format_repository')->getAllFormats(); $format = reset($filter_formats); $format_id = $format->id(); $trail = $config + [ diff --git a/core/modules/taxonomy/src/Tests/TaxonomyTestTrait.php b/core/modules/taxonomy/src/Tests/TaxonomyTestTrait.php index d78ff2204e..afdaceff9f 100644 --- a/core/modules/taxonomy/src/Tests/TaxonomyTestTrait.php +++ b/core/modules/taxonomy/src/Tests/TaxonomyTestTrait.php @@ -45,7 +45,7 @@ public function createVocabulary() { * The new taxonomy term object. */ public function createTerm(Vocabulary $vocabulary, $values = []) { - $filter_formats = $this->container->get('filter.format_repository')->getAllFormats(); + $filter_formats = \Drupal::service('filter.format_repository')->getAllFormats(); $format = array_pop($filter_formats); $term = Term::create($values + [ 'name' => $this->randomMachineName(), diff --git a/core/modules/taxonomy/tests/src/Functional/TaxonomyTestTrait.php b/core/modules/taxonomy/tests/src/Functional/TaxonomyTestTrait.php index 71fd1eee65..c9fa15d880 100644 --- a/core/modules/taxonomy/tests/src/Functional/TaxonomyTestTrait.php +++ b/core/modules/taxonomy/tests/src/Functional/TaxonomyTestTrait.php @@ -40,7 +40,7 @@ public function createVocabulary() { * The new taxonomy term object. */ public function createTerm(Vocabulary $vocabulary, $values = []) { - $filter_formats = $this->container->get('filter.format_repository')->getAllFormats(); + $filter_formats = \Drupal::service('filter.format_repository')->getAllFormats(); $format = array_pop($filter_formats); $term = Term::create($values + [ 'name' => $this->randomMachineName(), diff --git a/core/modules/taxonomy/tests/src/Functional/Views/TaxonomyFieldFilterTest.php b/core/modules/taxonomy/tests/src/Functional/Views/TaxonomyFieldFilterTest.php index 942bcab818..3cbbc0e3ec 100644 --- a/core/modules/taxonomy/tests/src/Functional/Views/TaxonomyFieldFilterTest.php +++ b/core/modules/taxonomy/tests/src/Functional/Views/TaxonomyFieldFilterTest.php @@ -160,7 +160,7 @@ protected function assertPageCounts($path, $counts, $message) { */ protected function createTermWithProperties($properties) { // Use the first available text format. - $filter_formats = $this->container->get('filter.format_repository')->getAllFormats(); + $filter_formats = \Drupal::service('filter.format_repository')->getAllFormats(); $format = array_pop($filter_formats); $properties += [ diff --git a/core/modules/taxonomy/tests/src/Functional/Views/TaxonomyTestBase.php b/core/modules/taxonomy/tests/src/Functional/Views/TaxonomyTestBase.php index 14375b086f..94618d55cd 100644 --- a/core/modules/taxonomy/tests/src/Functional/Views/TaxonomyTestBase.php +++ b/core/modules/taxonomy/tests/src/Functional/Views/TaxonomyTestBase.php @@ -137,7 +137,7 @@ protected function mockStandardInstall() { * The created taxonomy term. */ protected function createTerm(array $settings = []) { - $filter_formats = $this->container->get('filter.format_repository')->getAllFormats(); + $filter_formats = \Drupal::service('filter.format_repository')->getAllFormats(); $format = array_pop($filter_formats); $settings += [ 'name' => $this->randomMachineName(), diff --git a/core/modules/taxonomy/tests/src/Kernel/Views/TaxonomyTestBase.php b/core/modules/taxonomy/tests/src/Kernel/Views/TaxonomyTestBase.php index 7ef0721e46..50871de693 100644 --- a/core/modules/taxonomy/tests/src/Kernel/Views/TaxonomyTestBase.php +++ b/core/modules/taxonomy/tests/src/Kernel/Views/TaxonomyTestBase.php @@ -169,7 +169,7 @@ protected function mockStandardInstall() { * The created taxonomy term. */ protected function createTerm(array $settings = []) { - $filter_formats = $this->container->get('filter.format_repository')->getAllFormats(); + $filter_formats = \Drupal::service('filter.format_repository')->getAllFormats(); $format = array_pop($filter_formats); $settings += [ 'name' => $this->randomMachineName(), diff --git a/core/modules/text/tests/src/Functional/TextFieldTest.php b/core/modules/text/tests/src/Functional/TextFieldTest.php index 032870ad70..4d8c5f58e2 100644 --- a/core/modules/text/tests/src/Functional/TextFieldTest.php +++ b/core/modules/text/tests/src/Functional/TextFieldTest.php @@ -177,7 +177,7 @@ public function _testTextfieldWidgetsFormatted($field_type, $widget_type) { // Disable all text formats besides the plain text fallback format. $this->drupalLogin($this->adminUser); - foreach ($this->container->get('filter.format_repository')->getAllFormats() as $format) { + foreach (\Drupal::service('filter.format_repository')->getAllFormats() as $format) { if (!$format->isFallbackFormat()) { $this->drupalPostForm('admin/config/content/formats/manage/' . $format->id() . '/disable', [], t('Disable')); } @@ -216,7 +216,7 @@ public function _testTextfieldWidgetsFormatted($field_type, $widget_type) { 'name' => $this->randomMachineName(), ]; $this->drupalPostForm('admin/config/content/formats/add', $edit, t('Save configuration')); - $this->container->get('filter.format_repository')->resetFormats(); + \Drupal::service('filter.format_repository')->resetFormats(); $format = FilterFormat::load($edit['format']); $format_id = $format->id(); $permission = $format->getPermissionName(); diff --git a/core/modules/text/tests/src/FunctionalJavascript/TextareaWithSummaryTest.php b/core/modules/text/tests/src/FunctionalJavascript/TextareaWithSummaryTest.php index 64a4267732..e4abd22934 100644 --- a/core/modules/text/tests/src/FunctionalJavascript/TextareaWithSummaryTest.php +++ b/core/modules/text/tests/src/FunctionalJavascript/TextareaWithSummaryTest.php @@ -70,7 +70,7 @@ public function testTextSummaryBehavior() { [ 'value' => $this->randomMachineName(32), 'summary' => $this->randomMachineName(32), - 'format' => $this->container->get('filter.format_repository')->getDefaultFormat()->id(), + 'format' => \Drupal::service('filter.format_repository')->getDefaultFormat()->id(), ], ], ]); diff --git a/core/modules/views/tests/src/Functional/DefaultViewsTest.php b/core/modules/views/tests/src/Functional/DefaultViewsTest.php index a72fa49104..7d353ddf54 100644 --- a/core/modules/views/tests/src/Functional/DefaultViewsTest.php +++ b/core/modules/views/tests/src/Functional/DefaultViewsTest.php @@ -152,7 +152,7 @@ public function testDefaultViews() { * Returns a new term with random properties in vocabulary $vid. */ public function createTerm($vocabulary) { - $filter_formats = $this->container->get('filter.format_repository')->getAllFormats(); + $filter_formats = \Drupal::service('filter.format_repository')->getAllFormats(); $format = array_pop($filter_formats); $term = Term::create([ 'name' => $this->randomMachineName(), diff --git a/core/modules/views/tests/src/Functional/Plugin/DisplayFeedTest.php b/core/modules/views/tests/src/Functional/Plugin/DisplayFeedTest.php index 7b2c318282..6683ada99b 100644 --- a/core/modules/views/tests/src/Functional/Plugin/DisplayFeedTest.php +++ b/core/modules/views/tests/src/Functional/Plugin/DisplayFeedTest.php @@ -49,7 +49,7 @@ public function testFeedOutput() { 'body' => [ 0 => [ 'value' => 'A paragraph', - 'format' => $this->container->get('filter.format_repository')->getDefaultFormat()->id(), + 'format' => \Drupal::service('filter.format_repository')->getDefaultFormat()->id(), ], ], ]); @@ -107,7 +107,7 @@ public function testFeedFieldOutput() { 'body' => [ 0 => [ 'value' => 'A paragraph', - 'format' => $this->container->get('filter.format_repository')->getDefaultFormat()->id(), + 'format' => \Drupal::service('filter.format_repository')->getDefaultFormat()->id(), ], ], ]); diff --git a/core/modules/views/tests/src/Functional/Plugin/ExposedFormTest.php b/core/modules/views/tests/src/Functional/Plugin/ExposedFormTest.php index 79991e80b4..c271ab60c0 100644 --- a/core/modules/views/tests/src/Functional/Plugin/ExposedFormTest.php +++ b/core/modules/views/tests/src/Functional/Plugin/ExposedFormTest.php @@ -283,7 +283,7 @@ public function testTextInputRequired() { // @see https://www.drupal.org/node/535868 $on_demand_text = 'Select any filter and click Apply to see results.'; $display['display_options']['exposed_form']['options']['text_input_required'] = $on_demand_text; - $display['display_options']['exposed_form']['options']['text_input_required_format'] = $this->container->get('filter.format_repository')->getDefaultFormat()->id(); + $display['display_options']['exposed_form']['options']['text_input_required_format'] = \Drupal::service('filter.format_repository')->getDefaultFormat()->id(); $view->save(); // Ensure that the "on demand text" is displayed when no exposed filters are diff --git a/core/modules/views/tests/src/Kernel/Handler/AreaTextTest.php b/core/modules/views/tests/src/Kernel/Handler/AreaTextTest.php index d5c9052053..d235ad3e87 100644 --- a/core/modules/views/tests/src/Kernel/Handler/AreaTextTest.php +++ b/core/modules/views/tests/src/Kernel/Handler/AreaTextTest.php @@ -55,7 +55,7 @@ public function testAreaText() { $build = $view->display_handler->handlers['header']['area']->render(); $this->assertEqual('', $renderer->renderRoot($build), 'Nonexistent format should return empty markup.'); - $view->display_handler->handlers['header']['area']->options['content']['format'] = $this->container->get('filter.format_repository')->getDefaultFormat()->id(); + $view->display_handler->handlers['header']['area']->options['content']['format'] = \Drupal::service('filter.format_repository')->getDefaultFormat()->id(); $build = $view->display_handler->handlers['header']['area']->render(); $this->assertEqual(check_markup($string), $renderer->renderRoot($build), 'Existent format should return something'); diff --git a/core/tests/Drupal/KernelTests/Core/Entity/EntityFieldTest.php b/core/tests/Drupal/KernelTests/Core/Entity/EntityFieldTest.php index be807948d7..4f0c4a91dc 100644 --- a/core/tests/Drupal/KernelTests/Core/Entity/EntityFieldTest.php +++ b/core/tests/Drupal/KernelTests/Core/Entity/EntityFieldTest.php @@ -907,7 +907,7 @@ public function testEntityReferenceComputedField() { protected function doTestComputedProperties($entity_type) { $entity = $this->createTestEntity($entity_type); $entity->field_test_text->value = "The text text to filter."; - $entity->field_test_text->format = $this->container->get('filter.format_repository')->getDefaultFormat()->id(); + $entity->field_test_text->format = \Drupal::service('filter.format_repository')->getDefaultFormat()->id(); $target = "

The <strong>text</strong> text to filter.

\n"; $this->assertEqual($entity->field_test_text->processed, $target, format_string('%entity_type: Text is processed with the default filter.', ['%entity_type' => $entity_type]));