Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Throughout the weblinks code we rely on the name of the taxonomy vocabulary being 'weblinks'. However, an admin user can rename this internal name via admin/structure/taxonomy/weblinks/edit
I think we should prevent this, as it would cause all sorts of code failures. Maybe a form_alter to disable this input field when editing our vocabulary?
Comment | File | Size | Author |
---|---|---|---|
#10 | 2425859_10.disable_weblinks_machine_name_edit.patch | 534 bytes | jonathan1055 |
#2 | 2425859_2.disable_weblinks_machine_name_edit.patch | 713 bytes | jonathan1055 |
#2 | machine name 3 disabled.png | 36.19 KB | jonathan1055 |
#2 | machine name 2 field exposed.png | 57.31 KB | jonathan1055 |
#2 | machine name 1 before.png | 40.87 KB | jonathan1055 |
Comments
Comment #1
GStegemann CreditAttribution: GStegemann commentedYou are right. As of current the vocabulary machine name should not be renamed. Good idea to disable the filed by form_alter hook.
Comment #2
jonathan1055 CreditAttribution: jonathan1055 commentedThree images
1. before change when first visiting the form
2. before change but after clicking 'edit'
3. After patch - no 'edit' link or field shown
Patch for testing.
Comment #3
GStegemann CreditAttribution: GStegemann commentedSorry, I forgot to test. Works. Thanks.
Comment #5
jonathan1055 CreditAttribution: jonathan1055 commentedThanks.
Comment #6
jonathan1055 CreditAttribution: jonathan1055 commentedThe commit above has not yet appeared in the dev release which still shows:
This is just a reminder after the next commit to check that this change is also included.
[update: yes this commit is included now]
Comment #8
jonathan1055 CreditAttribution: jonathan1055 commentedI've noticed that the change I made was not exactly right. I tested the 'current' vocabulary used for weblinks. This is wrong, as it allows the weblinks machine name to be editted when a different non-weblinks vocab is the one currently selected for Weblinks navigation. I think it should specifically check on the vocab called 'weblinks' ie the one provided by our module, not the one being used by the module.
Comment #9
GStegemann CreditAttribution: GStegemann commentedYes, you're right.
Comment #10
jonathan1055 CreditAttribution: jonathan1055 commentedThe change is minimal - we simply check the existing machine name #default_value instead of matching on vid.
Here's a patch
Comment #11
GStegemann CreditAttribution: GStegemann commentedI've tested the patch.
But there is still a problem. In case of sites upgraded from D6 for example, the machine of the Web Links navigation vocabulary can be any name. In case of my test site the machine name of this vocabulary is 'vocabulary_9'. How can we address such cases? Assume, that when only one vocabulary term reference field is used in Web Links content type, that this is the navigation vocabulary? Or do you have any other ideas?
Comment #12
jonathan1055 CreditAttribution: jonathan1055 commentedIn weblinks.install we have the function weblinks_update_7000 which looks like it should rename the field to the D7 standard.
Did you run this after converting from D6 to D7?
Comment #13
GStegemann CreditAttribution: GStegemann as a volunteer commentedYes, I know. I have added the update function. It renames the field, but not the machine name of the vocabulary. That's the point. So from that field you should determine the machine name of the Web Links navigation vocabulary. That should possibly work.
Sure.
Comment #14
jonathan1055 CreditAttribution: jonathan1055 commentedI beg your pardon ;-) yes I thought you wrote that function - just checking that you had not forgotten it.
I think that if the vocab machine name is not 'weblinks' then we should not be preventing the rename. The only point of this patch was to retain the name 'weblinks' and if, for whatever reason, that is already no longer the case on a specific site then we should not try any further to identify the actual name. Just leave the form unprotected as it is now.
It should be possible to write another update function to rename the machine name. That would be a good solution, but are we "allowed" to rename a vocabulary machine name that is not "owned" by our module?
Comment #15
GStegemann CreditAttribution: GStegemann as a volunteer commentedNo problem. No, I haven't forgot the function.
A possible approach.
OK, understood now. Initially I thought your intend was to prevent to rename of "Web Links navigation vocabulary" at all.
Yes, since we never then would know what effectively the name of the "Web Links navigaton vocabulary" is.
Only when there would be a mechanism to define the "ownership" of vocabulary. But I think there is no such mechanism. And as far as I know an update function can not interact with the user while running update.php. And how about providing a vocabulary rename feature on the Web Links setting page when the vocab machine name is not 'weblinks'?
Comment #16
GStegemann CreditAttribution: GStegemann as a volunteer commentedAnother thought: when a taxonomy reference field is named 'taxonomy_weblinks' we can assume that this is the reference to the Web Links navigation vocabulary. Which in turn means we can also prevent renaming the vocabulary machine name even the machine name is not 'weblinks'.
Comment #17
jonathan1055 CreditAttribution: jonathan1055 commentedYes you are right, we could do that, but I do not think it would gain us anything. The point about ensuring our vocab was called 'weblinks' was to allow for sensible defaults to work. With the patch in #10 we at least know that for a new D7 install we can rely on this default. For sites migrated from D6 our code should still work in general as we cater for non-weblinks vocabs in all places now. So I think that is enough and we do not need to inhibit renaming when the vocab is not 'weblinks' as that would probably cause more problems than it solves.
This issue will remain as an aid to help support sites if they have any difficulty with non-weblinks vocabs. The discussion above is very valuable for that.
Are you OK if I commit the change from #10 then we call this issue fixed?
Comment #18
GStegemann CreditAttribution: GStegemann as a volunteer commentedOK, convinced. Here my OK to commit the patch.
Comment #20
jonathan1055 CreditAttribution: jonathan1055 commentedExcellent. Thank you.