Needs work
Project:
Drupal core
Version:
main
Component:
base system
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
8 Feb 2016 at 12:50 UTC
Updated:
16 Feb 2026 at 01:25 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
aleksipI'd be happy to create a patch if this is considered a viable idea.
Comment #3
star-szrThanks for this. For reference here is the issue where Attribute was first introduced: #1290694: Provide consistency for attributes and classes arrays provided by template_preprocess()
If we do go this route I am almost certain we'd need to keep \Drupal\Core\Template\Attribute and related classes as wrappers for backwards compatibility.
This could probably be categorized as a task but either way I think it would land in 8.1.x at the earliest so changing the version.
Comment #4
aleksipHere is a patch with wrapper classes.
I found 31 occurrences in core where
Attributeis used. Should they be changed too, or are the wrapper classes containing a deprecation notice sufficient?Comment #5
star-szrThanks, sending for bot review :)
I don't think these fit with our coding standards, I think we need to maybe
useas something else. https://www.drupal.org/node/1353118Comment #7
dawehnerIf we do that, we should also move
\Drupal\Tests\Core\Template\AttributeTesttocore/tests/Drupal/Tests/ComponentComment #8
star-szrDiscussed this with @alexpott a bit at the sprints at DrupalCon Asia.
He pointed out the Attribute currently has a dependency on \Drupal\Component\Utility\SafeMarkup which is deprecated, it would be really nice to remove that dependency before moving these classes to the Component namespace. So it would be great to get #2579691: Remove usages of SafeMarkup::isSafe() in before this.
Comment #9
aleksipThanks for the comments! While waiting for #2579691: Remove usages of SafeMarkup::isSafe() here is an updated patch. Will reroll when that issue lands.
Comment #11
aleksipAny suggestions on what should be done about
\Drupal\Core\Render\MarkupinAttributeTest, which causestestNoCoreInComponentTeststo fail?Comment #12
dawehner@aleksip
The way around that here is to implement a custom implementation of
MarkupInterfaceinside the file, so something like:Comment #13
aleksip@dawehner Thanks!
Here is a new patch with a
TestMarkupclass.Comment #14
aleksipChange to psr-4 as per #2337283-58: Add a composer.json file to every component. Should this issue be committed first so the Attribute component can be reviewed there?
Comment #15
star-szr#2579691: Remove usages of SafeMarkup::isSafe() is in so this needs a reroll now.
Comment #16
aleksipHere is the reroll.
Comment #18
star-szrThanks!
I think it might be nicer to prefix these with Component instead of Attribute. Similar to how this was done:
use Drupal\Component\Discovery\YamlDirectoryDiscovery as ComponentYamlDirectoryDiscovery;There needs to be a period at the end of the "Use [class]" part in these deprecation docs per https://www.drupal.org/node/1354#drupal (proper sentences), and looking at other examples I found in core.
Comment #19
aleksipNew patch with requested changes. Also bumped composer.json requirements to ~8.2.
Comment #20
aleksipComment #21
jhedstromThis is looking good.
However, given the efforts over in #2572635: Fix 'Drupal.Commenting.DocComment.LongFullStop' coding standard (and more generally #2571965: [meta] Fix PHP coding standards in core, stage 1, it would be nice for this change to go in without introducing new PHPCS issues. For instance:
To run PHPCS only on the changed/staged files:
git diff --name-only --cached | grep -v "core/tests/Drupal/Tests/Core/Template/AttributeTest.php" | xargs phpcs --standard=Drupal(Note the weird grep is to remove the old/renamed file--this method is modified from #1266444: DrupalCI should return failed for poor code style - php)
I don't think they all need to be fixed, but the ones regarding the empty doc comments should be fixed here while the context is still relevant, rather in the huge issue attempting to add doc comments where they are missing.
Comment #22
star-szrThat sounds reasonable to me, and I think we have time to fix those CS issues and get this into 8.2.x. Thanks @jhedstrom!
Comment #23
aleksipFixed most PHPCS issues. Of the only remaining errors
is an error itself (#2502837: Multiple code snippets, todos, and links are allowed in file doc blocks) and
for unlimited unnamed parameters I don't know what to do about.
Comment #24
jhedstromThanks @aleksip! I think all of the above concerns and issues have been addressed.
I also do not know, but it probably need not be addressed here. My main concern was that this patch not add new issues that would need to be dealt with later.
Comment #25
mile23Adding parent.
Comment #26
alexpottAlso all the @file blocks need to be removed.
Comment #27
kostyashupenkoReroll of #23
Comment #28
dawehner@kostyashupenko
#26 needs to be addressed.
Please use the git configuration from https://www.drupal.org/documentation/git/configure, see
. This allows you to create much smaller patches when files needs to be "just" moved
These are unrelated changes, probably caused by a bad reroll
Comment #29
kostyashupenkoOh, i am so sorry, my bad. There is really unrelated changes from another issue :) i've added too much unnecessary files
Comment #30
kostyashupenkoNew reroll of #23
Comment #31
kostyashupenkoComment #32
dawehner@kostyashupenko
Please read me full comment (hint, git config)
Comment #33
eric_a commentedI successfully applied #30 to 89712cf26fe49e446c49eba912d9961744243b9c (based on git log -- core/lib/Drupal/Core/Template/)
Here's the diff with renames = copies. Perhaps I'll do a re-roll later if you guys don't want to pursue this anymore.
And is moving decoupled stuff from core to component really a Feature request? How about a Task?
Comment #35
eric_a commentedRerolled #33.
Comment #36
eric_a commentedAddressed #26.
Comment #37
dawehnerThis is just a quick driveby review.
None of those changes are needed. Do you mind putting them into its own issue? By doing so, these test changes can land more quickly.
Comment #42
mile23Needs a re-roll.
We'll also need a follow-up to make sure there's a subtree split for this component.
Update the deprecation notice for 8.6.0.
Add @see for change notice.
Add a follow-up to add @trigger_error().
We don't use @file in tests any more.
Use []. There are other places where we have this usage.
We don't use @file any more in tests.
So basically: As per #37, do the file moves, add the @deprecation notices, run phpcbf, and that's the patch. Then we can do other cleanups in follow-ups.
Comment #43
mile23Comment #44
savkaviktor16@gmail.com commentedre-rolled
Comment #46
savkaviktor16@gmail.com commentedAdjusted patch by following #42's comment (1-3 but without adding @see)
Also adjusted composer.json in keeping with https://www.drupal.org/node/2769841
Comment #47
savkaviktor16@gmail.com commentedComment #49
yogeshmpawarUpdated patch with interdiff added.
Comment #53
aleksipCould not reroll the patch without conflicts.
#2572605: Make Drupal 8 optionally working with Twig 2, while keeping its dependency on Twig 1 added a simple
getClass()method toAttribute.However, a change made in #2600154: Update our Twig code to be ready for Twig 2.x to
AttributeTestseems problematic, as it adds a core dependency totestTwigAddRemoveClasses()in the form ofDrupal\Core\Template\Loader\StringLoader. So I did not apply this change to the reroll.Since it was not a clean reroll I also updated 8.6.0 references to 8.8.0 ones. Fingers crossed.
So now I guess
testTwigAddRemoveClasses()should be written in a Twig 2.0 compatible way, without introducing a core dependency?Comment #55
aleksipLooks like something also needs to be done to
assertArrayEquals()andrandomMachineName()calls inAttributeTest.Comment #56
Mixologicseems like
testTwigAddRemoveClasses()had unexpressed dependencies in it.$twig = new \Twig_Environment($loader);is assuming that everything in the Drupal\Core\Template namespace is available, including Twig_Environment.It seems to me like that test is just misplaced in the attribute class, and could live in core/tests/Drupal/Tests/Core/Template/TwigExtensionTest.php and could reference the attribute component.
Comment #57
aleksip@Mixologic Thanks! Moving
testTwigAddRemoveClasses()toTwigExtensionTestseems logical, and also means thatStringLoadercan then be used too. I have now updated the patch to do that.I have also added local implementations of
assertArrayEquals()andrandomMachineName()toAttributeTest. I wonder if these should be moved fromDrupal\Tests\UnitTestCaseto a new abstract base class extended by all component unit tests and alsoUnitTestCase? But that would be a case for another issue.Comment #58
aleksipD'oh, forgot to do a rebase before creating the patch, this one should have just the
Attributestuff.Comment #59
aleksipNew version of patch using
renames = copies.Comment #60
mile23I know I said we should follow-up to add @trigger_error() in #42, but let's just add it here. So that means adding @trigger_error() like in the docs: https://www.drupal.org/core/deprecation#how-class
Comment #61
aleksip@Mile23 Does this mean we need a change notice as well?
Comment #62
mile23Yes, we have to have a CR with a deprecation.
Comment #63
aleksipCreated a draft CR and added
@trigger_error()s.Comment #65
aleksipUh oh, so now do we need to change all the places in core that use the deprecated class to use the new class? I found 34 matches.
Comment #66
andypost@aleksip yes, no deprecated usages should be found
Comment #67
aleksipOk, have now replaced all references to
Drupal\Core\Template\AttributewithDrupal\Component\Attribute\Attribute.Comment #69
aleksipMissed a usage without the namespace.
Comment #70
MixologicI wonder how widespread useage of Drupal\Core\Template\Attribute is in contrib. I.e. how much of an impact is it going to be to update their modules. (some maintainers are complaining about the increased frequency of deprecations as we're getting closer to 8.8.0)
Comment #71
aleksipIs there a good way to find out? I am guessing that it is used quite a bit, and it is used in popular modules like Display Suite and Field Group for example.
I have always thought that
Attributeis one of the greatest things that came with Drupal 8. And that it is so useful, if not essential, that it (or something similar) should really be made a part of Twig core.Attributeis also used in projects like Pattern Lab. So while this change might be painful for contrib, I believe it would be a great service to the larger PHP/Twig community. I'm also confident that most contrib maintainers would see this in the same way.Comment #72
andypost@aleksip there's unofficial but working tool http://grep.xnddx.ru/
Comment #73
aleksip@andypost Thanks! Interesting tool. It doesn't seem to show the number of modules (which would be really useful!) but looks like
Drupal\Core\Template\Attributeis referenced in at least 484 files in contrib.I would actually say that this is a strong argument for making
Attributea Component, as it is widely used in both core and contrib, and clearly is a great solution for a common requirement (even beyond Drupal).Also, all that is required is to change one
useline, which is easy to do.Comment #74
brianperryOn the topic of determining impact in the contrib space, some of the D9 readiness tools might help here.
With this patch in place it should be possible to run drupal-check for deprecations and find references to Attribute in the results. If a few of us ran this on some relevant projects locally, I think we could come up with a decent representation of the most common projects that use it. We could even submit some issues proactively to notify the projects and/or provide patches.
Comment #75
jhedstromRegarding deprecations, this seems like the time to do it rather than wait for Drupal 10?
Here are the usages mentioned above. Note that many of these are not the
usestatement that would require updating, so less than 484 actual edits. Many of them are@seecomments.There are also some bugs in that search. For instance, it returns core file module files for the portfolio_theme project...
All this to say I think we should move forward with this, as module maintainers are going to need to do some work for Drupal 9 whether this goes in or not, and this seems like a pretty minor impact.
Comment #76
a-fro commented@aleksip thanks for your work on this. I'm thrilled with this change, and agree that it will be a valuable component to give back. We have a project that will use it immediately. Also, I agree that now is the time to do it and also that the impact will be minimal on contrib. @brianperry's point that getting the patch to land so that it will get reported by drupal-check seems key as well.
I reviewed the code to get my head wrapped around the changes, and it looks good to me. What is needed to get this to RTBC?
Comment #77
a-fro commentedMarking this as RTBC after following the patch review instructions. The patch applied cleanly against 8.8.x, commit 39bbdf40ac3599bf61db6ba392dafb9e3fdb11ef. Local testing of the site before and after the patch worked flawlessly.
Comment #78
aleksipThank you for your review @a-fro!
This is a public promise that if this gets committed I will start submitting patches to affected contrib modules right away. :)
Comment #79
mikelutzI agree that this move is probably beneficial. I think it might be a little late to try to deprecate the old classes for removal in D9.
Statistics on contrib use are one thing, but the attribute system is a primary way for preprocess functions to interact with templates, and as such is like to be extensively used in custom themes. I spot checked several of the projects I maintain, and each one of them reference this class in the custom theme's .theme file. While the required update is minor, it's very possible that it affects almost all medium to complex custom themes out there, which could be a very large number of sites. Likewise (and again, just my thoughts, with no real empirical evidence) I would think a common scenario would be a website with no real custom modules or code, but with a custom theme using this class. Such a site owner might not be looking at tests, and might think that as soon as their custom modules are D9 ready, then they can safely update.
We have already started discussing requiring all deprecations from here on out be scheduled for removal in Drupal 10 instead of 9, and I think this one would be particularly disruptive given the fact that no contrib will be able to update for it until Drupal 8.7 support drops, and the unknown usages in Custom themes (and again, I fully support the idea).
I think at minimum at this point we should change the scheduled removal to Drupal 10, and we should seriously consider postponing until the D9 branch opens so that we keep the current namespaces with no triggered errors in 8.9LTS
That all being said, I'm not a Release Manager, so I will leave RTBC, but I am tagging for RM review to make a final decision.
Comment #80
aleksipI understand the need to make moving to Drupal 9 as easy as possible, but then again isn't the point of major versions to make breaking changes? Drupal 8.9 support ends in November 2021, giving a lot of time for custom themes to be updated.
Comment #81
mile23We could deprecate now (in 8.8.0) for Drupal 10 without making a @trigger_error(), with a follow-up targeting D9.0.x to add the @trigger_error().
That way we get both the component now and the deprecation path later.
Comment #82
aleksip@Mile23 Sounds good to me! Will be happy to update the patch accordingly if that gets it in 8.8.0.
Comment #83
mile23Hey look what just got filed: #3073936: [policy, no patch] Policy for Drupal 10 deprecations
Comment #84
MixologicRight, I dont think anything prevents this from getting into 8.8.0, except just deciding whether its deprecated for 10 vs 9, and if 10, how.
re #81 funny you should say that. We were just discussing how to handle something like that, in a general way:
https://www.drupal.org/project/drupal/issues/3073936
Comment #85
aleksipGreat! Will be keeping an eye on that issue.
Comment #86
brianperryRegardless of when it is decided that this will land, I'd be happy to help with patches to contrib modules if dividing and conquering would be useful.
Comment #87
larowlanI can see the benefit of people being able to use this outside Drupal.
However, I don't see the benefit in deprecating the core classes.
If we go down that route, the patch is missing deprecation tests (tests that ensure the deprecation errors are triggered).
But I don't see the point - we can keep the classes in core that extend, they're a useful extension point if we need to provide Drupal-centric implementations again at some point. E.g. we have a PluginBase in component with a Drupal-centric one in core. I can't see any discussion above about why we added the deprecation - am I missing something?
This is good work, but I think we should work out if we need the deprecation at all, I'd vote we don't
Needs work for some nits, and either removing the deprecation or adding deprecation tests.
phpcs issue here: > 80
same here
while we're touching this, let's use the class constant
Comment #88
larowlanAnother reason against deprecation - it would be terrible to deprecate it and make people do all the work to remove it and then find we need an extension point and have to add it back
Comment #89
mile23Re: #88: It would be our component, too, so we could modify it there.
Comment #90
mikelutzWell, I think he meant if we needed an extension with some non component dependency
Comment #91
larowlanYeah, this is what I meant, sorry should have been clearer
Comment #92
mile23Right so the plan would be to have non-deprecated empty subclasses that extend the component classes, to reserve a class namespace in core in case we need to inject services or something?
Comment #93
aleksipIt is probably useful to provide some more background as to why many folks are interested in
Attributeas an independent component.Component-based theming has been gaining popularity for many years now, and one benefit from this approach is that theme components can be used on more than one platform. That is, the same Twig theme component could be used in Drupal, WordPress and Grav, for example. This is not just theoretical, real world examples already exist.
The Twig used in platform independent components should not use any platform specific code. While it is possible to write these components without using
Attribute, it would be a shame not to use it, asAttributeis not Drupal specific, and it is super useful.So my vote would be to deprecate, as I would not like
Attributeto be extended with Drupal specific features. I would say that this is a good case for composition over inheritance. Composition could be used if something Drupal specific is needed for processing in PHP, and plainAttributecomponent objects could then be passed to Twig.Comment #94
aleksipFixed the nits from #87.
Will work on deprecation tests or other required changes after a release manager decision.
Comment #95
xjmComment #96
Gnanasampandan Velmurgan commentedComment #97
aleksipThere seems to be a consensus that an Attribute Component can be added in 8.8.0. However, several people have expressed concerns regarding deprecation at this point, and there is even an option not to deprecate the current classes at all.
8.8.0 is getting closer and closer, and any deprecation option would require further work that would need to be reviewed. So maybe we could proceed with non-deprecated empty subclasses that extend the component classes, and decide on deprecation in a follow-up? Here is a patch that does only that.
Comment #98
larowlanI'm plus one on this approach, but we also need a release manager review, I will ping them
do we need an entry for this in core/composer.json too?
we don't do this anymore
Comment #99
xjmI agree with not deprecating the core copy prior to D9; it's constructed directly all over theme-layer code and would be a big disruption as deprecations go. I do think we should file a followup to decide whether to retain or deprecate the core wrapper. If we don't find a reason to have Drupal-specific implementation details, we should still consider deprecating it before D10. The docblock for the core wrapper could also link this followup in a
@todo.This was anappropriate documentation addition when we were deprecating the core component, but I think we should actually put the explanation of why we have this core subclass in the docblock. We don't normally substitute change records for API documentation.
Thanks everyone!
Comment #100
aleksip@larowlan and @xjm, thanks for your comments and reviews!
Here is a new patch with the changes requested. I have also created a follow-up issue, #3080648: Consider deprecating core Attribute classes, and updated the change record accordingly.
Comment #102
aleksipComment #103
shaal@aleksip it looks good!
After this patch becomes part of core. would it make #2623960: Improve the merge() method on Attribute objects easier to implement?
Comment #104
aleksip@shaal Thanks!
Should not make a big difference for #2623960: Improve the merge() method on Attribute objects, the current patch in that issue just has to be updated to modify the new Component classes. I'd be happy to do that once this gets committed. Looks like a great feature.
Comment #105
MixologicI don't have much to contribute other than from the testing/CI site of things, and ensuring that it gets subtree split out properly when it goes in. Seems to me that now that this does not introduce any new deprecations, that there aren't any real barriers to making this a component. That being said, I personally unfamiliar with Twig, or how this component would be used, so Im not a great resource to move it forward, but Im definitely +1 on making functionality like this available to the wider community.
Looks like the followup was filed as well, so Im removing the @deprecated and Needs Followup tags.
Comment #106
MixologicSince this is not altering any functionality, I suppose my lack of Twig knowledge shouldnt matter. I'll go ahead and RTBC this because it still has the "Needs release manager review" tag, and they generally focus on RTBC stuff first, IIRC.
Comment #107
catchLooks like xjm has already properly reviewed this (note, I haven't yet) and feedback was addressed, removing the tag.
Comment #108
markhalliwellOne small nit/request that has bugged me for years:
Rename the wrapper class
AttributetoAttributes(plural) since it is really a collection of attributes, not a singular standalone attribute.Comment #109
mikelutzHaving recently started a small personal SF4.3 project that requires a few templates, I now realize that I am quite strongly in favor of this, much more than I had realized, and am even wondering if there would be interest in packaging attributes up and getting it included as part of symfony/twig...
Comment #110
aleksipNice to see all the interest in this issue!
I get the point of renaming
AttributetoAttributes, but I don't have a strong opinion either way. I guess this would be the perfect time to change the names of the new component classes. Not the core wrapper classes though, as we would need to keep the current names to avoid breakage?Getting
Attributeinto Symfony/Twig would be fantastic, and by keeping the wrapper classes we could then easily change them to extend the new Symfony/Twig implementation. But as such an addition to Symfony/Twig is uncertain and would definitely take some time, hopefully we can still proceed with a Drupal component in 8.8 as a first step.Comment #111
xjmThanks for the updated patch! Just another bit we need to do for the docs:
We still need documentation explaining what it is, why it exists, etc. This doesn't pass the core documentation gate: https://www.drupal.org/core/gates#documentation
Normally we'd use
{@inheritdoc}here, but that doesn't work when we have to add additional information. (Ref: #1994890: Allow {@inheritdoc} and additional documentation) And in this case I think we need, at a minimum, explaining why this exists and how it is different from theDrupal\Componentversion. We can then add "See Drupal\Component\Attribute\Whatever for full documentation of this class." or such.I'm not super thrilled about the notion of making the new component Attributes instead of Attribute; that seems like an upgrade path WTF and annoyance waiting to happen.
Comment #112
xjmComment #113
aleksipHere is a patch with the requested documentation changes.
@xjm Do documentation changes like this require a formal review or could this be set straight to RTBC after tests have passed?
Comment #114
mikelutzAn interdiff would help me evaluate the changes and re-RTBC quickly. I'd make one, but I won't be able to until probably tomorrow.
Comment #115
aleksip@mikelutz Good thing that you asked for an interdiff, because when creating it I noticed that the two changes requested in #98 and added in #100 were for some reason dropped out of #113.
So here is a brand new patch with an interdiff of the last RTBC'd patch in #100.
Comment #116
catchfwiw I agree with duplicating and not deprecating for the moment.
I am not 100% convinced about leaving the Drupal\Core version in permanently 'just in case', we might never need to change it. So it seems worth opening a follow-up, against 9.x, to consider deprecating it for 10.x (or even later).
There are some core issues which may involve changes to the Attribute class such as #2567743: Add protocol filtering to the core Attribute component, #2531824: Attribute class to check safe strings before escaping (has tests), and a whole range of related issues like #2544110: XSS attribute filtering is inconsistent and strips valid attributes and others. These could (probably) be done in the Component, and not all of the issues touch Attribute itself anyway, but worth being aware of.
If we're not deprecating, we need some way to encourage people who are working with Drupal core not to use the Component version of the class, in case we ever do make a change to the Core version, because then they wouldn't get the bug fix. Should this just be docs in the Component referencing the Core version? Could we add a DrupalCS rule that looks for the use statement and tells you to use core instead?
Comment #117
aleksip@catch A follow-up issue has already been created (see #100) and it is referenced in the wrapper classes. In addition to the issues you mentioned there is at least the one mentioned in #103.
Comment #118
aleksipRegarding the follow-up and the possibility of adding core specific features, I am in favour of deprecating the core wrapper classes and if required using a composition over inheritance based approach. If we encourage people to use a core specific
Attributesubclass this could make theAttributecomponent less useful from an interoperability perspective.Comment #119
catchThanks for that follow-up and apologies for missing it had already been created - following the issue now.
Comment #120
alexpottThis is comment is similar to catch's (comes about after a discussion) but with a slightly different pov and a suggestion about how to resolve it.
One thing that confuses me about this change is that once it goes in what are we expecting new code to use? The component version - or the core version? Atm they are functionally equivalent but #87 down suggest that we might need to make changes to the core versions due to things like:
I've reviewed all of those and fortunately I think all of these can be fixed in the component version.
I've been pondering if an alternative would be to use class_alias() to alias the new component classes to the old core namespace. That way we wouldn't have additional classes lying around and we wouldn't have additional class inheritance. The question would then come how can we deprecate usage of the core namespace in future. For that I have two thoughts:
1. We just don't have too - a class_alias() can remain and it doesn't matter.
2. If we want to we could use static analysis ie PHPCS or PHPStan to do the deprecation.
So where would we add the class_alias() code? For me the best place to do this is in the autoloader. We can add a files section to core/composer.json - something like
And add core/aliases.php with something like
In order to get composer to rebuild the autoloader and .lock file correctly you'll need to
composer update drupal/corefrom the cli. And then we can remove all the core classes in favour of the component classes.Comment #121
aleksip@alexpott A good question and an interesting solution!
I'm just wondering, seems like it could cause confusion if there is code using an alias class that is not in the file system? Don't think I've ever used an alias class — does PhpStorm for example support alias classes so it will point to the real class?
Would it be possible to still go ahead with adding the component in 8.8 and then making a decision on the core classes in the follow-up issue? Maybe with some additional clarification in the change record and wrapper class documentation? "Drupal specific code should continue to use the core classes until a decision on deprecation has been made." Or something to that effect?
Comment #122
mikelutzI see three potential future scenarios:
This seems a bit sloppy, but is the most compelling argument for using class_alias. Given than this is a class that is highly likely to be used in custom themes, which is a large majority of sites, I would assume, and unlikely to have the same type of testing that catches deprecation errors, it might be worth avoiding the disruption of moving this class.
For this, obviously we can't use class_alias, although we could possibly go the class_alias route until such time as this potential situation actually occurs. The problem there is that if we say we don't care which one people use and then add something to core, then we are in trouble, since some people were using component. So I would say in this case it would have been better to start with separate class files that could have separate documentation pointing people to use core from åœw
In this case, we could do it with class_alias and some static analysis or classloader trickery, but it seems far easier to just do the extension and
document the docblock and trigger an error like normal.
Comment #123
alexpott@aleksip PHPStorm supports class_aliases - we them already in the testing system.
Comment #124
aleksipSince this has not yet been re-RTBCd, I took the opportunity to further clarify the documentation of the wrapper classes. I hope that the documentation now addresses the points made in the latest comments. I have also updated the draft change record accordingly.
The interdiff is for the last RTBCd patch, and the only changes made are to documentation.
Is it at this point realistic to get this in 8.8.0? I do hope so. If not, could this still go in 8.9.0, if nothing is being deprecated?
Comment #125
mikelutzLooks like the current feedback has been addressed, so I'll RTBC
Comment #128
aleksipUpdated
composer.jsonlicense string.Comment #129
alexpottHere's another approach to the class "copying" that doesn't rely on inheritance and ensure that the core and component classes stay the same without any effort because there are no core classes anymore. Also when we want to deprecate we can add @trigger_error to the core files and be done.
I think we should only consider deprecating the core attribute classes in Drupal 9 for Drupal 10.
Comment #130
aleksipTested the latest patch, works fine and the approach seems great.
Should the component
composer.jsonrequirements be updated, or are they somehow automagically updated for all components when a new major/minor version is released?Comment #131
alexpottThere's no magic component composer.json updating
Comment #132
aleksipIn that case here is a patch with an updated component
composer.json.Component versions seem to be updated in sync with core versions, even if nothing in them changes. And since component requirements are not updated, a 8.7.x component can require a 8.2.x component, for example. I don't see any real problem with this, but it just seems... interesting!
Comment #133
alexpottI think we need to target drupal 9 first. So
"php": ">=7.2.3". One thing that is interesting is the other components all have drupal stuff at ^8.8.Comment #134
aleksipLooks like all component Drupal dependencies were bumped to
^8.8in #3039611: Update core PHP dependencies for 8.8.x, and the PHP dependency was bumped to>=7.2.3in #3079791: Bump Drupal's minimum PHP version to 7.2 as soon as 9.0.x is branched (a higher version may be required later). It would seem logical to also bump component Drupal dependencies to^9.0for Drupal 9? Although I would argue that it would also be logical to have independent versioning for independent components.Anyway, back to this issue: should there be two patches, one for 8.9.0 and the other for 9.0.0? So the current patch would be for 8.9.0 and the other one for 9.0.0? Should the Drupal dependencies for the 9.0.0 patch be the same as for 8.9.0?
Comment #135
alexpott@aleksip let's focus on D9 for now as this is a new component and I agree that in ^9.0 make sense in that case. We should open an issue to bump the rest of the components.
I don't think there is any benefit in this landing in 8.9 as we're not going to deprecate the core classes in Drupal 8 anyway - so this would only happen in D9 and probably after sometime.
Comment #136
aleksip@alexpott Ok, I still had hopes for 8.9.0 since you left these in. So I guess they should be changed too?
But is it possible then to land this before 9.1? If not, the benefit for landing in 8.9 would be that otherwise this would have to wait for over a year, and might need extra work in the form of rerolls if changes are made to the classes. Also component Drupal versions should then probably need to be
^9.1too?Comment #137
aleksipDidn't mean to change the version.
Comment #138
alexpottIn #3090145-19: Ensure that mixing array and Attribute objects in theme rendering is managed properly @mondrake correctly points out that Attribute is badly named. It should be something like AttributeCollection or Attributes. Using a better name for the component version should be in-scope here.
Comment #139
xjmMore of a task than a feature, really.
Comment #143
mondrakeRerolled and moved to MR workflow.
Comment #144
mondrakeAttempted renaming as per #138.
Comment #146
mondrakeRebased on 9.3.x
Comment #147
mondrakeAdded typehints to new code where possible, and deprecation errors to the legacy code.
Comment #148
longwaveI think deprecating here is out of scope? We can still move to the core classes extending component (with no additional code), but #87 is a core committer giving a -1 to deprecation and #3080648: Consider deprecating core Attribute classes exists for further discussion of this.
One additional comment about dropping the single use of random in a test, I don't see why we need that.
Comment #149
mondrakeFixed the use of random.
Re #148 and #87 I learned we do not leave stuff in if it's only potential use. We implement when the need comes. So here keeping the deprecations and adding a silencer.
IMHO, either we move and deprecate, or we leave stuff as is and won't fix this.
Comment #150
longwaveOther than the deprecation decision this is ready to go, marking RTBC to get another round of core committer feedback. Noting that @catch was also -1 to deprecating in #116 but then @alexpott had other thoughts in #120 that I'm not sure we've fully explored, let's see what they think now.
Comment #151
mondrakeStill something to do. Apart from fails, deprecation tests.
Comment #152
mondrakeApart from the changes needed to
composer.lock, this is for review now.Comment #153
longwave@mondrake to fix the composer issue just run
composer update --lockfrom the top level directory and commit the change which should beComment #154
mondrakeThanks @longwave! One day I will learn this :)
Comment #155
longwaveTwo questions about backward compatibility, and still the problem of whether we deprecate or not to answer, but core committers can have the final say on that one.
Comment #156
mondrakeFor signature typehint BC, I think we must come to a decision on how to add typehints to existing code, #3050720: [Meta] Implement strict typing in existing code. An example could be #3217961: Prepare for Connection::select() signature to be fully typehinted in D10.
Comment #157
mondrakeFixed part of #155.
Comment #158
longwaveThanks - but do we need a deprecation test for that Settings change?
Comment #159
mondrakeAdded deprecation tests for:
AttributeBaseValue(tricky because we need to avoid autoloading of the class before the test starts)Attributeclass in$settings['twig_sandbox_allowed_classes'](extremely tricky because this was read in a constructor, and with PHPUnit mocking this is a disaster, had to refactor some parts of TwigSandboxPolicy to allow mockingSettings::get)Also, deprecation of the usage of the Attribute class in $settings['twig_sandbox_allowed_classes'] is probably not enough, that's OK for developers but sites may have this set in their settings.php, so we probably need a warning in the status report on top? Maybe I see now reasons for reluctance in deprecating these classes.
Comment #160
mondrakeRerolled.
Comment #161
mondrakeRerolled.
I guess this is D10 material now, where in any case return typehints would have to be solved for classes in HEAD.
Comment #162
mondrakeRerolled.
Comment #163
mondrakererolled
Comment #164
daffie commentedTestbot not happy.
Comment #165
daffie commentedThe deprecation window for D9.3 has passed.
Comment #167
neclimdulApplied the changes that should be needed to target 10.x
Comment #168
andypostCI failed somehow
Comment #169
daffie commentedComment #170
mondrakeThis is an issue where #3180042: Add baseline for deprecation testing would help a lot.
Comment #171
mondrakeComment #172
mondrakeRebased onto 10.1.x, will work on renaming classes to HtmlAttribute* as suggested in #3252386-148: Use PHP attributes instead of doctrine annotations.
Comment #173
mondrakeComment #174
mondrakeThis patch is raising the new component's PHPStan compliance level to 9. This requires excluding PHPCS checks on it because they are incompatible to most PHPStan L6+ fixes. Keeping the patch separate from the MR since I am aware this is too far fatching ATM.
Comment #175
mondrakeSpell check fixes.
Comment #176
mondrakeSorry.
Comment #178
mondrakeSome improvements in scope/visibility of properties and constructors, driven by PHPStan.
Comment #179
mondrakeComment #180
mondrakeApparently, using phpstan prefixed annotations for params and returns, we can get code compliant with PHPStan-9 AND pass current Drupal PHPCS checks.
So I did that in the MR.
Comment #181
mondrakerebased
Comment #182
catchThis issue is already compatible with #3344303: [policy, no patch] Decide on a namespace for PHP Attribute classes but just noting the decision over here.
Comment #183
catchRemoving the needs follow-up tag since that already exists per #100.
Comment #184
smustgrave commentedWasn't entirely sure how to best test this one.
I applied the MR and did some basic features like creating content, media, using the workflow, etc.
Nothing seemed to break but if there's a more targeted way let me know!
+1 from me but with a large feature maybe should get a few more (and real testing)
Comment #185
mile23I think the issue here is that we need some specialist information, such as whether the infrastructure is set up to add another packagist listing and whether the subtree split will work.
Back in the day, @Mixologic had that set up to happen smoothly, but since he's not at the DA any more, it unclear who to ask. Or at least I don't know who. :-)
Comment #186
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".
This does not mean that the patch needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #187
mondrakeMaybe after commit of #3358739: Update coder to 8.3.18 we can now go back to use standard
@paramand@returnannotations.Comment #188
mondrakeComment #189
mondrakeComment #190
smustgrave commentedThink this would be good to get in early for 10.2
Tried rebasing to see if the tests would run but seems to be an issue.
Comment #191
andypostI think we can close this one for less disruption
Comment #192
neclimdulComment #193
smustgrave commentedTest failure seems legit to issue.
Thanks for updating!
Comment #194
mondrakeRebased. Now phpstan-deprecation is triggering a load of errors. Shall we ignore/baseline them for the moment, or do we need to address them here? (The latter may significantly increase the size of the MR)
Comment #195
mondrakeRebased.
Comment #196
mondrakeIgnoring phpstan deprecation messages for the Attribute classes, per #194.
Comment #197
smustgrave commentedThink it needs a manual rebase as MR is showing unmergable.
Comment #198
neclimdulI looked at it a while back and its kinda a big lift to rebase this. Without some interest in committing its hard to justify that time. I think its worth that effort but doing it now, 3 or 4 more times before commit is a big waste of time.
Comment #199
mile23It seems like we need:
drupal/core-attributespackage.Then after that is sorted, we'd need to perform a re-roll, and can do the code review and changes.
With that in mind, adding 'needs subsystem maintainer review' since there's not really an 'ask ops' tag, and adding NRQI tag and asking in slack so maybe some maintainer can please affirm that it's worth the time to do.
Comment #200
mile23Asked just now on Slack, and @drumm says the GitHub split will happen automagically.
Comment #201
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".
This does not mean that the patch needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #204
luke.leberSelf-assigning for this weekend. This could be useful in a pet project.
Comment #206
luke.leberOkay, things have been re-rolled as much as possible until a blocker is resolved.
In
main, the\Drupal\Core\Template\Attribute::addClassmethod is very lenient in what's accepted...The issue fork tightens this up considerably through type hinting...
This represents a fairly significant backwards compatibility break that's causing existing tests to legitimately fail. I think this needs a framework manager's opinion on how to proceed: Does the new class relax the type hinting? My intuition is leaning toward "yes" FWIW.
Once someone chimes in, I'm happy to continue re-rolling things. It's going to get big and messy!
Comment #207
luke.leberComment #208
godotislateArgument type declaration changes are usually only done in new majors and can be prepared before that per https://www.drupal.org/about/core/policies/core-change-policies/how-to-d.... That would be kind of annoying to add in the brand new AttributeCollection class, though.
Comment #209
godotislateAnother note is that https://www.drupal.org/node/3509577 introduced an API to move classes, which maybe can be leveraged, though I haven't looked at the changes here closely.
One note is that it uses
class_aliasunder the hood, which has been found to failinstanceofchecks, because instanceof does not check aliases on loaded object.Comment #210
luke.leberComment #211
luke.leberThis is also another B/C break in that the new
\Drupal\Component\HtmlAttribute\HtmlAttributeValueBaseintroduces a new abstract method,\Drupal\Component\HtmlAttribute\HtmlAttributeValueBase::doGetValue()that would cause WSOD's for any extensions to the legacy\Drupal\Core\Template\AttributeValueBaseclass.To fully preserve B/C here, I think that a slight re-architecture to the new stack of component classes is required. The following makes sense to me on the surface: eliminating the new abstract method and using child constructors to further refine the types down through derived classes (perhaps in 14.0.0?).
Comment #213
luke.leberAlright, now I think there's a show-stopper for real in this effort. HEAD has a reference to
Drupal\Core\Serialization\Attribute\JsonSchema, thus making the original intent of this issue no longer possible. 😞Comment #215
nicxvan commentedCan components have interdependencies? If they can we could move the json schema one as well probably.
I'm not advocating for or against the move to components, but if that is allowed that seems like a way forward.