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?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

GStegemann’s picture

You are right. As of current the vocabulary machine name should not be renamed. Good idea to disable the filed by form_alter hook.

jonathan1055’s picture

Three 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.

GStegemann’s picture

Status: Needs review » Reviewed & tested by the community

Sorry, I forgot to test. Works. Thanks.

  • jonathan1055 committed f5c0459 on 7.x-1.x
    Issue #2425859 by jonathan1055: Do not allow admins to edit the weblinks...
jonathan1055’s picture

Status: Reviewed & tested by the community » Fixed

Thanks.

jonathan1055’s picture

The commit above has not yet appeared in the dev release which still shows:

Last updated: March 4, 2015 - 17:18
Last packaged version: 7.x-1.0-alpha2+34-dev

This is just a reminder after the next commit to check that this change is also included.

[update: yes this commit is included now]

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

jonathan1055’s picture

Status: Closed (fixed) » Needs work

I'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.

GStegemann’s picture

Yes, you're right.

jonathan1055’s picture

Status: Needs work » Needs review
FileSize
534 bytes

The change is minimal - we simply check the existing machine name #default_value instead of matching on vid.

Here's a patch

GStegemann’s picture

I'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?

jonathan1055’s picture

In weblinks.install we have the function weblinks_update_7000 which looks like it should rename the field to the D7 standard.

/**
 * Rename field to 'taxonomy_weblinks'.
 */
function weblinks_update_7000() {
  $new_field_name = 'taxonomy_weblinks';
  // Test to see if the taxonomy_weblinks field exists.
  $fields = _update_7000_field_read_fields(array('field_name' => $new_field_name));
  if ($fields) {
    // Since the field exists, we're done.
    return;
  }
  // Calculate the old field name.
  $vid = variable_get('weblinks_nav_vocabulary', 0);
...

Did you run this after converting from D6 to D7?

GStegemann’s picture

In weblinks.install we have the function weblinks_update_7000 which looks like it should rename the field to the D7 standard.

Yes, 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.

Did you run this after converting from D6 to D7?

Sure.

jonathan1055’s picture

I 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?

GStegemann’s picture

just checking that you had not forgotten it.

No problem. No, I haven't forgot the function.

I think that if the vocab machine name is not 'weblinks' then we should not be preventing the rename.

A possible approach.

The only point of this patch was to retain the name 'weblinks'

OK, understood now. Initially I thought your intend was to prevent to rename of "Web Links navigation vocabulary" at all.

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.

Yes, since we never then would know what effectively the name of the "Web Links navigaton vocabulary" is.

That would be a good solution, but are we "allowed" to rename a vocabulary machine name that is not "owned" by our module?

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'?

GStegemann’s picture

That would be a good solution, but are we "allowed" to rename a vocabulary machine name that is not "owned" by our module?

Another 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'.

jonathan1055’s picture

Which in turn means we can also prevent renaming the vocabulary machine name even the machine name is not 'weblinks'.

Yes 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?

GStegemann’s picture

Status: Needs review » Reviewed & tested by the community

OK, convinced. Here my OK to commit the patch.

  • jonathan1055 committed d0fd9e3 on 7.x-1.x
    Issue #2425859 by jonathan1055, GStegemann: Do not allow admin to edit...
jonathan1055’s picture

Status: Reviewed & tested by the community » Fixed

Excellent. Thank you.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.