Make Redirects fieldable

Created on 7 August 2018, almost 7 years ago
Updated 14 March 2023, about 2 years ago

I would prefer that redirects were field-able so that I could add a taxonomy or other type of field to organize and manage redirects. I would add a taxonomy field to identify redirects used for ad campaigns, changes to paths, paths from old sites, etc.

✨ Feature request
Status

Needs review

Version

1.0

Component

User interface

Created by

πŸ‡ΊπŸ‡ΈUnited States dgwebcreative Reno, NV

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡«πŸ‡·France federiko_

    I applied patch from comment #6 but had no luck. When editing a redirection, an error message appeared stating :

    Notice : Undefined index: #value dans locale_form_redirect_edit_form_alter() (/app/web/modules/contrib/redirect/redirect.module ligne 261)

    Exception: Object of type Drupal\Core\Language\Language cannot be printed. in Drupal\Core\Template\TwigExtension->escapeFilter() (line 454 of /app/web/core/lib/Drupal/Core/Template/TwigExtension.php)

    Environnment = drupal 9.4.10 + PHP 7.4

  • πŸ‡«πŸ‡·France federiko_

    In my case, in a fresh drupal 9.4.10 installtion, removing the locale_form_redirect_edit_form_alter() function is solving the issue I had.

  • Status changed to Needs work about 2 years ago
  • πŸ‡¨πŸ‡­Switzerland berdir Switzerland

    That must not be removed but fixed if it changed, maybe you configured the field to be hidden or so?

  • πŸ‡«πŸ‡·France federiko_

    I have performed a fresh installation and added a text field through the UI on the redirection module.

    I decided to remove the 'locale_form_redirect_edit_form_alter()' hook because it seems to not be used at all, at least in recent drupal core versions. But you're right @Berdir it's possible that doing so could affect compatibility with older versions of Drupal 8 or 9. I will investigate this further.

  • πŸ‡¨πŸ‡­Switzerland berdir Switzerland

    It has nothing to do with the drupal core version and yes it is definitely used or you would not have received an error.

    If you have a single-language site then you likely don't see it, but it's there and used.

  • πŸ‡«πŸ‡·France federiko_

    I have received an error related to the code added in comment #5, which has not been commited yet if I am not wrong...

    The code added disables the bundle support for redirect entity and had as a consequence to change the redirect entity edit form id and also trigger locale_form_redirect_edit_form_alter()... (which mas not triggered before , if I understand well)
    Before that, the form alter was never triggered because it was targeting an old form id (redirect_edit_form and not redirect_redirect_edit_form).
    But may be I am missing something...

    The language field related code seems to be implemented there, at least in Drupal 9.2+ :
    https://git.drupalcode.org/project/redirect/-/blob/8.x-1.x/src/Entity/Re...

  • Issue was unassigned.
  • Status changed to Needs review about 2 years ago
  • πŸ‡¨πŸ‡­Switzerland berdir Switzerland

    You're right, the logic of that hook was moved to \Drupal\redirect\Form\RedirectForm::form(), it can indeed be removed.

    I expected that this also needs an update function, but it's currently not reporting anything on the status page, possibly because the key was bogus and never actually used.

  • πŸ‡«πŸ‡·France federiko_

    So to sum up :
    - it seems that locale_form_redirect_edit_form_alter() is deprecated code, which removal does not have any impact at all.
    - as a consequence of disabling bundle support for the redirect entity and to avoid collision with updated/patched redirect edit form id, it seems also that we could remove this deprecated code

    Then the remaining question that I see for a generic implementation is : can the modification of the redirect edit form id have an impact outside of the redirect module ? If a custom module (named my_custom_module) implemented my_custom_module_form_redirect_redirect_edit_form_alter() that custom hook would stop working, is that correct ?

  • πŸ‡·πŸ‡ΊRussia kala4ek πŸ‡·πŸ‡Ί Novosibirsk

    Looks like locale_form_redirect_edit_form_alter() was already removed during some other ticket and patch from #8 not applied anymore. So here is updated patch.

  • πŸ‡ΊπŸ‡ΈUnited States ivagold Philadelphia, PA

    Hi all, what's the current status on this? What would it take to get it over the finish line?

    I'd love it if this were a real, stable feature. The site I currently manage has lots of redirects, because our marketing team likes to make shortened "Vanity URLs" for use in printed campaign materials. It would be helpful to have a comment field about why redirects were added, which campaigns they were for, etc.

  • πŸ‡΅πŸ‡ͺPeru krystalcode

    Adding a few thoughts here. If I understand this issue correctly you want to be able to add bundle fields via the UI.

    What you should ideally be doing is adding base fields to the entity programmatically. Adding new fields as "bundle fields" i.e. field and storage definitions in configuration files would harm performance since they are always created as separate tables in the database forcing extra joins in the database queries - and redirects (potentially multiple in redirect chains) may be loaded in every request.

    Adding new base fields is really straightforward, including displaying them in forms. Contrib modules can do that for common use cases e.g. a redirect_comment module could provide a comment field for redirects and a redirect_category module could provide a field referencing a taxonomy term for classification.

    That said, if a UI and the ability to add bundle fields were to be added, and since entity type definitions are cached, I do not think there will be too much of a performance hit for applications that do not use bundle fields - just a little bit. I would be more concerned about promoting the non-optimal way, and also adding more code to maintain to the main module. It might be best that such ability goes to a separate module or submodule that could alter the entity type and make it fieldable, and provide some notes that this should be used by site builders while developers should prefer base fields where possible.

Production build 0.71.5 2024