Problem/Motivation
See referenced issues. Module-exist checks have been put in place in multiple core components that reference other core components in order to prevent a PHP exception when the referenced component is not enabled/installed. In some cases, the inline module exists checks make the code less readable.
Proposed resolution
The results of some of those inline checks can be moved into local variables in order to make the code more readable.
See contact_help() for an example of how to deal with this.
$block_page = \Drupal::moduleHandler()->moduleExists('block') ? \Drupal::url('block.admin_display') : '#';
Above line is an example of moving the inline check to a local variable.
Remaining tasks
Identify and replace inline module-exists checks with local variable equivalents where it will improve readability.
User interface changes
None
API changes
None
Comment | File | Size | Author |
---|---|---|---|
#9 | refactor_certain_inline-2492505-9.patch | 73.27 KB | umarzaffer |
#9 | interdiff-2492505-6-9.txt | 1.44 KB | umarzaffer |
#6 | refactor_certain_inline-2492505-6.patch | 74.85 KB | opratr |
Comments
Comment #1
opratr CreditAttribution: opratr as a volunteer commentedWorking on new patch now.
Comment #2
opratr CreditAttribution: opratr as a volunteer commentedComment #3
opratr CreditAttribution: opratr as a volunteer commentedComment #4
opratr CreditAttribution: opratr as a volunteer commentedComment #6
opratr CreditAttribution: opratr as a volunteer commentedComment #7
jhodgdonThis is mostly great! I think we should make sure to do a manual test of all the changed help and other pages before we mark this RTBC and commit it, to make sure all the links are working.
A few comments, and one thing to fix:
Since $block_page is already needed in two places in this same function, how about defining the variable outside the case statement, rather than doing it twice, one in each case?
Well, I guess that would be marginally less efficient for the cases that don't need it. So, either way. For better maintainability and because I think the efficiency hit is very small (and I hate copy/paste of code in general), I would be in favor of moving it outside the switch, but we could go either way.
This looks suspicious, but I verified that $field_ui_url is not being used anywhere, so it's fine.
In this file, we should not be making this change.
This is the sample function body for the hook_help() hook, and the example it's using is for the Block module, so we do not need to check whether Block is enabled here.
Comment #8
opratr CreditAttribution: opratr as a volunteer commentedThanks for the review jhodgdon!
Response to your comments:
Comment #9
umarzaffer CreditAttribution: umarzaffer at Srijan | A Material+ Company commentedHave made changes as per #7.3 and manually tested the help pages. Everything looks good to me.
Comment #10
opratr CreditAttribution: opratr as a volunteer commented@umarzaffer Thanks for the patch!
Next time, please leave a note on the issue if you decide to work on a patch that is being actively worked on, especially if the issue is assigned to someone. In this case it was only a 5 minute fix, but on other issues it could mean hours of wasted work for someone that doesn't know that you're performing duplicate work.
Comment #11
umarzaffer CreditAttribution: umarzaffer at Srijan | A Material+ Company commentedApologies @opratr. I realized that a bit late and in fact sent you an apology message as well. Never meant to work on an issue assigned to someone. Was a miss from my side. All in good faith!
Comment #12
jhodgdonGreat, meant in good faith I'm sure. We all have to learn the procedures at some point. :) Anyway, the manual testing is much appreciated @umarzaffer, and we needed a new patch one way or another. Thanks for the gentle handling of the problem @opratr.
One way or another, the new patch looks good. Thanks!
Comment #13
opratr CreditAttribution: opratr as a volunteer commentedComment #14
opratr CreditAttribution: opratr as a volunteer commentedNo worries @umarzaffer! Got your message. No harm done. Thank you. :)
Comment #17
jhodgdonBack to previous status after green retest.
Comment #18
xjmThanks everyone for your work here!
My first reaction to this issue is that it needs a beta evaluation and the case for making the change during the beta is not clear. See the allowed beta changes policy. The patch is not disruptive for contrib or existing sites, but it is the type of patch that needs frequent rerolls, takes disproportionate time to review, and may introduce the need for non-trivial rerolls in other patches. Furthermore, even if there were none of this disruption, any normal task with no prioritized changes should be postponed unless there is a special circumstance.
Leaving aside my first point and looking at the patch:
We're repeating this line a lot (maybe 26 times or so based on the diffstat of this patch?). That would suggest to me that we should refactor this into a method (or a function in
help.module
even). That said though...I do not think linking to
#
is the correct behavior. A link that basically does nothing is a usability and accessibility problem. It is also not semantic for a resource that does not exist. (See my comment in #2498675-5: Linking to a non-existent route should not throw an exception.)I recognize for point 3 is not introduced by this patch. However, it would be reason to mark this issue wontfix, and we could instead improve this as a part of fixing that bug.
Comment #19
xjmOh, I forgot to mention that I discussed this with @alexpott as well.
I think that either the entire sentence should be conditionally displayed depending on whether or not the module is available, or the help text should be written in such a way that it's relevant whether or not the module is enabled (and possibly even informs you if the module is not available). @alexpott preferred the second option.
Another issue though is that even if the module is enabled, the user might not have permission to access the linked resource. I believe in some places we do a permission check and add the link or paragraph conditionally based on that as well (or we have in the past). At least, there have been conditionals like this in
hook_help()
implementations for sure.Comment #20
jhodgdonWe *want* the sentence to be there, actually, because it would tell people "You could enable this other module to get this functionality". I agree linking to # is not ideal.
Probably then ideally what we want to do is make the substitution into the t() function either be
<a href="...">Block list page</a>
or justBlock list page
. However I think this would be very difficult for translators if not impossible.So I think we should leave things as they are.
Comment #21
DuaelFrRemoving the Novice tag as this issue is lacking a consensus.
https://www.drupal.org/core-mentoring/novice-tasks#avoid