Problem/Motivation

The following methods are still in filter.module with no OO replacement:

  • filter_formats()
  • filter_formats_reset()
  • filter_get_roles_by_format()
  • filter_get_formats_by_role()
  • filter_default_format()
  • filter_fallback_format()

They are all for loading filter formats under certain circumstances, and many revolve around old drupal_static calls.

Splitting filter_formats() into two methods is especially important, as the extra $account parameter drastically changes the behavior of the function (whether or not any access checks should be performed).

Proposed resolution

  • Create a new service Drupal\filter\FilterFormatRepositoryInterface
  • Deprecate all 6 of these functions. Move the functionality of 5 out of 6 to the new service. The filter_formats_reset() functionality is replaced by a call to \Drupal::cache('memory')->delete('filter_formats').

Remaining tasks

None.

User interface changes

None.

API changes

  • New service Drupal\filter\FilterFormatRepositoryInterface
  • Procedural functions are deprecated

Data model changes

None.

CommentFileSizeAuthor
#66 interdiff_64-66.txt1.58 KBridhimaabrol24
#66 2536594-66.patch94.14 KBridhimaabrol24
#64 interdiff_62-64.txt2.66 KBridhimaabrol24
#64 2536594-64.patch93.94 KBridhimaabrol24
#62 interdiff_61-62.txt1.02 KBridhimaabrol24
#62 2536594-62.patch92.72 KBridhimaabrol24
#61 2536594-61.patch92.72 KBridhimaabrol24
#57 2536594-57.patch92.44 KBclaudiu.cristea
#56 2536594-56.patch14.06 KBclaudiu.cristea
#56 2536594-56.interdiff.txt14.06 KBclaudiu.cristea
#52 2536594-52.patch92.45 KBandypost
#52 interdiff.txt13.11 KBandypost
#50 2536594-50.patch94.08 KBandypost
#50 interdiff.txt4.92 KBandypost
#47 2536594-47.interdiff.txt48.48 KBclaudiu.cristea
#47 2536594-47.patch95.1 KBclaudiu.cristea
#44 2536594-44.interdiff.txt527 bytesclaudiu.cristea
#44 2536594-44.patch94.97 KBclaudiu.cristea
#42 2536594-42.patch94.97 KBclaudiu.cristea
#42 2536594-42.interdiff.txt4.85 KBclaudiu.cristea
#40 2536594-40.interdiff.txt50.35 KBclaudiu.cristea
#40 2536594-40.patch91 KBclaudiu.cristea
#37 2536594-37.patch91.81 KBclaudiu.cristea
#37 2536594-37.interdiff.txt1.29 KBclaudiu.cristea
#35 2536594-34.patch91.8 KBclaudiu.cristea
#35 2536594-34.interdiff.txt4.92 KBclaudiu.cristea
#32 2536594-32.patch91.44 KBclaudiu.cristea
#32 2536594-32.interdiff.txt2.19 KBclaudiu.cristea
#30 2536594-30.interdiff.txt19.46 KBclaudiu.cristea
#30 2536594-30.patch91.45 KBclaudiu.cristea
#29 2536594-29.interdiff.txt746 bytesclaudiu.cristea
#29 2536594-29.patch91.31 KBclaudiu.cristea
#27 2536594-27.interdiff.txt59.48 KBclaudiu.cristea
#27 2536594-27.patch92.04 KBclaudiu.cristea
#25 2536594-25.interdiff.txt59.48 KBclaudiu.cristea
#25 2536594-25.patch59.48 KBclaudiu.cristea
#22 2536594-22.patch34.78 KBclaudiu.cristea
#22 2536594-22.interdiff.txt22.63 KBclaudiu.cristea
#11 interdiff.txt7.6 KBtim.plunkett
#11 filter-2536594-11.patch35.44 KBtim.plunkett
#10 interdiff.txt2.1 KBdawehner
#9 filter-2536594-9.patch35.28 KBtim.plunkett
#9 interdiff.txt6.91 KBtim.plunkett
#7 interdiff.txt16.46 KBtim.plunkett
#7 filter-2536594-7.patch34.86 KBtim.plunkett
#5 interdiff.txt525 bytestim.plunkett
#5 filter-2536594-5.patch35.66 KBtim.plunkett
#3 interdiff.txt3.64 KBtim.plunkett
#3 filter-2536594-3.patch35.66 KBtim.plunkett
#1 filter-2536594-1.patch32.02 KBtim.plunkett

Issue fork drupal-2536594

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

tim.plunkett’s picture

Status: Active » Needs review
StatusFileSize
new32.02 KB

Status: Needs review » Needs work

The last submitted patch, 1: filter-2536594-1.patch, failed testing.

tim.plunkett’s picture

Status: Needs work » Needs review
StatusFileSize
new35.66 KB
new3.64 KB

Ran php core/scripts/generate-proxy-class.php '\Drupal\filter\FilterFormatRepository' "core/modules/filter/src" to fix that

Status: Needs review » Needs work

The last submitted patch, 3: filter-2536594-3.patch, failed testing.

tim.plunkett’s picture

Status: Needs work » Needs review
StatusFileSize
new35.66 KB
new525 bytes

You've gotta be kidding me. Why the hell is that not valid!?

dawehner’s picture

It is great to do those things, but I kinda doubt this will be able to land in 8.0.x

  1. +++ b/core/modules/filter/src/FilterFormatRepositoryInterface.php
    @@ -0,0 +1,113 @@
    +  /**
    +   * Gets only those formats that are allowed for this user account.
    +   *
    

    Define what means allowed

  2. +++ b/core/modules/filter/src/FilterFormatRepositoryInterface.php
    @@ -0,0 +1,113 @@
    +   * Gets a list of text formats that are allowed for a given role.
    ...
    +   * Returns the default text format for a particular user.
    

    Any reason for gets vs. returns?

  3. +++ b/core/modules/filter/tests/src/Unit/FilterFormatRepositoryTest.php
    @@ -0,0 +1,309 @@
    +class FilterFormatRepositoryTest extends UnitTestCase {
    

    Did you considered mocking using prophecy? You should see the error messages created by prophecy, its from another universe

  4. +++ b/core/modules/filter/tests/src/Unit/FilterFormatRepositoryTest.php
    @@ -0,0 +1,309 @@
    +    $entity_type_definition = $this->getMock('\Drupal\Core\Entity\EntityTypeInterface');
    

    I would argue that entity type definitions are value objects and so don't need to be mocked, as they don't consists of logic for themselves

tim.plunkett’s picture

StatusFileSize
new34.86 KB
new16.46 KB

1) Rewritten
2) Returns was c/p, changed all to Gets
3) Tried it out. Thanks for the pointers
4) Fair point!

dawehner’s picture

+++ b/core/modules/filter/tests/src/Unit/FilterFormatRepositoryTest.php
@@ -0,0 +1,274 @@
+    $current_language = $this->prophesize('\Drupal\Core\Language\LanguageInterface');

What about using ::class and get autocompletion?

tim.plunkett’s picture

StatusFileSize
new6.91 KB
new35.28 KB

I broke some of the coverage with that.

Also I have no idea what #8 is suggesting. @dawehner, do you want to implement what you have in mind?

dawehner’s picture

StatusFileSize
new2.1 KB

Sometimes along this lines ...

tim.plunkett’s picture

StatusFileSize
new35.44 KB
new7.6 KB

Oh cool, importing those really shows you how many things you depend on.
@dawehner++

mile23’s picture

Status: Needs review » Needs work

Really like the Interface::class pattern. :-)

I don't suppose there's an easy way to do a test-only patch here.

+++ b/core/modules/filter/filter.module
@@ -85,174 +85,69 @@ function filter_theme() {
+ * @deprecated in Drupal 8.0.x-dev, will be removed before Drupal 9.0.0. Use
+ *   either \Drupal\filter\FilterFormatRepositoryInterface::getAllFormats() or
+ *   \Drupal\filter\FilterFormatRepositoryInterface::getFormatsForAccount().

The patch in #11 still applies, but there's no FilterFormatRepositoryInterface anymore.

mile23’s picture

Hey, you know what? git diff --name-only won't tell you files *added* by the patch. :-)

mile23’s picture

My proxy-fu is no good, so I can't review that. Coding standards:

+++ b/core/modules/filter/src/FilterFormatRepositoryInterface.php
@@ -0,0 +1,113 @@
+   *
+   * @return \Drupal\filter\FilterFormatInterface
+   */
+  public function getDefaultFormat(AccountInterface $account = NULL);
+

Needs a return comment.

Mile23 queued 11: filter-2536594-11.patch for re-testing.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

claudiu.cristea’s picture

Version: 8.6.x-dev » 8.7.x-dev
Status: Needs work » Needs review
Issue tags: -Needs beta evaluation
StatusFileSize
new22.63 KB
new34.78 KB

Added CR. Rerolled, refreshed the code, added proper deprecations.

claudiu.cristea’s picture

Adding #1577902: [META] Remove all usages of drupal_static() & drupal_static_reset() as related because this remove usages of drupal_static() and drupal_static_reset().

Status: Needs review » Needs work

The last submitted patch, 22: 2536594-22.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

claudiu.cristea’s picture

Status: Needs work » Needs review
StatusFileSize
new59.48 KB
new59.48 KB

Replaced all usages of deprecated functions.

Status: Needs review » Needs work

The last submitted patch, 25: 2536594-25.patch, failed testing. View results

claudiu.cristea’s picture

Status: Needs work » Needs review
StatusFileSize
new92.04 KB
new59.48 KB

The patch from #25 was wrong. Republishing.

Status: Needs review » Needs work

The last submitted patch, 27: 2536594-27.patch, failed testing. View results

claudiu.cristea’s picture

Status: Needs work » Needs review
StatusFileSize
new91.31 KB
new746 bytes

Ouch, an accidental edit.

claudiu.cristea’s picture

StatusFileSize
new91.45 KB
new19.46 KB

::getDefaultFormat() was not properly used.

The last submitted patch, 29: 2536594-29.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

claudiu.cristea’s picture

StatusFileSize
new2.19 KB
new91.44 KB

More fixes.

The last submitted patch, 30: 2536594-30.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

Status: Needs review » Needs work

The last submitted patch, 32: 2536594-32.patch, failed testing. View results

claudiu.cristea’s picture

Status: Needs work » Needs review
StatusFileSize
new4.92 KB
new91.8 KB

Fixing coding standards.

Status: Needs review » Needs work

The last submitted patch, 35: 2536594-34.patch, failed testing. View results

claudiu.cristea’s picture

Status: Needs work » Needs review
StatusFileSize
new1.29 KB
new91.81 KB

Last fix.

andypost’s picture

+++ b/core/modules/filter/filter.services.yml
@@ -9,3 +9,8 @@ services:
+  filter.filter_format_repository:

why not just filter.format_repository?

claudiu.cristea’s picture

I would say, better filter.format_repository. Because the service ID is always namespaced under the module’s name, which in this case is filter.*

EDIT: @andypost, initially I misread your comment. In fact we're on the same page.

claudiu.cristea’s picture

StatusFileSize
new91 KB
new50.35 KB

Fixed #38. Improved the service.

Status: Needs review » Needs work

The last submitted patch, 40: 2536594-40.patch, failed testing. View results

claudiu.cristea’s picture

Status: Needs work » Needs review
StatusFileSize
new4.85 KB
new94.97 KB

Added deprecation test. Fixed unit test failure.

Status: Needs review » Needs work

The last submitted patch, 42: 2536594-42.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

claudiu.cristea’s picture

Status: Needs work » Needs review
StatusFileSize
new94.97 KB
new527 bytes

Coding standards.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

claudiu.cristea’s picture

Assigned: Unassigned » claudiu.cristea
Status: Needs review » Needs work
  1. +++ b/core/modules/comment/src/Plugin/migrate/source/d6/Comment.php
    @@ -85,7 +85,7 @@ public function fields() {
    -      'format' => $this->t('The {filter_formats}.format of the comment body.'),
    +      'format' => $this->t('The {filter_format}.format of the comment body.'),
    
    +++ b/core/modules/comment/src/Plugin/migrate/source/d7/Comment.php
    @@ -79,7 +79,7 @@ public function fields() {
    -      'format' => $this->t('The {filter_formats}.format of the comment body.'),
    +      'format' => $this->t('The {filter_format}.format of the comment body.'),
    

    Not related & wrong changes. Undo.

  2. +++ b/core/modules/filter/filter.module
    @@ -90,50 +89,36 @@ function filter_theme() {
    + * @deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. Use the
    ...
    +  @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);
    ...
    + * @deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. Use the
    ...
    +  @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);
    
    @@ -144,15 +129,15 @@ function filter_formats_reset() {
    + * @deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. Use the
    ...
    +  @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);
    
    @@ -164,16 +149,15 @@ function filter_get_roles_by_format(FilterFormatInterface $format) {
    + * @deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. Use the
    ...
    +  @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);
    
    @@ -199,17 +183,14 @@ function filter_get_formats_by_role($rid) {
    + * @deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. Use the
    ...
    +  @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);
    
    @@ -238,17 +219,16 @@ function filter_default_format(AccountInterface $account = NULL) {
    + * @deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. Use the
    ...
    +  @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);
    

    Increase version: 8.7.0 -> 8.8.0. Update also the CR.

  3. +++ b/core/modules/filter/src/Entity/FilterFormat.php
    @@ -409,6 +410,19 @@ public function removeFilter($instance_id) {
    +    // Handle the fallback format upfront (all roles have access to this format).
    

    Exceeds 80 chars.

  4. +++ b/core/modules/filter/src/FilterFormatListBuilder.php
    @@ -48,12 +55,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) {
    ...
    +    $this->formatRepository = $format_repository;
    

    For BC reasons $format_repository should be optional and should trigger deprecation error if not passed.

  5. +++ b/core/modules/filter/tests/src/Functional/FilterAdminTest.php
    @@ -187,8 +187,9 @@ public function testFilterAdmin() {
    +    $format_repository = $this->container->get('filter.format_repository');
    
    +++ b/core/modules/filter/tests/src/Functional/FilterDefaultFormatTest.php
    @@ -50,12 +50,13 @@ public function testDefaultTextFormats() {
    +    $format_repository = $this->container->get('filter.format_repository');
    
    @@ -65,14 +66,14 @@ public function testDefaultTextFormats() {
    +    $this->container->get('filter.format_repository')->resetFormats();
    
    +++ b/core/modules/filter/tests/src/Functional/FilterFormatAccessTest.php
    @@ -118,9 +118,10 @@ protected function setUp() {
    +    $format_repository = $this->container->get('filter.format_repository');
    
    @@ -189,17 +190,18 @@ public function testFormatRoles() {
    +    $format_repository = $this->container->get('filter.format_repository');
    
    @@ -283,8 +285,10 @@ public function testFormatWidgetPermissions() {
    +    $format_repository = $this->container->get('filter.format_repository');
    
    @@ -296,7 +300,7 @@ public function testFormatWidgetPermissions() {
    +    foreach ($this->container->get('filter.format_repository')->getAllFormats() as $format) {
    
    @@ -328,7 +332,7 @@ public function testFormatWidgetPermissions() {
    +    $this->container->get('filter.format_repository')->resetFormats();
    
    +++ b/core/modules/filter/tests/src/Functional/FilterNoFormatTest.php
    @@ -31,7 +31,7 @@ public function testCheckMarkupNoFormat() {
    +    $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.');
    
    +++ b/core/modules/filter/tests/src/Kernel/FilterAPITest.php
    @@ -486,7 +486,7 @@ public function testDependencyRemoval() {
    +    \Drupal::service('filter.format_repository')->resetFormats();
    
    +++ b/core/modules/filter/tests/src/Kernel/FilterCrudTest.php
    @@ -66,8 +66,8 @@ public function testTextFormatCrud() {
    +    $formats = $this->container->get('filter.format_repository')->getAllFormats();
    
    +++ b/core/modules/filter/tests/src/Kernel/FilterSettingsTest.php
    @@ -47,7 +47,7 @@ public function testFilterDefaults() {
    +    $this->container->get('filter.format_repository')->resetFormats();
    
    +++ b/core/modules/layout_builder/tests/src/FunctionalJavascript/LayoutBuilderTest.php
    @@ -64,7 +64,7 @@ protected function setUp() {
    +          'format' => $this->container->get('filter.format_repository')->getDefaultFormat()->id(),
    
    +++ b/core/modules/node/tests/src/Functional/NodeRevisionsAllTest.php
    @@ -95,7 +95,7 @@ protected function createNodeRevision(NodeInterface $node) {
    +      'format' => $this->container->get('filter.format_repository')->getDefaultFormat()->id(),
    
    +++ b/core/modules/node/tests/src/Functional/NodeRevisionsTest.php
    @@ -105,7 +105,7 @@ protected function setUp() {
    +        'format' => $this->container->get('filter.format_repository')->getDefaultFormat()->id(),
    
    +++ b/core/modules/node/tests/src/Functional/NodeRevisionsUiTest.php
    @@ -99,7 +99,7 @@ public function testNodeRevisionDoubleEscapeFix() {
    +      'format' => $this->container->get('filter.format_repository')->getDefaultFormat()->id(),
    
    +++ b/core/modules/node/tests/src/Functional/Views/FilterNodeAccessTest.php
    @@ -57,7 +57,7 @@ protected function setUp($import_test_views = TRUE) {
    +              'format' => $this->container->get('filter.format_repository')->getDefaultFormat()->id(),
    
    +++ b/core/modules/node/tests/src/Functional/Views/FrontPageTest.php
    @@ -283,7 +283,7 @@ protected function doTestFrontPageViewCacheTags($do_assert_views_caches) {
    +            'format' => $this->container->get('filter.format_repository')->getDefaultFormat()->id(),
    
    +++ b/core/modules/node/tests/src/Functional/Views/PathPluginTest.php
    @@ -48,7 +48,7 @@ protected function setUp($import_test_views = TRUE) {
    +              'format' => $this->container->get('filter.format_repository')->getDefaultFormat()->id(),
    
    +++ b/core/modules/node/tests/src/Functional/Views/RowPluginTest.php
    @@ -49,7 +49,7 @@ protected function setUp($import_test_views = TRUE) {
    +              'format' => $this->container->get('filter.format_repository')->getDefaultFormat()->id(),
    
    +++ b/core/modules/node/tests/src/FunctionalJavascript/ContextualLinksTest.php
    @@ -56,7 +56,7 @@ protected function setUp() {
    +        'format' => $this->container->get('filter.format_repository')->getDefaultFormat()->id(),
    
    +++ b/core/modules/quickedit/src/Tests/QuickEditAutocompleteTermTest.php
    @@ -198,7 +198,7 @@ public function testAutocompleteQuickEdit() {
    +    $filter_formats = $this->container->get('filter.format_repository')->getAllFormats();
    
    +++ b/core/modules/rest/tests/src/Functional/Views/StyleSerializerTest.php
    @@ -632,9 +632,10 @@ public function testFieldapiField() {
    +    $format_repository = $this->container->get('filter.format_repository');
    
    +++ b/core/modules/search/tests/src/Functional/SearchDateIntervalTest.php
    @@ -34,7 +34,7 @@ protected function setUp() {
    +    $default_format = $this->container->get('filter.format_repository')->getDefaultFormat()->id();
    
    +++ b/core/modules/search/tests/src/Functional/SearchLanguageTest.php
    @@ -45,7 +45,7 @@ protected function setUp() {
    +    $default_format = $this->container->get('filter.format_repository')->getDefaultFormat()->id();
    
    +++ b/core/modules/search/tests/src/Functional/SearchMultilingualEntityTest.php
    @@ -62,7 +62,7 @@ protected function setUp() {
    +    $default_format = $this->container->get('filter.format_repository')->getDefaultFormat()->id();
    
    +++ b/core/modules/system/tests/src/Functional/Menu/BreadcrumbTest.php
    @@ -127,7 +127,7 @@ public function testBreadCrumbs() {
    +    $filter_formats = $this->container->get('filter.format_repository')->getAllFormats();
    
    +++ b/core/modules/taxonomy/src/Tests/TaxonomyTestTrait.php
    @@ -45,7 +45,7 @@ public function createVocabulary() {
    +    $filter_formats = $this->container->get('filter.format_repository')->getAllFormats();
    
    +++ b/core/modules/taxonomy/tests/src/Functional/TaxonomyTestTrait.php
    @@ -40,7 +40,7 @@ public function createVocabulary() {
    +    $filter_formats = $this->container->get('filter.format_repository')->getAllFormats();
    
    +++ b/core/modules/taxonomy/tests/src/Functional/Views/TaxonomyFieldFilterTest.php
    @@ -160,7 +160,7 @@ protected function assertPageCounts($path, $counts, $message) {
    +    $filter_formats = $this->container->get('filter.format_repository')->getAllFormats();
    
    +++ b/core/modules/taxonomy/tests/src/Functional/Views/TaxonomyTestBase.php
    @@ -137,7 +137,7 @@ protected function mockStandardInstall() {
    +    $filter_formats = $this->container->get('filter.format_repository')->getAllFormats();
    
    +++ b/core/modules/taxonomy/tests/src/Kernel/Views/TaxonomyTestBase.php
    @@ -166,7 +166,7 @@ protected function mockStandardInstall() {
    +    $filter_formats = $this->container->get('filter.format_repository')->getAllFormats();
    
    +++ b/core/modules/text/tests/src/Functional/TextFieldTest.php
    @@ -177,7 +177,7 @@ public function _testTextfieldWidgetsFormatted($field_type, $widget_type) {
    +    foreach ($this->container->get('filter.format_repository')->getAllFormats() as $format) {
    
    @@ -216,7 +216,7 @@ public function _testTextfieldWidgetsFormatted($field_type, $widget_type) {
    +    $this->container->get('filter.format_repository')->resetFormats();
    
    +++ b/core/modules/text/tests/src/FunctionalJavascript/TextareaWithSummaryTest.php
    @@ -70,7 +70,7 @@ public function testTextSummaryBehavior() {
    +          'format' => $this->container->get('filter.format_repository')->getDefaultFormat()->id(),
    
    +++ b/core/modules/views/tests/src/Functional/DefaultViewsTest.php
    @@ -152,7 +152,7 @@ public function testDefaultViews() {
    +    $filter_formats = $this->container->get('filter.format_repository')->getAllFormats();
    
    +++ b/core/modules/views/tests/src/Functional/Plugin/DisplayFeedTest.php
    @@ -49,7 +49,7 @@ public function testFeedOutput() {
    +          'format' => $this->container->get('filter.format_repository')->getDefaultFormat()->id(),
    
    @@ -107,7 +107,7 @@ public function testFeedFieldOutput() {
    +          'format' => $this->container->get('filter.format_repository')->getDefaultFormat()->id(),
    
    +++ b/core/modules/views/tests/src/Functional/Plugin/ExposedFormTest.php
    @@ -283,7 +283,7 @@ public function testTextInputRequired() {
    +    $display['display_options']['exposed_form']['options']['text_input_required_format'] = $this->container->get('filter.format_repository')->getDefaultFormat()->id();
    
    +++ b/core/modules/views/tests/src/Kernel/Handler/AreaTextTest.php
    @@ -55,7 +55,7 @@ public function testAreaText() {
    +    $view->display_handler->handlers['header']['area']->options['content']['format'] = $this->container->get('filter.format_repository')->getDefaultFormat()->id();
    
    +++ b/core/tests/Drupal/KernelTests/Core/Entity/EntityFieldTest.php
    @@ -907,7 +907,7 @@ public function testEntityReferenceComputedField() {
    +    $entity->field_test_text->format = $this->container->get('filter.format_repository')->getDefaultFormat()->id();
    

    Tests should use \Drupal::service(...) instead of $this->container->get(...).

Apart from the inline review, we should handle the case when a 3rd party code uses calls the cache reset directly drupal_cache_reset('filter_formats').

claudiu.cristea’s picture

Assigned: claudiu.cristea » Unassigned
Status: Needs work » Needs review
Parent issue: » #1577902: [META] Remove all usages of drupal_static() & drupal_static_reset()
Related issues: -#1577902: [META] Remove all usages of drupal_static() & drupal_static_reset()
StatusFileSize
new95.1 KB
new48.48 KB

Fixed #46.

andypost’s picture

+++ b/core/modules/filter/src/FilterFormatRepository.php
@@ -0,0 +1,174 @@
+      $cid = 'filter_formats:' . $this->languageManager->getCurrentLanguage()->getId();
+      if ($cache = $this->cacheBackend->get($cid)) {
+        $this->formatsAll = $cache->data;
...
+  public function resetFormats() {
+    unset($this->formatsAll);
+    $this->formatsByUser = [];

btw Entities are could be statically cached in storage handler and I'm sure better to relay on its caching instead of internal property
Also it needs __sleep() method to unset this properties on serialize

claudiu.cristea’s picture

btw Entities are could be statically cached in storage handler and I'm sure better to relay on its caching instead of internal property

Not sure I get this.

andypost’s picture

Issue tags: +needs profiling
StatusFileSize
new4.92 KB
new94.08 KB

I mean kind of it, we already using static cache for user roles, so caching of formats also makes sense
I see no reason to abuse cache with already cached config entities (only sorting of formats could be moved to storage handler)

Status: Needs review » Needs work

The last submitted patch, 50: 2536594-50.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

andypost’s picture

Status: Needs work » Needs review
StatusFileSize
new13.11 KB
new92.45 KB

A bit of clean-up

Status: Needs review » Needs work

The last submitted patch, 52: 2536594-52.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

claudiu.cristea’s picture

+++ b/core/modules/filter/src/FilterFormatRepository.php
@@ -0,0 +1,136 @@
+    $formats = $this->storage->loadByProperties(['status' => TRUE]);

I see your point, but this is a performance regression compared to #47, as ::loadByProperties() is doing a real query against the DB on each ::getAllFormats() call. So, it's not only sorting of formats that occurs every time.

andypost’s picture

Just checked \Drupal\Core\Entity\EntityStorageBase::loadByProperties() and worried as well(

Then I think we should always use loadMultiple() & filter/sort in repository method but makes sense to test & I sure there should not be big diff in performance

claudiu.cristea’s picture

Status: Needs work » Needs review
StatusFileSize
new14.06 KB
new14.06 KB

Then I think we should always use loadMultiple() & filter/sort ...

Yep, I fully agree. better than having another caching layer.

... but makes sense to test & I sure there should not be big diff in performance

Given that there are only few text formats, usually fewer than 10 I don't know if it make sense to benchmark.

  1. +++ b/core/includes/bootstrap.inc
    @@ -950,6 +950,12 @@ function &drupal_static($name, $default_value = NULL, $reset = FALSE) {
    +      @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);
    
    +++ b/core/modules/filter/filter.module
    @@ -90,50 +89,36 @@ function filter_theme() {
    + * @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.
    ...
    +  @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);
    ...
    + * @deprecated in Drupal 8.8.0 and will be removed before Drupal 9.0.0. Use the
    + *   'filter.format_repository' service with ::resetFormats() method.
    ...
    +  @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);
    
    @@ -144,15 +129,15 @@ function filter_formats_reset() {
    + * @deprecated in Drupal 8.8.0 and will be removed before Drupal 9.0.0. Use the
    + *   \Drupal\filter\FilterFormatInterface::getRoles() method.
    ...
    +  @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);
    
    @@ -164,16 +149,15 @@ function filter_get_roles_by_format(FilterFormatInterface $format) {
    + * @deprecated in Drupal 8.8.0 and will be removed before Drupal 9.0.0. Use the
    + *   'filter.format_repository' service with ::getFormatsByRole() method.
    ...
    +  @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);
    
    @@ -199,17 +183,14 @@ function filter_get_formats_by_role($rid) {
    + * @deprecated in Drupal 8.8.0 and will be removed before Drupal 9.0.0. Use the
    + *   'filter.format_repository' service with ::getDefaultFormat() method.
    ...
    +  @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);
    
    @@ -238,17 +219,16 @@ function filter_default_format(AccountInterface $account = NULL) {
    + * @deprecated in Drupal 8.8.0 and will be removed before Drupal 9.0.0. Use the
    + *   'filter.format_repository' service with ::getFallbackFormatId()
    + *   method.
    ...
    +  @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);
    
    +++ b/core/modules/filter/src/FilterFormatListBuilder.php
    @@ -48,12 +55,19 @@ class FilterFormatListBuilder extends DraggableListBuilder {
    +      @trigger_error('The $format_repository parameter will become mandatory before Drupal 9.0.0. See https://www.drupal.org/node/3035368.', E_USER_DEPRECATED);
    

    Use the standard deprecation messages.

  2. +++ b/core/modules/filter/src/FilterFormatRepository.php
    @@ -0,0 +1,136 @@
    +    $this->storage = $entity_type_manager->getStorage('filter_format');
    

    We should not do this in constructor. I hit an edge case, see https://www.drupal.org/project/drupal/issues/2863986#comment-12899598. Let's revert this

I also noticed that some tests are doing a useless cache clearing.

The failing test still needs some investigation.

claudiu.cristea’s picture

StatusFileSize
new92.44 KB

Sorry, the patch from #56 was wrong. Here's the correct version. The interdiff is correct.

Status: Needs review » Needs work

The last submitted patch, 57: 2536594-57.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

ridhimaabrol24’s picture

Status: Needs work » Needs review
StatusFileSize
new92.72 KB

Reroll for 9.1.x and trying to fix test cases.

ridhimaabrol24’s picture

StatusFileSize
new92.72 KB
new1.02 KB

Fixing PHP lint error in #61

Status: Needs review » Needs work

The last submitted patch, 62: 2536594-62.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

ridhimaabrol24’s picture

Status: Needs work » Needs review
StatusFileSize
new93.94 KB
new2.66 KB

Fixing test cases.

Status: Needs review » Needs work

The last submitted patch, 64: 2536594-64.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

ridhimaabrol24’s picture

Status: Needs work » Needs review
StatusFileSize
new94.14 KB
new1.58 KB

Fixing failed test cases. Also regarding #54, loadbyproperties() has been used in several repository methods in core.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

berdir’s picture

Status: Needs review » Needs work
  1. +++ b/core/modules/filter/src/FilterFormatRepository.php
    @@ -0,0 +1,141 @@
    +   * {@inheritdoc}
    ...
    +  public function getAllFormats() {
    +    $formats = $this->storage->loadByProperties(['status' => TRUE]);
    +    uasort($formats, [$this->storage->getEntityType()->getClass(), 'sort']);
    +    return $formats;
    

    We seem to be losing both static and persistent caching here.

    I kinda get the persistent cache, but note that loadByProperties() is *not* cached and is pretty slow. We could add a lookup_keys for status to FilterFormat as well, that would help a bit, but it's still a database query. And that requires an upgrade path too. I don't think removing the caching here is a good idea.

    I see that this was discussed before, but even a loadMultiple() is still an extra query. Every time. See \Drupal\Core\Config\Entity\ConfigEntityStorage::doLoadMultiple(). We cache the list of all config entities of a given type.

  2. +++ b/core/modules/filter/src/FilterFormatRepository.php
    @@ -0,0 +1,141 @@
    +   */
    +  public function resetFormats() {
    +    $this->entityTypeManager->getStorage('filter_format')->resetCache();
    +    $this->formatsByUser = [];
    

    this on the other hand seems pointless. All actual changes to the filter formats already save them and imply invalidating the entity cache. And any change that does not change the format but e.g. changes user/role permissions, this is pointless.

  3. +++ b/core/modules/filter/src/Plugin/DataType/FilterFormat.php
    @@ -46,7 +46,7 @@ public function getSettableOptions(AccountInterface $account = NULL) {
         // @todo: Avoid calling functions but move to injected dependencies.
         return array_map(function ($format) {
           return $format->label();
    -    }, filter_formats($account));
    +    }, \Drupal::service('filter.format_repository')->getFormatsForAccount($account));
    

    the array map thing happens quite often, we could add a method for that.

  4. +++ b/core/modules/filter/src/ProxyClass/FilterFormatRepository.php
    @@ -0,0 +1,120 @@
    +<?php
    +// @codingStandardsIgnoreFile
    +
    +/**
    + * This file was generated via php core/scripts/generate-proxy-class.php 'Drupal\filter\FilterFormatRepository' "core/modules/filter/src".
    + */
    +
    +namespace Drupal\filter\ProxyClass {
    +
    

    interesting, where are we injecting it in the critical path but might not actually use it? The proxy actually adds overhead and it's only worth doing if we are saving calls. What you want to do instead IMHO is make sure that you don't do any extra work in the constructor, specifically instantiating the entity storage.

  5. +++ b/core/modules/views/tests/src/Functional/Plugin/DisplayFeedTest.php
    +++ b/core/modules/views/tests/src/Functional/Plugin/DisplayFeedTest.php
    @@ -58,7 +58,7 @@ public function testFeedOutput() {
    
    @@ -58,7 +58,7 @@ public function testFeedOutput() {
           'body' => [
             0 => [
               'value' => 'A paragraph',
    -          'format' => filter_default_format(),
    +          'format' => \Drupal::service('filter.format_repository')->getDefaultFormat()->id(),
             ],
    

    this seems like an old method that no longer exists like this, used quite a lot.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

claudiu.cristea’s picture

Assigned: Unassigned » claudiu.cristea

Restarted by converting #66 into a MR. I didn't make any changes, just verbatim conversion to begin with

claudiu.cristea’s picture

Issue summary: View changes
Issue tags: -needs profiling
  • Updated the CR
  • Updated the IS
  • Addressed remarks from #69
  • As we are back to static and persistent caching I'm also removing the "needs profiling" tag
claudiu.cristea’s picture

Assigned: claudiu.cristea » Unassigned
Status: Needs work » Needs review

This is ready for review

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.

claudiu.cristea’s picture

Applied @berdir's suggestion

berdir’s picture

Status: Needs review » Needs work

Another review posted. I'm open to discuss this and get feedback from others about things like the deprecation version. And know that the service name would be a very tedious change to update due to uses and so on.

claudiu.cristea’s picture

Status: Needs work » Needs review

Addressed the remarks. Back to "Needs review"

claudiu.cristea’s picture

Issue summary: View changes

Updated IS & CR

berdir’s picture

Status: Needs review » Needs work

Hopefully really the last review iteration...

claudiu.cristea’s picture

Status: Needs work » Needs review

Thank you. I've addressed the latest remarks.

claudiu.cristea’s picture

there's also this second plugin here.

Yes, I saw that before but finally I forgot to change.

Fixed latest change requests. Ready for review again

berdir’s picture

Status: Needs review » Reviewed & tested by the community

Thanks, I think this is ready.

IMHO the introduction of the repository service makes sense here, the methods are not trivial due to caching and so on. In regards to performance, I was wondering a bit, because I don't think any of these calls really are in the critical path, but I think it makes sense to essentially keep the level of caching that we have here for now, the we don't need to discuss that further. What's really neat is that the introduction of cache tags for that caches means that we can remove a lot of explicit cache invalidation and it makes it much easier to remove the caching if we consider it to no longer be necessary in the future.

As a follow-up, I'd like to explore to add a general persistent cache for loadMultiple() without ids for config entities, it's a fairly common thing for them and would likely allow us to remove the custom caching here for this. Possibly combined with the idea in #3551948: Document that EntityStorageInterface::loadMultiple may bypass caching, but likely cache first, refactoring and deprecations later. That certainly would allow us to drop this extra cache, because we essentially add a cache for the wildcard config query + the format config entity load, which is in fast chained config cache, which would be faster than this.

We did DI where we could with BC, most changes are in tests.

wim leers’s picture

Issue tags: +blocker

Just postponed #2917817 on this: would be better to land this first.

claudiu.cristea changed the visibility of the branch recover-2536594 to hidden.

claudiu.cristea’s picture

Since RTBC, all commits were rerolls. MR !14343 is the one that counts

godotislate’s picture

Status: Reviewed & tested by the community » Needs work

Some minor comments on the MR.

I think it'd also be useful to have unit(?) tests to confirm that the caching in getAllFormats() and getFormatsForAccount() works and is invalidated as expected.

godotislate’s picture

Looks like the CR needs updating as well:

  • update the repository service ID
  • Add removal version for the filter* functions
  • Add note about constructor changes
  • Add note about the new method in FilterFormatInterface
claudiu.cristea’s picture

Update the CR according to #94

claudiu.cristea’s picture

Status: Needs work » Needs review

Addressed remarks except the testing of cache. I wonder if we still need that, in very rare cases we're doing that

nicxvan’s picture

Status: Needs review » Needs work

A couple of minor comments, I'm not sure how strongly @godotislate feels about the unit tests.

godotislate’s picture

If there's existing coverage, even implicit, for the caching behavior, then I think the tests aren't that necessary.

claudiu.cristea’s picture

Status: Needs work » Needs review

Ready for a new review

berdir’s picture

Status: Needs review » Needs work

> Ok, there's a lot of back and forth with these versions, each reviewer has different POV. My head is exploding

I think we're consistently on 11.4 for 13 now, which seems fine. not sure if we'd need to bother with the BC for drupal_static_reset() until D13, it's such a super edge case, but it also doesn't hurt to keep it.

> If there's existing coverage, even implicit, for the caching behavior, then I think the tests aren't that necessary.

We definitely have test coverage for the persistent caching invalidation, otherwise plenty of tests would fail that add new formats and then use them.

getFormatsForAccount() might not be explicitly covered, but I'm not even sure we need that memory caching there. This isn't in the critical path, I had a look at how often it's called, it's 2-3 times when editing a node (multiplied by number of text fields with a format). The only thing this really caches is getting the memory-cached filters and the array_filter() with the access check, which also is cached.

But we kind of thought that we want to avoid the discussion and decision on whether or not we need it and just keep it. Fairly limited complexity I think.

On other side, I just realized that we have a bug in the caching logic, see MR review. So maybe we should have more explicit test coverage, but with my suggested refactoring, there won't be much left to test and the problem can't really happen anymore.

claudiu.cristea’s picture

Status: Needs work » Needs review

Status:

  • Changed according the latest @berdir's suggestion. I hope I've correctly understood the proposed solution
  • Updated the CR

Ready for review

berdir’s picture

Status: Needs review » Reviewed & tested by the community

Thanks, yes, exactly like that. That is much easier.

I added a note to the CR that the reset calls are very likely not needed and can probably be removed.

I'll leave it to @godotislate to decide on whether or not the test coverage here is sufficient, I think it is ok now with the updated implementation. I'd rather open a follow-up to decide if we want to remove caching from getFormatsForAccount().

claudiu.cristea’s picture

Straight reroll after #3580662: Deprecate _filter_tips() has been merged

  • godotislate committed d65f0172 on main
    refactor: #2536594 Add a FilterFormatRepository providing methods to...

  • godotislate committed f7f8afdd on 11.x
    refactor: #2536594 Add a FilterFormatRepository providing methods to...
godotislate’s picture

Version: main » 11.x-dev
Status: Reviewed & tested by the community » Fixed

Thanks to everyone for their incredible patience to get this one over the line!

There were two minor merge conflicts in filter.module and FilterThemeHooks.php when backporting to 11.x, but these just involved the use statements. I manually resolved the conflicts.

Committed d65f017 and pushed to main and committed f7f8afd and pushed to 11.x. Thanks!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.