Problem/Motivation
Now that path aliases have been converted to entities in #2336597: Convert path aliases to full featured entities, we can convert their custom forms to use content entity forms instead.
Proposed resolution
Convert custom path alias forms to entity forms.
The following table lists all the previous form classes and their IDs, along with their replacements.
Previous form class | Previous form ID | New form class | New form ID | |
---|---|---|---|---|
Drupal\path\Form\AddForm |
path_admin_add |
-> | Drupal\path\PathAliasForm |
path_alias_form |
Drupal\path\Form\EditForm |
path_admin_edit |
-> | Drupal\path\PathAliasForm |
path_alias_form |
Drupal\path\Form\DeleteForm |
path_alias_delete |
-> | Drupal\Core\Entity\ContentEntityDeleteForm |
path_alias_delete_form |
Drupal\path\Form\PathFormBase |
N/A | -> | Drupal\path\PathAliasForm |
N/A |
Custom code needs to be updated for any hook_form_alter()
or hook_form_FORM_ID_alter()
implementations that were using the previous form IDs. For example, a hook_form_path_admin_add_alter() implementation of hook_form_FORM_ID_alter()
for the path_admin_add
form ID needs to be renamed to hook_form_path_alias_form_alter().
Additionally, the following routes have been deprecated and replaced by generic entity routes:
Previous route name | New route name |
---|---|
path.admin_add |
entity.path_alias.add_form |
path.admin_edit |
entity.path_alias.edit_form |
path.delete |
entity.path_alias.delete_form |
path.admin_overview |
entity.path_alias.collection |
Remaining tasks
Review, commit.
User interface changes
Nope.
API changes
Nope.
Data model changes
Nope.
Release notes snippet
Path alias administrative forms have been converted to generic entity forms. This means form IDs and form class names have changed, so custom code needs to be updated for any hook_form_alter()
or hook_form_FORM_ID_alter()
implementations that were using the previous form IDs. Additionally, some path routes have been deprecated and replaced by generic entity routes: See the change record for a full list of changes.
Comment | File | Size | Author |
---|---|---|---|
#33 | interdiff-33.txt | 5.1 KB | amateescu |
#33 | 3007832-33.patch | 61.26 KB | amateescu |
#30 | interdiff-30.txt | 6.45 KB | amateescu |
#30 | 3007832-30.patch | 62.35 KB | amateescu |
#28 | interdiff-28.txt | 746 bytes | amateescu |
Comments
Comment #2
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedWorked a bit on this today.
Comment #4
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedFixed a few things.
Comment #5
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedSmall cleanup.
Comment #7
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedOops.
Comment #9
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedThe dependent patch has been fixed, there's no change to the "for review" one here so just posting a combined one to get a green light from the testbot :)
Comment #10
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedRerolled on top of #2336597-84: Convert path aliases to full featured entities and made a few improvements.
Comment #11
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedFixed the post update function.
Comment #12
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedBrought over an improvement from a followup issue.
Comment #14
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedRerolled the patch on top of #2336597-136: Convert path aliases to full featured entities.
Comment #15
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedComment #16
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedFixed a few failures, but the JSON:API one needs to be fixed in the parent issue.
Comment #17
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedRerolled the combined patch with #2336597-141: Convert path aliases to full featured entities.
Comment #18
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedComment #19
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedRerolled the combined patch with #2336597-142: Convert path aliases to full featured entities.
Comment #20
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedRerolled with the latest patch from the initial conversion issue.
Comment #21
Berdiroh wow, I don't think I've seen that before (the regex).
But wondering if we could just do that as part of ValidPath?
we can't re-use UniqueFieldValueValidator for this I guess?
I know from redirect.module that the default language widget options are very confusing for path/redirect and I think we ended up customizing that.
Ah, I see, you did that too :)
wondering if it wouldn't be cleaner to put this stuff in PathAliasForm, that's how we do it on other entity types like node too?
And we do use the field description by default, but often these descriptions don't make too much sense as the general field description and vice-versa.
This feels icky, thought we could use list builder operations already or something, but we're refactoring all of this anyway in the list builder issue.
makes me wonder if pathauto or redirect use some of these old routes anywhere..
Comment #22
jibran#2336597: Convert path aliases to full featured entities is in.
Comment #23
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedThe 'for review' patch doesn't need a reroll, it needs work to address #21.
Comment #24
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedWatching this since it may be helpful or a blocker for #3085480: \Relax PathAliasConstraint when creating draft content and instead create pending alias revisions.
Comment #25
andypostConstructor can get storage instead of ETM, also why the property is private?
Comment #26
amateescu CreditAttribution: amateescu for Pfizer, Inc. commented@Berdir, re #21:
We could, but we still need to do it separately for the
alias
base field, and IMO it looks better to have these two similar constraints in the same place. It makes the code easier to scan (visually) for someone who needs to debug or something :)We can't because we need to add the language fallback stuff, which is specific to path aliases.
I don't think it would be cleaner because we are altering widget-level code here. There's no other entity form in core that's altering stuff like
$element['<field_name>'][0]['value']...
, because that's whathook_field_widget_form_alter()
is for :)@andypost, no idea why I set that to private, probably an IDE autocomplete mistake. Fixed!
Comment #27
Berdirprivate was definitely wrong, not quite so sure about the entity type manager -> storage change. IMHO injecting non-services can be a bit problematic. We already had to add special support for entity storages to \Drupal\Core\DependencyInjection\DependencySerializationTrait for example.
Comment #28
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedOk, let's stick with storing only services as class members, I agree that it makes more sense. The interdiff is to #20 :)
Comment #29
andypost@berdir as #17 said ...is there existing issue about it? There's both ways used in core now
Personally I prefer to require in constructor only storage cos class has "less knowledge" about external dependencies
Comment #30
amateescu CreditAttribution: amateescu for Pfizer, Inc. commented@andypost, that's an interesting point, but let's not hold up this patch just for that detail :) Since both ways are used in core, I think we need a policy issue to decide one way or the other, and then we can update everything at once.
After discussing this patch with @Berdir, he mentioned that we should add a BC layer for the routes that we're removing, so here it is.
Comment #31
BerdirWith deprecation tests and everything, beautiful ;)
@andypost: Yeah, I'm happy to argue why I think it's better the inject the entity type manager only in a separate issue (in short, performance when not used and ability to clear storages when certain changes happen. Might not be too relevant for this validator, but matters in other cases).
I think the main point from my review that wasn't addressed is altering the form elements in the widget alter or in the entity form. I prefer doing something like that in the EntityForm class instead of putting things in the .module file, but that's more a personal preference and I don't feel strongly about it. I'll leave that decision to the core maintainer who is going to review this. @amateescu correctly said that we don't do that yet in core in e.g. NodeForm, but we don't have any comparable widget alter hooks either I think, commerce seems to do that a lot though ;) And most core content entity forms unfortunately don't use widgets at all.
I did some manual tests as well and as far as I see, the add/edit forms look identical. There are tiny differences on the delete form (Confirm button becomes Delete, and the confirm message has an extra "the", but that's standardized on entity delete forms and actually seems more correct).
Comment #32
alexpottAnd the deprecation messages need to link to said change record. Ah I see we are going to update the existing CR - well that CR needs to link to this issue and so do the deprecation messages.
This change is likely to be disruptive but form arrays are not API so this is allowed to change in a minor. Hopefully won't be too painful for contrib and custom tests.
The good thing is that these form class removals would appear not to break contrib - http://grep.xnddx.ru/search?text=Drupal%5Cpath%5CForm&filename=
This is not a RestResourceGetRouteProcessorBC
First reaction is that this seems unrelated - how come these changes are necessary?
Comment #33
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedThanks for the review!
Those changes were needed because I added the
path
module inPathAliasResourceTestBase
, but that was a mistake, we don't need it there, so I reverted those three hunks from the patch :)Fixed all the other points as well.
Comment #34
alexpottSo this change is going to break some contrib - see
http://grep.xnddx.ru/search?text=_form_path_&filename=
So https://www.drupal.org/project/fixed_path_alias https://www.drupal.org/project/mpac and https://www.drupal.org/project/views_url_alias
Comment #35
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedOpened issues for all three projects:
https://www.drupal.org/project/fixed_path_alias/issues/3086814
https://www.drupal.org/project/mpac/issues/3086816
https://www.drupal.org/project/views_url_alias/issues/3086817
Comment #37
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedUpdated the issue summary to list all the changes to form classes / IDs as well as deprecated routes and their replacements.
Comment #38
alexpottDiscussed with @catch and @plach and consider whether we should put this in as a breaking change in 9.0.x but they both felt it was better to go in 8.8.x and I agreed.
Committed f9528c5 and pushed to 9.0.x and cherry-picked to 8.9.x and 8.8.x. Thanks!
Comment #42
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedThanks, @alexpott!
Updated the CR and added a release note snippet.
Comment #43
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedComment #44
jibranFound this gold #147143: Add new URL aliases UI and moved it to 9.1.x
Comment #46
xjmUpdating the release note with disruption information from @pameeela, and crediting her for the improvement
Comment #47
xjmAnd actually pasting the draft snippet.
Comment #48
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedThe update looks great to me, thanks!