- 🇮🇳India Manoj Raj.R Chennai
Works foe me also commerce product edit forms
- Status changed to Needs work
almost 2 years ago 10:50pm 23 February 2023 - 🇨ðŸ‡Switzerland berdir Switzerland
-
+++ b/redirect.module @@ -293,18 +301,26 @@ function redirect_entity_extra_field_info() { - /** @var \Drupal\node\NodeInterface $node */ - $node = $form_state->getFormObject()->getEntity(); - if (!$node->isNew() && \Drupal::currentUser()->hasPermission('administer redirects')) { +function redirect_form_alter(&$form, FormStateInterface $form_state, $form_id) { + /** @var \Drupal\Core\Entity\ContentEntityForm $form_object */ + $form_object = $form_state->getFormObject(); + if (!$form_state->getFormObject() instanceof ContentEntityForm || !in_array($form_object->getOperation(), ['edit', 'default'])) { + return; + } - $nid = $node->id(); + $entity = $form_object->getEntity();
I 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.
-
+++ b/redirect.module @@ -293,18 +301,26 @@ function redirect_entity_extra_field_info() { - // Find redirects to this node. + // The internal url, e.g. taxonomy/term/1 (NOTE: doesn't include initial forward slash, it is added below)
nitpick: comment over 80 characters.
-
- 🇨🇦Canada phjou Vancouver 🇨🇦 🇪🇺
Patch #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.
- 🇨🇦Canada phjou Vancouver 🇨🇦 🇪🇺
@Berdir Apparently $form_object->getFormDisplay($form_state)->getComponent('url_redirects') is not enough.
This behavior is bleeding into my webforms when logged in. - 🇺🇦Ukraine vasyok
Peolple, 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?
- 🇺🇸United States ericchew
@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... →
- 🇩🇪Germany Anybody Porta Westfalica
Yes 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. - First commit to issue fork.
- 🇺🇸United States dcam
I 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.
- 🇺🇸United States dcam
I 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.
- 🇺🇸United States dcam
I added the visibility check mentioned in #17 to the extra field. I think this is ready for review again.
- 🇩🇪Germany Anybody Porta Westfalica
Thanks 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?