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.
See title.
Recommended solutions (from our issues wrap-up spreadsheet):
1) "Include javascript to check for valid path, and warn if invalid.
2) Discuss a “browse” interface alternative."
Comment | File | Size | Author |
---|---|---|---|
#85 | selecting_only_the-1164722-85.patch | 10.99 KB | siva_epari |
#79 | interdiff-76-79.txt | 5.63 KB | legolasbo |
#79 | block-invalid_path_feedback-1164722-79.patch | 10.96 KB | legolasbo |
#76 | interdiff-74-76.txt | 2 KB | legolasbo |
#76 | block-invalid_path_feedback-1164722-76.patch | 9.18 KB | legolasbo |
Comments
Comment #1
franzTitle doesn't fully describe bug, but I can guess you're talking about block visibility settings, specifically when setting block to show on listed pages. Is that right?
1) Doesn't have to be javascript, can be a simple validation on PHP
2) Browse doesn't sound good, we have router items, i.e node/[nid] wich can hold millions of entries. They are also not easy to pre-determine. As for interface, auto-complete sounds better.
Comment #2
benjy CreditAttribution: benjy commentedCan you please post the exact steps to replicate this issue.
Comment #3
franz@benjy
This is simply a usability improvement, not a bug to reproduce.
When you restrict block visibility to a page and type the wrong path, nothing happens (as expected), but it's hard to figure why. I suggested a simple validation of paths entered as a mean to help. Could be a warning like: "The path you entered does not seem to exist, are you sure it's right?"
Comment #4
benjy CreditAttribution: benjy commented@franz, thanks I understand now. It's a good point, even if it is a bit of an edge case.
I've updated the title to be a little clearer.
Comment #5
legolasboAttached patch adds this usability improvement.
If an invalid path is entered it will set a warning message.
Comment #6
benjy CreditAttribution: benjy commentedThis needs injecting as a dependency. @see \Drupal\system\Form\SiteInformationForm for an example.
Comment #7
legolasboAttached patch uses dependency injection
Comment #8
benjy CreditAttribution: benjy commentedCan you please add a property to the class for $aliasManager
This is not needed but we do need a
use Drupal\Core\Path\AliasManagerInterface;
We also need to update the doc comment.
Comment #9
legolasboAlso changed everything commented in #8
Comment #10
legolasboComment #12
legolasboI guess the test needs to be updated to reflect the new constructor.
Comment #13
benjy CreditAttribution: benjy commentedThis looks to have been copy and pasted by accident.
Try and add the alias manager to the test. Drupal\Tests\Core\PathProcessor\PathProcessorTest has an example of using the AliasManager in a test.
Comment #14
legolasboUpdates in attached patch:
From #14:
- Fixed copy/paste error
- Added alias manager to the test
From a discussion with dawehner in #drupal-contrib
- Changed $container->get('path.alias_manager') to $container->get('path.alias_manager.chached')
Comment #16
benjy CreditAttribution: benjy commentedI'm not sure what the difference is between
$container->get('path.alias_manager')
and$container->get('path.alias_manager.chached')
but maybe someone can explain?Either way, you've missed spelt "cached".
Comment #17
benjy CreditAttribution: benjy commentedOK, as explained by @tim.plunkett to me on IRC. The non-cached version of alias_manager recalculates paths when you call a method. We should in most cases be using the cached version.
Comment #18
legolasboFixed the typo
Comment #19
lukewertzThe patch in #18 works as advertised. I wonder though about the implementation. I think that this validation should probably happen on the edit form and not after the submit. I understand why it was implemented the way it was, but getting an error (or even a warning, in this case) after you've navigated away from a page seems like it may not be the most user-friendly workflow.
Settings the status to RTBC since the patch does work as described.
Great effort! Please keep it up!
Luke
Edit: I think that the warning message should include a link to the block (in the appropriate region) that was just edited as well as the alias that triggered the warning. That would avoid the odd work-flow as best as it can be.
Comment #20
lukewertzSorry for the quick update -- this patch does not handle wildcards. Changing this back to "Needs Work" until that can be reliably addressed as well.
Comment #21
legolasboThanks for the review lukewertz.
I'll fix the wildcard handling and I'll look into a way to do a javascript check on top of this implementation.
I'm not sure about what you exactly mean with:
Would that be a link to an anchor? I foresee situations where the block is invisible on the page where the error message is shown. An anchor wouldnt' do any good then. Or do you mean a link back to the block configuration page?
Comment #22
legolasboI've moved the path validation to a new function and added wildcard handling, This way i can reuse the code when i'm starting work on the javascript check.
I'm unable to do an access check on dynamic system paths like node/% because of #876580: drupal_valid_path fails for dynamic paths (e.g. user/% cannot be added to menus) and i'm still thinking about a way to implement an access check for the records in the url_alias table.
My current to do list:
Comment #23
benjy CreditAttribution: benjy commented1. I'm not sure JavaScript is correct here. Why can't we just use form_set_error in the validate function when there is an invalid path?
2. The last patch has a logic error in validate_paths() and doesn't work.
3. The block comment on validate_paths() needs fixing up.
4. I'm not sure about a function called validate_paths() which returns an array of error paths otherwise an empty array. Could we make it a little clearer? Maybe a validate path method that just returns true or false?
Good work so far!
Comment #25
lukewertzI don't think we should do the validation because (in this instance), I think people should be allowed to submit invalid URLs if they want to. We shouldn't stop them as site builders from entering a path that they know (or think) will be valid even if it isn't currently.
I don't think the JS implementation is necessary.
If we add more context to the warning message after save (specifically: a link to the block in the correct context that was just edited), that should be enough.
Think of this workflow: you're working on a site with 150 blocks (including a block that is in multiple regions). You've just saved a block that has an invalid path. If the warning only displays the block name (as well as the invalid path) that you just edited, you might forget what instance of the block you were editing. I think simply providing more information in the warning would suffice. That way the warning could be dismissed without blocking the save.
Thanks,
Luke
Comment #26
legolasboI agree with lukewertz's argument in #25 on not using form_set_error. Just informing the user about an invalid path should suffice. I think the current implementation using drupal_set_message does an excellent job of exactly that. However I do think checking paths before submitting the form could be a UX improvement since users would be informed about the incorrect path in time to alter it. This should happen in an unobtrusive way, which I'm still thinking about.
Perhaps we could make that a follow up issue, since i'm not that experienced with (Drupal) javascript.
Strange, i've tested it with a combination of existing and non existing paths and it worked like a charm locally. Any problem you've had will probably be fixed in the attached patch.
I agree and have rewritten the code (and comments) accordingly, improving readability in the process.
Comment #28
legolasbo#26: core-block-invalid-path-feedback-1164722-26.patch queued for re-testing.
Comment #30
tim.plunkettThis docblock is formatted incorrectly.
:)
This should be form_set_error, not drupal_set_message. Also, it doesn't "seem" to be invalid, it is invalid. This should be rewritten more like an error message.
Also, we should test the new validation.
Comment #31
scotwith1tCan this please NOT be done? It is not uncommon for people to create blocks ahead of time, knowing what they will set up the path to be in the future, and enter those paths in the "only show on these pages" section. To force the workflow to make the user create the page with the path first is undesirable...IMHO anyway...if the path doesn't exist, that entry does nothing...what's the harm?
Full disclosure, i haven't seen what, if anything, else has changed in D8 for block workflow, i'm just speaking generally. will set up a D8 instance soon to start pitching in, promise!
Comment #32
legolasboI agree with scotself. Displaying a warning after saving the configuration will be helpful for people who unknowingly entered a wrong path , while still allowing people who like to create blocks ahead of time to knowingly configure the block to show on pages that don't exists (yet).
I've changed the docblock formatting and warning message. I've also removed the call to dpm. I'll hold off on changing to form_set_error untill we've reached a consensus and I will be adding tests for the validation.
Comment #33
legolasboI've updated the patch with test for the new validation function. Besides that I've also had a discussion with dawehner in #drupal-contrib about the use of drupal_valid_path in the valid_path function. Since drupal_valid_path doesn't work for dynamic paths and still uses the old routing system in stead of the new I will rewrite the valid_path function to make use of the new routing system.
Comment #35
legolasbo#33: core-block-invalid-path-feedback-1164722-33.patch queued for re-testing.
Comment #36
franzThis looks good!
Comment #37
legolasboI've updated the valid_path function to also use the new routing system. As a result the aliasManager i've added before was no longer needed, so i removed it.
Comment #39
legolasboMissed a comma
Comment #40
dawehnerLet's try to never make functions private as they are harder to reuse.
Some minor codestyle issues: there should be a space after the else and the if.
There should be a @todo that we won't support it anymore once the old router system is removed.
Comment #41
legolasboI've addressed the code style issues, added the @todo and made valid_path() public.
Comment #43
legolasbo#41: core-block-invalid-path-feedback-1164722-41.patch queued for re-testing.
Comment #45
legolasboWhen i run the failing test locally it just passes. Unfortunately I currently don't have much time, so if someone else could chip in that would be greatly appreciated.
Comment #46
legolasboI've located and fixed the bug in the test.
Because of the recent additions/changes to the routing systems I decided to also review the valid_path() function to ensure it still worked as designed. It didn't so i've also made some alterations there.
Comment #48
legolasbo#46: core-block-invalid-path-feedback-1164722-46.patch queued for re-testing.
Comment #49
Stefan Lehmann CreditAttribution: Stefan Lehmann commentedI applied the patch from #46 and get:
Page not found
The requested page "/admin/structure/block/manage/mycustomblock_2" could not be found.
.. if I enter any path into the field "Only the listed pages". It doesn't matter if the path exists or not. I assume something else has changed since the patch was written.
Comment #50
legolasboI've tried to reproduce the behaviour you mention, but i've been unable to do so. Could you provide a more detailed description of how to reproduce this bug or even better, a patch with a failing test.
During my attempts to reproduce the bug you've mentioned i've also uncovered a routing exception that occurs when the only 'path' I put in is a space. I'll look into that and will also incorporate it into the test.
Comment #51
Stefan Lehmann CreditAttribution: Stefan Lehmann commentedThere is the possibility, that I didn't apply the patch correctly, so it would be nice if somebody else could verify, if the patch is working or not, before I try to reproduce it. For me it simply failed yesterday evening after cloning the latest Drupal 8 version.
Sorry I don't have time to look into it right now. But will have a look later today, if nobody else responded.
Comment #52
Stefan Lehmann CreditAttribution: Stefan Lehmann commentedOk .. I did a git reset --hard on my Drupal installation and pulled in the latest changes.
Afterwards I applied the patch: git apply -v core-block-invalid-path-feedback-1164722-46.patch again.
Checking patch core/modules/block/lib/Drupal/block/BlockFormController.php...
Checking patch core/modules/block/lib/Drupal/block/Tests/BlockTest.php...
Applied patch core/modules/block/lib/Drupal/block/BlockFormController.php cleanly.
Applied patch core/modules/block/lib/Drupal/block/Tests/BlockTest.php cleanly.
It still breaks with the error message mentioned above if I enter any path in the path inclusion field. I'm doing a manual test. I don't know what else I could do. Still .. it's perfectly possible, that I did something wrong ..
Comment #53
swentel CreditAttribution: swentel commentedMore coding standards.
capitalize the first word.
Exceeding 80 chars - happens in a lot of places.
I don't we do this in our coding standards. Wondering whether we can also inject the processor or not.
needs a space between if and ( - happens in a lot of places.
two spaces to much
Should use format_string form the replacements
same here
Comment #54
johnnydarkko CreditAttribution: johnnydarkko commentedWorking on this during drupal mentoring.
http://drupalmentoring.org/task/6501
Comment #55
johnnydarkko CreditAttribution: johnnydarkko commentedApplied coding standard changes mentioned by swentel in #53 to legolasbo's patch in #46.
Just posted my progress with this, but still needs work to address the third change request:
Comment #56
mikey_p CreditAttribution: mikey_p commentedI asked about the injections in IRC and chx says that there isn't a standard for injecting into form controllers.
At any rate I see 4 different services in use here and I'm not sure what the standards are on which should be injected and which shouldn't.
Comment #57
XanoShould be /**
The descriptions after @param or @return definitions are indented with two extra spaces.
Redundant empty line.
Exceeds the 80-character limit.
This does not belong here, as it is not a class property.
No class property.
Exceeds the 80-character limit.
Lower case @todo.
Exceeds the 80-character limit.
No contractions ("we'll" -> "we will") and exceeds the 80-character limit.
No contractions ("we'll" -> "we will") and exceeds the 80-character limit.
Let's use the query builder here. Inject the database service into the form controller, and then to $this->database->select().
Comment #58
johnnydarkko CreditAttribution: johnnydarkko commentedComment #59
johnnydarkko CreditAttribution: johnnydarkko commentedFixed comments as pointed out by Xano. Adding the progress here as I'm still working on the twelfth item mentioned.
Comment #60
piyuesh23 CreditAttribution: piyuesh23 commentedFixed #12 as well. Uploading the patch here.
Comment #62
Bram Esposito CreditAttribution: Bram Esposito commentedI'm reviewing this patch, if necessary I'll reroll.
Comment #63
Bram Esposito CreditAttribution: Bram Esposito commentedThe patch in #60 was rather old, so I've rerolled it (thanks @pfrenssen for mentoring me). Many changes were done in the files incl deletions and renames so this patch might fail in testing.
Comment #64
esod CreditAttribution: esod commentedChanging Status to Needs Review. You need to change the Status to "Needs Review" to get a patch reviewed.
Comment #68
legolasboComment #69
legolasboI'll be working on this today
Comment #70
legolasboMany tests were failing because of some function calls to non existing functions. These functions have been removed in D8, so I've replaced them with their replacements. There are more problems to fix but I'm posting my progress so far, to see what testbot thinks of it.
Comment #72
legolasboAttached patch should fix the remaining failing tests.
Comment #74
legolasboLet's try again... fixed another bug.
Comment #76
legolasboAaaand... fixed another few test bugs. this should do it.
Comment #77
pwolanin CreditAttribution: pwolanin commentedUsing $form['#action'] here seems quite wrong.
Comment #78
mauzeh CreditAttribution: mauzeh commentedThis is a little weird, and does not work if Drupal is installed in a subdirectory...
The '@' replacement formatter is incorrect. '@block' is a link that contains a prepared HTML anchor tag which was already run through check_plain() so we can use the "!" formatter instead.
Comment #79
legolasboComment #80
legolasboWe should check to see if this function can be replaced or simplified by using
\Drupal::pathValidator()->isValid($path)
Comment #81
Mile23Comment #84
Mile23How to make a re-roll: https://www.drupal.org/patch/reroll
Comment #85
siva_epari CreditAttribution: siva_epari commentedPatch rerolled.
Comment #87
Patrick Storey CreditAttribution: Patrick Storey at Hook 42 commentedI am removing the Novice tag from this issue because it was applied in 2013 and there has been quite a bit of work done since then.
Also this issue is getting close to 100 comments which is a lot for a new contributor.
I’m using this documentation as a source: https://www.drupal.org/core-mentoring/novice-tasks#avoid
Comment #90
pwolanin CreditAttribution: pwolanin as a volunteer and at SciShield commentedComment #91
pwolanin CreditAttribution: pwolanin as a volunteer and at SciShield commentedMaybe we could just add a minimal validation to make sure it has a leading slash at least for 8?