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
The path module introduces the URL alias field for node/taxonomy term/media entities. There is a form alter to add a vertical tab for the node form. Having a different UI for node vs taxonomy terms/media is confusing for users.
Proposed resolution
Let's make it consistent and create a vertical tab/fieldset for all places the URL alias is added.
Remaining tasks
User interface changes
A fieldset will be added for the URL alias to the taxonomy and media add forms.
Taxonomy before
Taxonomy after
Media before
Media after
API changes
None
Data model changes
None
Comment | File | Size | Author |
---|---|---|---|
#39 | interdiff-2916809-33-39.txt | 2.18 KB | phenaproxima |
#39 | 2916809-39.patch | 6.06 KB | phenaproxima |
#33 | interdiff-32-33.txt | 631 bytes | seanB |
#33 | 2916809-33.patch | 7.99 KB | seanB |
#32 | interdiff-29-32.txt | 3.29 KB | seanB |
Comments
Comment #2
seanBHere is a patch to fix it, plus the before / after screenshots for the taxonomy/media forms. This will also help to fix #2893740: Allow the sidebar for the node form to be used on other entity forms as well and make the UI more consistent for all content entity forms.
Comment #3
idebr CreditAttribution: idebr at ezCompany commentedNice improvement to the interface!
I suppose this function doc should be updated to new hook implementation.
Comment #4
seanBGood one, thanks!
Comment #6
borisson_This patch looks good! I really like this change. I have some nits to pick though.
Should be {@inheritdoc}
randomMachineName should not be used here, (see https://www.drupal.org/project/drupal/issues/2571183#comment-12350702). I think this will be just as good with any string as id.
Comment #7
seanBThanks, good to know! Updated the patch.
Comment #8
borisson_Looks solid! I don't think I can RTBC this before this gets that usability review though.
Comment #9
yoroy CreditAttribution: yoroy at Roy Scholten commentedThis also means we're hiding things behind yet another click. On the content form this is the case as well, but we may assume pathauto being used there more often. But l'll take the consistency argument. This is mostly a one-time set it and forget it task so I think it's fine to proceed here.
Comment #10
borisson_Setting to RTBC based on @yoroy's review on the usuability side and my review for the code.
Comment #11
Berdir\Drupal\path\Plugin\Field\FieldWidget\PathWidget::formElement() does have access to the full form?
Can we maybe move the logic in there, so we don't need a global form alter hook that is called on every form?
CommentWidget::formElement() is for example already doing that, based on the existence of a $form['advanced'] element.
Comment #12
seanBThanks! That seems like a better solution. Only thing I'm not sure about is the id attribute of the details element changes with this approach.
Patch is attached.
Comment #13
PanchoA much nicer solution! Needs another review though...
Comment #14
BerdirYeah, not sure about the raw ID check here either. Why don't we just look for vertical tab title (URL Alias settings), at least additionally to the ID?
Comment #15
robpowellLooking into this
Comment #16
robpowellWhen I applied the above patch to 8.6.x branch I did not get the expected results from the screenshots above. On both pages I saw the field displayed normally like the before patch screenshots.
Steps taken
Neither ContentEntityFormInterface or FormStateInterface is used in path.module, this can be deleted.
@berdir regarding #14, can you be more specific? I am still getting used to writing tests so an example of where we are already doing something similar would be hugely helpful.
Comment #17
robpowellComment #18
BerdirThe new test is looking for $form['advanced']. I'm not sure why it wouldn't be visible at least for media, that should get this from the parent in \Drupal\Core\Entity\ContentEntityForm::form? . I don't think it's the responsibility of this issue to define a vertical tabs element if it doesn't exist yet. Previous it always defined the details element but I guess the #group => 'advanced' just did nothing if it wasn't defined?
Not sure if the goal of this issue is to only add it to a vertical tabs/sidebar element if that exists or to always define a wrapper? This is now consistent with \Drupal\comment\Plugin\Field\FieldWidget\CommentWidget, but that was also specifically done like that to continue working as it did before for nodes.
We also have issues to generalize the node form sidebar thing in seven to other entity forms.
For the test, something like this is what I meant:
Alternatively, you can also use the find* methods on getSession()->getPage() and then from that, use getText() or getHTML() and work with $this->assertContains() or so:
Comment #19
robpowellAlright so I spun up two simplytest envs, one at patch #2 and one at patch #12 (password admin/admin).
#2 works for both media and taxonomy while #12 does not. Reviewing the interdiff for #12 shows that the hook_form_alter was removed but the following steps outlined in #11 were not completed.
Finally, I updated the test per #18.
Comment #20
robpowellComment #22
robpowellTried to replicate locally but was getting a different error
while the automatic test failure was
Wanted to get this quick change up to see if it passes.
Comment #23
robpowellComment #25
seanBHere is a new try to test for the fieldset and the field without using an ID.
Comment #26
seanBTriggering the tests.
Comment #29
seanBThis should fix it.
Comment #30
phenaproximaQuestion -- won't this end up removing the URL alias field if the 'advanced' tab set is unavailable? If so, this patch could theoretically introduce a regression. We might want to expand the test coverage to ensure that it's visible in some place where it previously appeared despite there being no "advanced" tab (if such a place exists in core).
Comment #32
seanBThe only thing we are doing is add a extra details wrapper when the advanced fieldset is available. In all other cases it does the same thing as before.
Since the advanced fieldset is only added for revisionable entities I've added a test for the taxonomy form.
Comment #33
seanBAhh missed one copy/paste rename thingy.
Comment #35
marcoscanoReviewed the patch and it looks good to me
Comment #36
webchickThis is really great, and cleans up the form so much!! Especially with remote video because then you don't have that utterly perplexing "Remote URL" and "URL alias" combo pak.
The one concern I had is that the test for making sure we don't vertical-tab this field on non-revisionable entities is targeting taxonomy terms, and while that should be fine for 8.6, in 8.7 we definitely hope to have those (as well as menu items + comments) revisionable, for an improved content staging experience. #2880149: Convert taxonomy terms to be revisionable has activity on it as of 11 hours ago, so is actively being worked on by that team, whereas this is "just" a UX improvement.
So could we instead either a) target something that's not one of the "main" content entities (shortcuts, maybe?) or b) invent our own "mock" non-revisionable entity for testing purposes?
Otherwise, this is a lovely improvement filled with loveliness, and I would love to see it in 8.6!
Comment #37
webchickOh one other tiniest nitpick we found during review:
Should be "media form ui" (and why not "UI" while we're at it, lol).
Comment #38
webchickMOAR credits!
Comment #39
phenaproximaIt turns out that we cannot test with shortcuts because Path has support for node, media, and taxonomy hard-coded. Wow.
From
path_entity_base_field_info()
:Yeah.
So in discussion with @webchick, we agreed to remove the new taxonomy term form test from the patch, since #2880149: Convert taxonomy terms to be revisionable will render it entirely useless anyway.
Comment #40
starshapedLooks good to me! Setting to RTBC.
Comment #41
webchickAwesome! Committed and pushed to 8.7.x and backported to 8.6.x. Thanks!
Comment #44
neclimdul#2989950: Fix Unused use in path.module follow up for added phpcs failure.