Problem/Motivation
Follow-up to #2830880: Warn site admins when composer dev dependencies are installed inside of docroot where we have a test that is a kernel test only because KernelTestBase makes REQUIREMENT_OK available to the system under test.
Let's move the REQUIREMENT_* family of constants to a loadable namespace.
@alexpott on #50 said:
I feel this is OO-ification for OO-ification's sake. We're only moving the constants so they can be autoloaded. But a proper redesign of the requirements system might end up with Requirement value objects that makes these constants redundant - imagine $requirement->isError() etc...
If what we want to solve autoloadability of constants there's another way. We could add core/constants.php to our autoloader in the files section and repeating myself from the other issue the advantages are
- there's no deprecation
- the constants become available to autoloaded code
- as constants.php grows it becomes a place to learn about all the core provided constants
The one downside is this approach is only available to core and not core modules/themes, or contrib or custom because they don't using composer to set up their autoloading. But I'm not sure that outweighs the advantages listed.
Proposed resolution
TBD.
Remaining tasks
Make a patch, or decide this is a Won't Fix.
User interface changes
API changes
Data model changes
| Comment | File | Size | Author |
|---|
Issue fork drupal-2909480
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
Comment #3
andypostRequirements class going to be added in #2908079: Move some of the bootstrap.inc PHP-related constants to \Drupal and deprecate the old versions
Comment #5
andypostbtw This constants already moved in #1987824: Convert system_php() to a new style controller
so here needs
- find a place for new constants (
REQUIREMENT_INFOis not inSystemManager) still think better to useRequirementsclass from #2908079: Move some of the bootstrap.inc PHP-related constants to \Drupal and deprecate the old versions- properly deprecate them
- replace usage
- file change record
- not sure about how to add deprecated tests for constants
Comment #6
andypostJust to make ball roll & check how much affected in tests
Comment #8
naveenvalechaCR drafted https://www.drupal.org/node/3047376
Also rerolled the patch for 8.8.x
Should we also replace the usage of the deprecated constants as part of this issue or will it be handled in follow-up?
Comment #9
volegerDeprecation should include replacement of usage.
Comment #10
naveenvalechaReplaced the usage of deprecated constants.
Comment #11
volegerThis two lines reached 80 chars limit.
Comment #12
volegerComment #13
mradcliffeAdding some tags to hopefully get more eyes on this today in seattle.
Comment #14
yogeshmpawarComment #15
yogeshmpawarRerolled the patch & comments addressed in #11.
Comment #16
naveenvalecha@yogeshmpawar
Thanks for rerolling. please provide the interdiff.
Comment #17
yogeshmpawar@naveenvalecha - your patch failed to apply on 8.8.x branch.
Comment #18
yogeshmpawar@naveenvalecha - Please find the attached interdiff file between #10 & #15.
Comment #19
yogeshmpawarComment #20
berdirsorry if I'm repeating a discussion that happened before.
I'm wondering if we still need the "Requirement severity --" prefix here. Seems pretty self-explaining, we are on the requirements class and the constant is prefixed with SEVERITY_..
In hook documentation/examples, we usually use the full namespace for classes, same for docs.
At the same time, repeating the constants here seems not that useful, especially since we duplicate the documentation with less information than on the class. I'm wondering if it would be sufficient to just say "One of the severity constants of the \Drupal\Core\Requirements class".
Comment #21
jhodgdon@berdir asked me to comment on his review in #20:
- I agree that we probably don't need to have "Requirement severity --" in documentation of a constant called Requirements::SEVERITY_* in a Requirements class. But maybe we could make the messages clearer, something like "Indicates an informational message from a requirements check" and "Indicates the requirement is satisfied"?
- It is true that all class mentions in documentation should have namespaces.
- I agree with the suggestion of not duplicating documentation too -- it makes it hard to maintain. So, "One of the severity constants of the \Drupal\Core\Requirements class" for the hook docs sounds good.... Or maybe "One of the SEVERITY_* constants from the \Drupal\Core\Requirements class" would be even clearer?
I also took a quick look at the patch in #15, and have a few other comments:
a) Make sure to use the namespace in docs in other spots in core/lib/Drupal/Core/Extension/module.api.php too
b)
Should be "requirements-related" (hyphenated).
c)
This seems like very weird code to me. Why is the Requirements class final, when it looks like this class really wants to extend it? Or should this class just use the constants from the other class and deprecate those class members? But maybe you discussed this already, I haven't read the other issue comments.
Comment #22
tatarbjComment #23
aardwolf commenteda) Make sure to use the namespace in docs in other spots in core/lib/Drupal/Core/Extension/module.api.php
Reviewed. I think it's ok.
b) Should be "requirements-related" (hyphenated).
Changed
c)Why is the Requirements class final
Any reason to extend this class?
Comment #24
aardwolf commentedSorry for uncompatible IDEA patch file. Reroll with clean diff.
Comment #25
aardwolf commentedFixed missing Requirements.php in patch file. Reroll.
Comment #27
yogeshmpawarAll looks good so setting back to Needs Review! Tests failure is not related (see #3055648: Frequent random fail in \Drupal\Tests\media_library\FunctionalJavascript\MediaLibraryTest).
Comment #28
volegerAt least
:or-would be better than--Also,
Requirement severitysounds weird. I thinkSeverity levelwill be more clear there. Because code reads exactly likeRequirements::SEVERITY_<level>Comment #29
yogeshmpawarComment #30
yogeshmpawarAddressed comment in #28 & added interdiff as well.
Comment #31
volegerTypically,
:used without blank space before the symbol.Comment #32
yogeshmpawarAddressed comment in #31 & added interdiff as well.
Comment #34
yogeshmpawarAll looks good so setting back to Needs Review! Tests failure is not related (see #3055648: Frequent random fail in \Drupal\Tests\media_library\FunctionalJavascript\MediaLibraryTest).
Comment #35
volegerLooks good to me. +1 for rtbc
Comment #36
jhodgdonIn core/lib/Drupal/Core/Extension/module.api.php ...
Technically, if you refer to a class in documentation, you are supposed to give its full namespace. So instead of
it should say \Drupal\Core\Requirements::SEVERITY_ERROR.
Similarly elsewhere in the patch. See
https://www.drupal.org/docs/develop/standards/api-documentation-and-comm...
for where this documentation standard is written down.
Comment #37
aardwolf commentedchanged.
Comment #38
aardwolf commentedReupload
Comment #39
aardwolf commentedReupload
Comment #40
jhodgdonThanks for the new patch!
A few notes:
a) When you make a new patch on an issue that already had a patch, please make an interdiff file. I made one this time (see attached). Here are instructions on how to make an interdiff:
https://www.drupal.org/documentation/git/interdiff
b) When you attach a patch, set the issue status to "Needs review". That will automatically launch a test (I assume you did one manually?) and alert reviewers that there is a patch to review.
c) Regarding the new patch, all documentation needs to wrap at under-80 character lines. Several of the lines you added are now quite a bit longer than 80 lines, so they need to be rewrapped. So, leaving the status at "Needs work".
As a note, when wrapping lines within a list, the wrapped section should be indented so that the text starts at the same place as the previous line. So it will look something like this (but with lines extending to as close to 80 characters as possible):
Comment #41
pingwin4egComment #42
pingwin4egLooks like the rest.install does not use requirements anymore. Removed it's changes from the patch. Fixed comments.
BTW, maybe we should make an interface instead of a final class? Sorry, if it's documented somewhere and I missed it.
Comment #43
pingwin4egComment #44
pingwin4egHere's the same as above, but using an interface. Just in case.
Comment #45
voleger+1 for the interface.
Still wondering... Should the SEVERITY be a part of the interface name? The Requirements name sounds generic and on the other hand RequirementsSeverity (or something similar) - more specific.
Comment #46
volegerOh, just ignore the #45 thoughts about naming. Anyway, this will be merged with other constants into a single Requirements class (regarding to #2908079: Move some of the bootstrap.inc PHP-related constants to \Drupal and deprecate the old versions) And regarding interface, that requires to follow the CS of the interface naming with suffix "Interface". So I don't think that it would look great.
Tested the #44 patch. It does not apply anymore. Reroll.
Comment #47
acbramley commentedRerolled and removed some changes to content_moderation.install and workspaces.install as those requirements were removed! Also added 1 that was missing from media.install. No interdiff due to the considerable difference in the reroll.
I've checked phpcs and manually checked all documentation added to ensure no lines are longer than 80 characters so this should be good to RTBC now!
EDIT: CR was drafted back in #8 https://www.drupal.org/node/3047376
Comment #48
kim.pepperLGTM!
Comment #49
jhodgdon+1. Docs look good.
Comment #50
alexpottIn #2908079: Move some of the bootstrap.inc PHP-related constants to \Drupal and deprecate the old versions I've pushed back on adding
\Drupal\Core\Requirementsbecause it's a very generic namespace that risks making core/lib/Drupal/Core a dumping ground for things that we don't know where to put.I have a couple of thoughts on this issue.
I feel this is OO-ification for OO-ification's sake. We're only moving the constants so they can be autoloaded. But a proper redesign of the requirements system might end up with Requirement value objects that makes these constants redundant - imagine
$requirement->isError()etc...If what we want to solve autoloadability of constants there's another way. We could add core/constants.php to our autoloader in the files section and repeating myself from the other issue the advantages are
The one downside is this approach is only available to core and not core modules/themes, or contrib or custom because they don't using composer to set up their autoloading. But I'm not sure that outweighs the advantages listed.
Comment #52
mradcliffeI'm adding the Needs issue summary update tag so that the issue summary includes the different approaches suggested by @alexpott in comment #50.
Comment #54
andypostComment #55
daffie commentedThe patch needs a reroll.
Comment #56
vsujeetkumar commentedRe-roll patch created for 9.1.x
Comment #57
vsujeetkumar commentedIgnore previous one, Please review this.
Comment #58
kim.pepper@vsujeetkumar You have some invalid PHP.
For local development, you can check for valid PHP on any files that are have been modified from the 9.1.x branch using the following handy snippet:
git diff 9.1.x --name-only --diff-filter=AM | grep 'php' | xargs -n1 -P8 php -lComment #59
vsujeetkumar commentedFixed php syntax issue, Please review.
Comment #61
acbramley commented@vsujeetkumar it doesn't look like #59 is a reroll of #47?
Comment #62
acbramley commentedThis message is now wrong. I believe it should be "deprecated in 9.1.0 and removed in 10.0.0"? I could be wrong though...
Comment #63
kim.pepperSee https://www.drupal.org/core/deprecation#how-method
Comment #64
kishor_kolekar commentedComment #65
kishor_kolekar commentedComment #66
jhodgdonAlso alexpott's comment in #50 has still not been addressed, so there is not really a lot of point in rerolling this patch over and over until we figure out what we're actually doing.
Comment #67
jpatel657 commentedComment #68
jpatel657 commentedComment #69
andypostRepair status
Comment #70
volegerSymfony has its own requirement checker https://github.com/symfony/requirements-checker
What about to implement requirement checks based on the Symfony package?
Comment #71
andypostRe #70 this class looks outdated https://github.com/symfony/requirements-checker/blob/master/src/SymfonyR...
Moreover it will need to override more then it provides
Comment #72
ravi.shankar commentedRemoved needs reroll tag.
Comment #74
jhodgdonGiven comment #50, this is not a Novice task. Also updating issue summary with note from #50.
Comment #79
andypostNowadays idea of discovery
Requirementobjects could use attributes to define title, value and description.Other similar kind of checks/tasks install system has, so approach from #50 sounds viable
it could be enum but it actually used only to group requirements
Comment #80
volegerSeems like we have an issue that already has some work done in that way #2909472: Add value objects to represent the return of hook_requirements
Comment #81
andypostLooks yep!
Comment #84
nicxvan commentedI am going to work on this because we need these constants for hook_update_requirements and hook_runtime_requirements.
Since these classes are used in core, contrib, and custom, I think this disqualifies the constants.php approach.
However, we don't actually have to deprecate these here, I think we can do that when we deprecate hook_requirements, for now we can just create the new classes and just use them as we convert hooks.
Comment #85
andypostDeprecation suppose removal of the usage, 240LOC surely needs chunking
Comment #86
nicxvan commentedYes, I wouldn't create the deprecation here, just create the new landing place for constants and the new constants we need.
I wonder if there is a way to have both.
E,g. something like
/Drupal/Core/Constants
That is where the constants live, you can use it if you need it.
Maybe it makes sense to auto load it so they are available everywhere that uses autoloading.
Comment #87
nicxvan commentedI am not going to work on this at the moment, I think @berdir found a clean workaround, I think my comments about constants.php are still valid.
Comment #88
volegerComment #89
dwwI keep adding
@todocomments to core MRs with@seepointing here. We really need a better solution than manually includinginstall.inc, or worse, usingloadInclude($module, 'install')to get it to happen magically. 😂Comment #90
kim.pepperI'm working on rebasing this. Now most of the hooks are converted to OOP we can see what is left over.Oops commented on wrong issue. I'm actually working on rebasing #3410938: Create enums for RequirementSeverity and deprecate drupal_requirements_severity() constants
Comment #91
kim.pepperComment #92
kim.pepperShould we close this issue in favour of #3410938: Create enums for RequirementSeverity and deprecate drupal_requirements_severity() constants ?
Comment #93
kim.pepperI think this can be closed as #3410938: Create enums for RequirementSeverity and deprecate drupal_requirements_severity() constants went in which deprecates the REQUIREMENT_* constants.
Comment #94
andypostthank you!