Notice: Undefined variable: vocabulary in term_permissions_form_alter() (line 152 of /...mysite.../sites/all/modules/term_permissions/term_permissions.module).

i am system admin ( i have all the permissions ) and i have set my roll to have access to all taxonomy terms but i am getting this error ...

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Exlord’s picture

i am not sure whats wrong with ur queries but both of the are returning false.
i changed the queries and they seems to be working dine now ...
line 261: function term_permissions_allowed :

$query = db_select('term_permissions_user', 't')
        ->fields('t', array('uid'))
        ->condition('t.tid', $tid)
        ->condition('t.uid', $user->uid);
    $users = $query->execute()->fetchField();
    $query = db_select('term_permissions_role', 't')
        ->fields('t', array('rid'))
        ->condition('t.tid', $tid)
        ->condition('t.rid', array_keys($user->roles), 'IN');
    $roles = $query->execute()->fetchField();
    if ($users || $roles) {
        return TRUE;
    }
MiSc’s picture

@Exlord, could you please add a patch for the fix?

anavrin’s picture

Hi there, I had the same problem:

Notice: Undefined variable: vocabulary in term_permissions_form_alter() ...
The problem is when (at least in my case) user has permission to only one term in a vocab. Have no idea why in the condition:
if (count($options) <= 1) was less or equal ?

it sould be if (count($options) < 1) - because sometimes user is allowed only one value ...
Changing this solved my problem. I also used a more redable form me version of code sent by Exlord #1 ...

So my whole modification looked like this:

if (count($options) < 1) {

and

	$query = db_select('term_permissions_user', 't')
        ->fields('t', array('uid'))
        ->condition('t.tid', $tid)
        ->condition('t.uid', $user->uid);
    $users = $query->execute()->fetchField();
	
	$query = db_select('term_permissions_role', 't')
        ->fields('t', array('rid'))
        ->condition('t.tid', $tid)
        ->condition('t.rid', array_keys($user->roles), 'IN');
    $roles = $query->execute()->fetchField();
  
	if ($users || $roles) {
        //debug_msg($roles);
		return TRUE;

instead of

  if (db_query("SELECT uid FROM {term_permissions_user} WHERE tid = :tid AND uid = :uid",
  array(':tid' => $tid, ':uid' => $user->uid))->fetchField() ||
      db_query("SELECT rid FROM {term_permissions_role} WHERE tid = :tid AND rid IN (:user_roles)",
  array(':tid' => $tid, ':user_roles' => $user_roles[$i]))->fetchField()) {
    return TRUE;
anavrin’s picture

and no matter what there should be some exception catch added in the situation when user is not allowed to the field at all ...

drasgardian’s picture

Version: 7.x-1.0-beta1 » 7.x-1.x-dev
Assigned: Exlord » Unassigned
Status: Active » Needs review
FileSize
3.63 KB

Attached is a patch against the latest dev implementing the work from #3 and also addressing #4 by denying the user access to the form if they do not have permissions for any of the terms and the field is required.

matthiasm11’s picture

Hi

When i read through the #5 patch, I think there is a closing parentheses  missing:

vocabulary.', array('%user' => isset($user->name) ? $user->name : variable_get('anonymous', 'Anonymous'),

should be

vocabulary.', array('%user' => isset($user->name) ? $user->name : variable_get('anonymous', 'Anonymous')),

The patch works fine.

gmasky’s picture

Issue summary: View changes

Has this been fixed in the core module? I am still getting this error here http://www.jaaindia.com/user/register

gmasky’s picture

Never mind. I had a field in the registration form and had not given permission to anonymous users to access the field.

AaronMcHale’s picture

I'm getting this same error when using the Pollfield module, using the latest 7.x release of both of these modules. I'm not sure if the issue is with this module or Pollfield though.

Any help would be appreciated

Camario39’s picture

Im not sure if this is related, but as a non admin user with permission to only a single term. If the user does not have access to the DEFAULT term selected in the manage fields section, then this error will display.

removing the default fixed the issue for me.

  • roborn committed 3c5f90e on 7.x-1.x
    Issue #1776178 by drasgardian, anavrin, Exlord: Undefined variable:...
roborn’s picture

Status: Needs review » Closed (fixed)

Patch on #5, we need to verify if permissions are enabled for the term and update code from 6.x

I fixed that and committed it.
Thank you, guys :)