Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
#2083547: PSR-4: Putting it all together includes a change record for the 8.x-to-8.x change of adding PSR-4 support, but does not make the many other updates needed to existing change records and/or documentation.
See the Documentation page for PSR-4 in Drupal 8.
#2247287: Drop automatic PSR-0 support for modules PSR-0 support will also be removed.
Proposed resolution
Update existing change records about PSR-0 to also mention PSR-4 and include a reference to the relevant issue.
Check these:
https://drupal.org/list-changes/published/drupal?keywords_description=ps...
Updated Issue Summaries
- Completely rewrite or replace https://drupal.org/node/1320394.
- https://drupal.org/node/1938688: Might need to be re-written the title is a bit of an overstatement at this point
- https://drupal.org/node/1800686 (routing language is being updated in #2244777: Document all the menu changes (tasks, actions, contextual links, menu links) from 7 to 8 in the WSCCI change record)
- https://drupal.org/node/1827470
- https://drupal.org/node/1937056
- https://drupal.org/node/2076489
- https://drupal.org/node/2186583
- https://drupal.org/node/2189199
- https://drupal.org/node/2186931
Comment | File | Size | Author |
---|---|---|---|
#30 | one_replace_php.txt | 1.26 KB | chx |
Comments
Comment #2
webchickWe probably want to wait on this until we move all of the files around, because otherwise we're going to introduce docs changes which don't actually line up with what the code is doing.
Also unpublished a comment that was completely unconstructive.
Comment #3
webchickActually, I didn't seem to find a dedicated issue for moving the code, so re-using this one.
As discussed in #2083547: PSR-4: Putting it all together among the core maintainers, this will be one of the last, if not the last, beta blocker to get committed in order to minimize disruption to the rest of the queue, so postponed is still the proper status IMO.
Comment #4
larowlanSorry for the unconstructive comment - it was 'puke' for those wondering.
What I should have said/meant was 'I really feel sorry for the poor soul who has to go back and update the change records cause thats a thankless painful job'.
Comment #5
tstoecklerIn that case unassigning.
BTW, I went through and didn't find any shortcut change notices that reference classes.
Comment #6
xjm@tstoeckler already volunteered to do the change record task, and we need to do it now. Let's split the other off into a separate issue if we are postponing it.
Comment #7
xjmUpdated the summary. There seems to be some misunderstanding here. While the filepaths do not need to be updated until we actually change them, we do need to go back and update all the change records that refer to PSR-0 and all the documentation that refers to PSR-0 and update it for this addition and policy change. And we need to do that now.
Comment #8
tstoecklerWent throught the list in the OP:
https://drupal.org/node/1320394/revisions/view/6942253/7175509
https://drupal.org/node/1400186/revisions/view/6860673/7175519
https://drupal.org/node/1477046/revisions/view/2189324/7175527
https://drupal.org/node/1479568/revisions/view/2189348/7175531
https://drupal.org/node/1525776/revisions/view/2008636/7175533
https://drupal.org/node/1532250/revisions/view/2518172/7175535
https://drupal.org/node/1543796/revisions/view/2544968/7175549
https://drupal.org/node/1691614/revisions/view/2229376/7175551
https://drupal.org/node/1703490/revisions/view/2250070/7175563
https://drupal.org/node/1848268/revisions/view/2455818/7175565
https://drupal.org/node/1918778/revisions/view/2566058/7175569
https://drupal.org/node/1935708/revisions/view/2883887/7175573
Also searched for "lib/Drupal":
https://drupal.org/node/1796000/revisions/view/7072485/7175577
https://drupal.org/node/1805846/revisions/view/7072467/7175593
https://drupal.org/node/1806650/revisions/view/7030497/7175599
https://drupal.org/node/1818734/revisions/view/2891497/7175603
https://drupal.org/node/1909596/revisions/view/6673109/7175615
https://drupal.org/node/1911646/revisions/view/7019347/7175619
https://drupal.org/node/1853148/revisions/view/7168383/7175609
https://drupal.org/node/1957310/revisions/view/7056991/7175627
https://drupal.org/node/1961370/revisions/view/7019431/7175629
https://drupal.org/node/1969794/revisions/view/2883449/7175633
https://drupal.org/node/1993056/revisions/view/7019429/7175637
https://drupal.org/node/2003376/revisions/view/7019377/7175639
https://drupal.org/node/2012184/revisions/view/7011697/7175641
https://drupal.org/node/2015901/revisions/view/7019507/7175643
https://drupal.org/node/2020549/revisions/view/7161927/7175645
https://drupal.org/node/2026025/revisions/view/6791911/7175649
https://drupal.org/node/2064123/revisions/view/7072447/7175651
https://drupal.org/node/2072699/revisions/view/2814651/7175653
https://drupal.org/node/2119699/revisions/view/6892933/7175655
https://drupal.org/node/2186931/revisions/view/7019601/7175663
Searching for "tests/Drupal" didn't yield any results.
Also put a list of TBD change notices (after the big change) in the issue summary based on the later search.
So marking "needs review" for now. Maybe someone can find some search that I forgot, otherwise I think we should be done here, until the final move.
Comment #9
tstoecklerComment #10
xjmFantastic work. A few questions/comments.
https://drupal.org/node/1320394/revisions/view/6942253/7175509
We'll probably want to completely rewrite or replace this change record once we complete all this, but this is likely good enough for now.
https://drupal.org/node/1400186/revisions/view/6860673/7175519
This still has Plugin in the entity namespace; some other change record update missed that. :P
https://drupal.org/node/1477046/revisions/view/2189324/7175527
https://drupal.org/node/1479568/revisions/view/2189348/7175531
https://drupal.org/node/1525776/revisions/view/2008636/7175533
https://drupal.org/node/1703490/revisions/view/2250070/7175563
https://drupal.org/node/1848268/revisions/view/2455818/7175565
I think the above changes aren't correct because they refer to things in
\Drupal\Core
or\Drupal\Component
.https://drupal.org/node/1532250/revisions/view/2518172/7175535
Maybe this should say "class autoloading and the configuration system".
https://drupal.org/node/1918778/revisions/view/2566058/7175569
I have no idea about this one. Someone ask @Crell?
https://drupal.org/node/1691614/revisions/view/2229376/7175551
We can revert this one... in fact maybe if we'd been using PSR-4 (or if it had existed) we wouldn't have had to rename list.module to begin with? ;) Oh well.
Comment #11
xjmFor #10.
Comment #12
tstoecklerOK, in the order you posted them:
https://drupal.org/node/1400186/revisions/view/7175519/7177537
Thanks overlooked that!
Regarding Core/Component:
Classes there are now, too using a PSR-4 compatible, class-loader. They are just not registered to a subnamespace - like /core/modules/node/src is registered to \Drupal\node - instead /core/lib is registered to the top-level namespace directly*. This distinction is important - i.e. it is important to state that we are using PSR-4 everywhere - because of the difference when it comes to underscores. I.e. class names with underscores will not get picked up as namespaces changes, where they would have been before the PSR-4 patch.
So leaving those as is.
* This is not technically true, in fact /core/lib/Drupal/Component and /core/lib/Drupal/Core are registered to \Drupal\Component and \Drupal\Core respectively, but that's only due to performance. They *could* both be reigstered by simply registering /core/lib to the top-level namespace.
That's not true. The problem with the reserved words and list module is regarding the namespace and not the filename. The namespace would still have been
list
. Kept that one as is.Comment #13
xjm...Wow, glad I asked rather than just changing them myself. ...So PSR-4 means
mymodule/src/Namespace/
but alsocore/lib/Drupal/Core/Namespace/
? That's not confusing AT ALL. ;) And why is theDrupal/
subdirectory still there then? Wouldn't it becore/src/Core/
andcore/src/Component
? How is it not interpreted as belonging to\Drupal\Drupal\Core
etc.?And why did we keep
lib
for that if it's not PSR-0? How do I know to look incore/lib/Drupal/
instead ofcore/src/
other than having to read some obscure documentation?What does this mean for hypothetically sharing our components with other projects, if those use PSR-4? And what about core modules supposedly pulling in components from other projects?
In any case, can we instead update the new PSR-4 change record under the \Drupal\Core and \Drupal\Component section to clarify this?
Thanks @tstoeckler.
Comment #14
donquixote CreditAttribution: donquixote commentedHi.
This was on the table for months, and noone really complained. I would have liked to get more feedback, but that was it.
I made this decision mostly for technical reasons, because PSR-4 is given priority in the class loader (this was Jordi's idea), and because now if we ever want to do any discovery in core folders (for tests or plugins or other), we can use the same logic as for modules.
I'd say there is simply no big enough benefit to move this stuff around. The deep directories are a productivity issue for modules, but not so much for core. Besides, we have class Drupal, which is at the top level and would not have a place otherwise. I think if everything was in Drupal\\Core\\, whereas Component would be in vendor, then it would start to make sense to shorten this path. But in the current situation, no.
I think most people, before turning to documentation, will simply look in the existing file structure and accept it as is. Maybe also a look into composer.json. This does not tell you much about the why, but it does tell you all you need to start writing patches or custom modules.
Why would this be a problem?
If we really want to share components, we would first have to put them into separate directories. And once we are at that, we can turn around the folder structure so it becomes component/Xyz/src/Foo.php for class Drupal\Component\Xyz\Foo. But this is all hypothetical, and would require a separate discussion.
This is something we really want to have, but has nothing to do with PSR-0 or PSR-4 for modules. These external dependencies could use PSR-0 or PSR-4 themselves, we don't care.
And even if modules would still use PSR-0, I don't think that the (module dir)/lib/ folder would be an appropriate place for 3rd party code.
Comment #15
xjmThanks @donquixote and @tstoeckler. I filed #2252761: Core components are loaded with PSR-4 but in core/lib/Drupal/ for this discussion, because the actual change is rather different from what I understood it to be after hours and hours and hours discussing the PSR-4 change.
Meanwhile, postponing on #2247991: [May 27] Move all module code from …/lib/Drupal/… to …/src/… for PSR-4 for the remaining tasks @tstoeckler listed.
Comment #16
xjmComment #17
xjmComment #18
donquixote CreditAttribution: donquixote commentedDo we have an issue for documentation changes regarding PSR-4?
I want to suggest to make this the new central doc page for PSR-4:
https://drupal.org/node/2156625
This page has existed for a while, and I think it is quite useful.
Or do we have an alternative?
Comment #19
xjmThanks for the pointer @donquixote. I've updated the page (with @donquixote's help) and deprecated the old pages in favor of it.
Comment #20
xjmOther handbook pages that may need updates:
https://drupal.org/search/site/psr-0?f[0]=ss_meta_type%3Adocumentation
Comment #21
catchComment #22
catchComment #23
jhr CreditAttribution: jhr commentedI'm at DrupalCon Austin's sprints and working on moving this forward (irc: #drupal-contribute -- Yancy).
@tstoeckler: Can you comment on:
. We need to determine if the rewriting needs be on this issue or another.
Comment #24
jhr CreditAttribution: jhr commentedPSR-0 support will be dropped, which will affect some rewriting.
https://drupal.org/node/2247287
Comment #25
jhr CreditAttribution: jhr commentedI ran the faceted search for documents and am adding those documentation links. The ones that I commented just have a small section.
FYI:
I scraped the links from the search by using the FireFox's Dev Console ( JavaSript console). That way I get links and titles.
This finds all the links in the search results and echoes it to the console as plain text.
After that I did some RegEx search/replaces to remove extra spaces and characters in PHPStorm.
Comment #26
jhodgdonThanks! That is very useful!
One note: lib/Drupal still exists in core/lib/Drupal -- what doesn't exist any more is core/modules/foo/lib/Drupal/foo -- so I am not sure about your list in the issue summary? But at least those would be pages to check and see if they need updates. Added this note to the summary.
Comment #27
chx CreditAttribution: chx commentedI believe someone should spin up a drupal.org devsite and test the attached UPDATE commands on the drupal.org DB -- better than manual edit. Courtesy of
find core/modules -maxdepth 1 -type d | sed 's#core/modules/\(.*$\)#UPDATE node_revision SET body = REPLACE("/lib/Drupal/\1/", "/src/") WHERE vid IN (SELECT vid FROM node WHERE type = "changenotice");#' > /tmp/updates.txt|tail -n +2
There are only 1151 change notices on drupal.org so that UPDATE won't be horrible.
Comment #28
chx CreditAttribution: chx commentedSorry; left out a body.
Edit: also, someone could write a script that generates in an embedded-chained REPLACE and then one command to rule them all:
UPDATE node_revision SET body = REPLACE(REPLACE(body, "/lib/Drupal/editor/", "/src/"), "/lib/Drupal/syslog/", "/src/") WHERE vid IN (SELECT vid FROM node WHERE type = "changenotice");
Comment #29
chx CreditAttribution: chx commentedI attached the PHP that generates two semantically correct SQL UPDATE statements; they run on a D7 database (unlike the previous ones) but I can't vouch whether the REPLACE command is correct. That should be trivial to fix, tho.
Comment #30
chx CreditAttribution: chx commentedOne more.
Comment #31
mtiftComment #32
mtiftComment #33
mtiftThere doesn't appear to be anything PSR-0 related in https://drupal.org/node/2084727
Comment #34
mtiftComment #35
mtiftComment #36
mtiftComment #37
mtiftComment #38
mtiftComment #39
mtiftDiscussed with @xjm and decided that documentation updates should not be beta-blocking critical issues. All change records should be updated for PSR-4.
Opened #2281687: Update documentation for PSR-4 support
Comment #40
mtiftAssigning to @xjm for review
Comment #41
xjmI've reviewed all the updates, and everything looks correct. The followup issue also looks great. Awesome work everyone!
Comment #42
donquixote CreditAttribution: donquixote commentedI am adding links to the main documentation page for PSR-4 in Drupal 8 to a few issues and change notices where it seems relevant and has yet been missing.
People who google for "Drupal PSR-4" should either directly get the doc page, or if they land elsewhere, they should get to the doc page easily. So far this was not the case.