Needs review
Project:
Redirect
Version:
8.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
21 Oct 2021 at 14:13 UTC
Updated:
23 Mar 2026 at 14:37 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
ericchew commentedComment #3
ericchew commentedComment #4
ericchew commentedComment #5
ericchew commentedSmall fix to make sure the element only renders on the edit page.
Comment #6
ericchew commentedI just noticed that for taxonomy terms (and possibly other entity types) that there is no "edit" form operation. When on the edit form for taxonomy terms, the operation is "default". This is another small change to make it so the element only renders if the form operation is "default" or "edit". I'm not sure if there is a better way to determine when on a content entity edit form in a form alter.
Comment #7
mglamanDo we need to check the Field UI base route property? I have plenty of custom content entities that don't have field UI support.
This seems new? It didn't check the display component before
This also looks new? Adding lookup by path alias vs internal/canonical
We need this to remain the redirect list builder, as it builds just those. Correct?
Comment #8
ericchew commented1. Good point. My initial thinking was that if you can't configure whether it should/shouldn't be displayed, then don't show it at all. It probably does make more sense to show it by default given what you said.
2. After testing, this doesn't seem necessary. I put it there initially because I thought that the element may render regardless of it being enabled/disabled in the form display, but that isn't the case. I removed the check and tested to see if I disabled the element in the form display whether it was properly disabled in the edit form, and it was.
3. I added this because in my testing, some of my redirects were not showing up for products because the redirect was pointing to its alias instead of its internal url. I'll remove this and check to see if there is already an issue for that.
4. Correct. Not sure what I was thinking.
Attached a new patch that makes the changes discussed above and adds a few cleanups.
Comment #10
ericchew commentedTests are failing because the form alter is too generic. The test that fails is trying to edit a path alias entity. When the edit form for the path alias entity loads, the form alter logic is run because the operation is "default". It then crashes when we try to get the canonical url for a path alias entity, because no canonical url link template is defined. This did not crash previously because of the check for whether the url_redirect component was added in the form display (it isnt for path alias because it has no field ui base route).
Need to figure out a better way to make sure we are only form altering edit forms.
Comment #11
ericchew commentedNew patch that has a check for whether the canonical link template exists for the entity in the form alter. There doesn't appear to be a better way to target the edit forms we want in a form alter.
Comment #12
ericchew commentedComment #13
tonytheferg commentedWorks for me on taxonomy term edit forms. Thanks!
Comment #14
skyredwangAlso works for me on commerce product edit forms
Comment #15
rossb89 commentedWorks for me, also tested on nodes & commerce product entity forms.
Comment #16
Manoj Raj.R commentedWorks foe me also commerce product edit forms
Comment #17
berdirI see that this, already now for node, doesn't contain a check whether the extra field is actually enabled.
That is IMHO more relevant now with making this visible in many more places. Instead of hardcoding the operations, what you want to do is call $form_object->getFormDisplay()->getComponent('url_redirects').
I'd also suggest to to add visible => $entity_type->id() == 'node' so that this doesn't change on existing sites automatically.
nitpick: comment over 80 characters.
Comment #18
phjouPatch #11 works well for me as well.
I attached a new patch with the change for $form_object->getFormDisplay()->getComponent('url_redirects'), I just had to pass the form state to getFormDisplay which is a mandatory argument.
And I broke the comment on two lines.
And the only thing left that needs to be addressed is the visible => $entity_type->id() == 'node'. The URL redirects stayed visible for me even with the patch so I am not 100% sure of what was needed there.
Comment #19
phjou@Berdir Apparently $form_object->getFormDisplay($form_state)->getComponent('url_redirects') is not enough.
This behavior is bleeding into my webforms when logged in and it was not happening with #11.
Comment #20
vasyok commentedPeolple, please let me know: why there is 2 files for patching? url-redirects-tab-3245137-18.patch and interdiff.txt. I need apply them all?
Comment #21
ericchew commented@VasyOK you only need to apply the patch file. The interdiff is uploaded to see what code has changed between the current patch and the previous patch because it makes it easier to review.
https://www.drupal.org/docs/develop/git/using-git-to-contribute-to-drupa...
Comment #22
vasyok commentedTheanx Ericchew!
#18 worked with terms
Comment #23
anybodyYes this totally makes sense. I just searched for it on taxonomy term pages. Indeed this should be available on all kinds of entities that can be redirected! +1!
Could someone maybe turn the latest implementation into a MR?
We shouldn't work with patches anymore.
Comment #26
dcam commentedI converted the patch from #18 to an MR. There's no need to give me credit for doing that.
This needs tests. The existing functionality for the Node edit form has a test. It's possible that the test can be renamed and repurposed to check other entity types.
Comment #27
dcam commentedComment #28
dcam commentedI added some new assertions to check for the Redirects element. I repurposed the existing Node form test for that purpose. Since Users are content entities, they also get the extra field with this patch. So I simply checked for its presence on the users' own edit forms.
Comment #29
dcam commentedI added the visibility check mentioned in #17 to the extra field. I think this is ready for review again.
Comment #30
anybodyThanks for the tests @dcam, just had a short look at the code and added a comment. Nice to see this moving forward!
Could we check all core entity types to be sure it works there?
Comment #31
anybodyComment #32
anybodyComment #33
phjouRerolled the patch to work on the latest version.
The patch does not contain this line that was in the branch:
That defies the purpose of the whole ticket to make it work with all entities and not just nodes.
Comment #34
phjouOOps, I uploaded the wrong patch. This should work better with that one, sorry.
Comment #35
phjouComment #36
tonytheferg commentedLooks like this needs re-rolled for 1.12
Comment #37
anybodyThis look quite close to the finish line, maybe someone would like to carry it over? :)
Comment #38
chris matthews commented@tonytheferg, the patch in #34 applies cleanly to 8.x-1.12 and 8.x-1.x-dev
Comment #39
anybody@chris matthews I think the MR was meant. At least we should have a MR from the patch to review? Maybe someone could do that?
Comment #40
chris matthews commentedThe MR should be ready for review now.