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
Deprecate all 6 of these functions, add \Drupal\filter\FilterFormatRepositoryInterface (\Drupal::service('filter.filter_format_repository')
) to replace them
Remaining tasks
N/A
User interface changes
N/A
API changes
N/A
Data model changes
N/A
Comment | File | Size | Author |
---|---|---|---|
#66 | interdiff_64-66.txt | 1.58 KB | ridhimaabrol24 |
#66 | 2536594-66.patch | 94.14 KB | ridhimaabrol24 |
#64 | interdiff_62-64.txt | 2.66 KB | ridhimaabrol24 |
#64 | 2536594-64.patch | 93.94 KB | ridhimaabrol24 |
#62 | interdiff_61-62.txt | 1.02 KB | ridhimaabrol24 |
Comments
Comment #1
tim.plunkettComment #3
tim.plunkettRan
php core/scripts/generate-proxy-class.php '\Drupal\filter\FilterFormatRepository' "core/modules/filter/src"
to fix thatComment #5
tim.plunkettYou've gotta be kidding me. Why the hell is that not valid!?
Comment #6
dawehnerIt is great to do those things, but I kinda doubt this will be able to land in 8.0.x
Define what means allowed
Any reason for gets vs. returns?
Did you considered mocking using prophecy? You should see the error messages created by prophecy, its from another universe
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
Comment #7
tim.plunkett1) Rewritten
2) Returns was c/p, changed all to Gets
3) Tried it out. Thanks for the pointers
4) Fair point!
Comment #8
dawehnerWhat about using ::class and get autocompletion?
Comment #9
tim.plunkettI 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?
Comment #10
dawehnerSometimes along this lines ...
Comment #11
tim.plunkettOh cool, importing those really shows you how many things you depend on.
@dawehner++
Comment #12
Mile23Really like the
Interface::class
pattern. :-)I don't suppose there's an easy way to do a test-only patch here.
The patch in #11 still applies, but there's no
FilterFormatRepositoryInterface
anymore.Comment #13
Mile23Hey, you know what?
git diff --name-only
won't tell you files *added* by the patch. :-)Comment #14
Mile23My proxy-fu is no good, so I can't review that. Coding standards:
Needs a return comment.
Comment #22
claudiu.cristeaAdded CR. Rerolled, refreshed the code, added proper deprecations.
Comment #23
claudiu.cristeaAdding #1577902: [META] Remove all usages of drupal_static() & drupal_static_reset() as related because this remove usages of
drupal_static()
anddrupal_static_reset()
.Comment #25
claudiu.cristeaReplaced all usages of deprecated functions.
Comment #27
claudiu.cristeaThe patch from #25 was wrong. Republishing.
Comment #29
claudiu.cristeaOuch, an accidental edit.
Comment #30
claudiu.cristea::getDefaultFormat() was not properly used.
Comment #32
claudiu.cristeaMore fixes.
Comment #35
claudiu.cristeaFixing coding standards.
Comment #37
claudiu.cristeaLast fix.
Comment #38
andypostwhy not just filter.format_repository?
Comment #39
claudiu.cristeaI would say, better
filter.format_repository
. Because the service ID is always namespaced under the module’s name, which in this case isfilter.*
EDIT: @andypost, initially I misread your comment. In fact we're on the same page.
Comment #40
claudiu.cristeaFixed #38. Improved the service.
Comment #42
claudiu.cristeaAdded deprecation test. Fixed unit test failure.
Comment #44
claudiu.cristeaCoding standards.
Comment #46
claudiu.cristeaNot related & wrong changes. Undo.
Increase version: 8.7.0 -> 8.8.0. Update also the CR.
Exceeds 80 chars.
For BC reasons
$format_repository
should be optional and should trigger deprecation error if not passed.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')
.Comment #47
claudiu.cristeaFixed #46.
Comment #48
andypostbtw 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
Comment #49
claudiu.cristeaNot sure I get this.
Comment #50
andypostI 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)
Comment #52
andypostA bit of clean-up
Comment #54
claudiu.cristeaI 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.Comment #55
andypostJust 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 performanceComment #56
claudiu.cristeaYep, I fully agree. better than having another caching layer.
Given that there are only few text formats, usually fewer than 10 I don't know if it make sense to benchmark.
Use the standard deprecation messages.
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.
Comment #57
claudiu.cristeaSorry, the patch from #56 was wrong. Here's the correct version. The interdiff is correct.
Comment #61
ridhimaabrol24 CreditAttribution: ridhimaabrol24 at Srijan | A Material+ Company for Drupal India Association commentedReroll for 9.1.x and trying to fix test cases.
Comment #62
ridhimaabrol24 CreditAttribution: ridhimaabrol24 at Srijan | A Material+ Company for Drupal India Association commentedFixing PHP lint error in #61
Comment #64
ridhimaabrol24 CreditAttribution: ridhimaabrol24 at Srijan | A Material+ Company for Drupal India Association commentedFixing test cases.
Comment #66
ridhimaabrol24 CreditAttribution: ridhimaabrol24 at Srijan | A Material+ Company for Drupal India Association commentedFixing failed test cases. Also regarding #54, loadbyproperties() has been used in several repository methods in core.
Comment #69
BerdirWe 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.
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.
the array map thing happens quite often, we could add a method for that.
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.
this seems like an old method that no longer exists like this, used quite a lot.