I've got a website with a lot of different entities/users and having "url redirects" for example on a user edit page is very messy.
I know you can undo this by using some hook_form_alter ... but I'm not a developer and I stay away from such code unless I really really have no other choice.

A list of all the entities with a simple checkbox on the url redirects settings page would be a great addition to the module.

Comments

bgilhome’s picture

StatusFileSize
new1.54 KB

Here's a patch for review. It adds the option to select entity types to ENABLE redirect editing on, perhaps it would be less disruptive to change to disable?

NB this acts on redirect_field_attach_form() only, the 'redirect' on entity info is unaltered, so redirects can be enabled but the editing interface simply hidden.

bgilhome’s picture

Status: Active » Needs review
joelstein’s picture

Status: Needs review » Needs work

Great patch!

However, I don't think you've got the right defaults. Existing installations may be using this for all sorts of entity types.

Also, there's already a function which tells us whether or not an entity type supports redirect: redirect_entity_type_supports_redirects(). We should leverage this somehow.

Perhaps it could be worded differently, "exclude" instead of "include". So the form would show all entity types, exclude by default the ones excluded in redirect_entity_type_supports_redirects(), and save the value to a variable like "redirect_disable_entity_types". Then in redirect_entity_type_supports_redirects() we'd check the value of this variable in addition to the other methods?

anybody’s picture

+1 for the idea! We need an interface like the metatags modul to select the entities the module is active on!
Perhaps have a look at the latest version there?

aaronbauman’s picture

Status: Needs work » Needs review
StatusFileSize
new1.41 KB

Agree with #3: previous patch drastically changes existing behavior, which is against Drupal best practices.

Attached is a simple re-rolled patch which is essentially the inverse:
the form disables Redirects on specific entities, but defaults to "on"

jrreid’s picture

StatusFileSize
new1.76 KB

Works perfectly for me, but I agree that we should probably try to utilize redirect_entity_type_supports_redirects() as this is pretty similar to what its used for. New patch attached.

devad’s picture

This is requested long ago and redirected here: #1604068: Limit redirects by entity / bundle.

Is it complicated to implement per-bundle choice as well?

scronide’s picture

Tried patch #6. It didn't apply cleanly for me but manually making the changes seemed to work. One problem with the patch is that your selection is excluded from the list of entities: so you can't add to your current selection, you can only replace it.

Echofive’s picture

StatusFileSize
new2.59 KB

Hello,

The patch #6 is not correct (see comment #8).
So I've create a new patch based on the patch made by jrreid.

The issue in his patch is the fact that the function (redirect_entity_type_supports_redirects) used to define the checkboxes options also skip the disabled options.

I've add a new patch, tested on the branch 7.x-1.0-rc3 and the 7.x-1.0-dev.

Kind regards,

Echofive

EDIT: PATCH ...-9.patch is not correct, use the ...-10.patch

Echofive’s picture

StatusFileSize
new2.59 KB

Sorry, big logical error into my previous patch (see comment #9), but the concept is the same.
I've added the right version ;)

chris matthews’s picture

The patch in #10 from 2 years ago still applied cleanly to the latest 7.x-1.x-dev and would indeed be a great addition to both the 7.x-1.x and 7.x-2.x branches of the module.

Checking patch redirect.admin.inc...
Hunk #1 succeeded at 702 (offset 35 lines).
Checking patch redirect.module...
Hunk #1 succeeded at 280 (offset 1 line).
Applied patch redirect.admin.inc cleanly.
Applied patch redirect.module cleanly.
damienmckenna’s picture

StatusFileSize
new2.5 KB
new2.94 KB

I simplified the logic and made it still backwards compatible.

damienmckenna’s picture

I wonder if this could be handled through hook_entity_info_alter() by setting the $info[$unsupported_entity_type]['redirect'] = FALSE; just like the module does with some entity types already?

damienmckenna’s picture

StatusFileSize
new1.42 KB
new2.77 KB

This is an improved version that fixes the changes made to the settings page.

anybody’s picture

Great @DamienMcKenna! Just reviewed the patch manually and tried it, does what it should and the logic looks correct to me.

sgdev’s picture

Status: Needs review » Reviewed & tested by the community

Have been using this patch since #10. Added #14 to the latest 7.x-1.0-rc4 release and working just as well. Marking as reviewed.

kristen pol’s picture

Assigned: Unassigned » kristen pol

Assigning to myself as I'm triaging all RTBC issues.

kristen pol’s picture

Assigned: kristen pol » Unassigned
Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs tests

Thanks, everyone, for the issue, patches, testing, and reviews. I scanned the code and didn't see anything obviously amiss.

This is a nice little feature, but one thing it's missing is some tests for testing the new functionality. I know it's not a bug, but IMO it still needs tests, so marking for that.

wylbur’s picture

Status: Needs work » Closed (outdated)

Closing this as Outdated as Drupal 7 is EOL.