diff --git a/modules/taxonomy/taxonomy.admin.inc b/modules/taxonomy/taxonomy.admin.inc index 6f72f4d..39ef5a7 100644 --- a/modules/taxonomy/taxonomy.admin.inc +++ b/modules/taxonomy/taxonomy.admin.inc @@ -768,7 +768,7 @@ function taxonomy_form_term($form, &$form_state, $edit = array(), $vocabulary = $form['actions']['delete'] = array( '#type' => 'submit', '#value' => t('Delete'), - '#access' => user_access("delete terms in $vocabulary->machine_name") || user_access('administer taxonomy'), + '#access' => user_access('delete terms in ' . _taxonomy_vocabulary_permissions_machine_name_hash($vocabulary->machine_name)) || user_access('administer taxonomy'), '#weight' => 10, ); } diff --git a/modules/taxonomy/taxonomy.module b/modules/taxonomy/taxonomy.module index 6e298af..fef0e03 100644 --- a/modules/taxonomy/taxonomy.module +++ b/modules/taxonomy/taxonomy.module @@ -71,13 +71,14 @@ function taxonomy_permission() { ), ); foreach (taxonomy_get_vocabularies() as $vocabulary) { + $machine_name = _taxonomy_vocabulary_permissions_machine_name_hash($vocabulary->machine_name); $permissions += array( - 'edit terms in ' . $vocabulary->machine_name => array( + 'edit terms in ' . $machine_name => array( 'title' => t('Edit terms in %vocabulary', array('%vocabulary' => $vocabulary->name)), ), ); $permissions += array( - 'delete terms in ' . $vocabulary->machine_name => array( + 'delete terms in ' . $machine_name => array( 'title' => t('Delete terms from %vocabulary', array('%vocabulary' => $vocabulary->name)), ), ); @@ -378,7 +379,7 @@ function taxonomy_term_edit_access($term) { $vocabulary = taxonomy_vocabulary_load($term->vid); $term->vocabulary_machine_name = $vocabulary->machine_name; } - return user_access("edit terms in $term->vocabulary_machine_name"); + return user_access('edit terms in ' . _taxonomy_vocabulary_permissions_machine_name_hash($term->vocabulary_machine_name)); } /** @@ -395,6 +396,26 @@ function taxonomy_admin_vocabulary_title_callback($vocabulary) { } /** + * Hash the machine name to avoid it being longer than 112 characters. + * + * This function in used for permissions because vocabularies machine names can + * be up to 255 chars but permissions are limited to 128 chars. The 112 chars + * limited is calculated to fit with the "delete terms in [machine_name]" + * permission. + * + * @param $machine_name + * The machine name. + * @return + * The machine name hashed to fit the 112 chars limit if needed. + */ +function _taxonomy_vocabulary_permissions_machine_name_hash($machine_name) { + if (drupal_strlen($machine_name) > 112) { + $machine_name = drupal_substr($machine_name, 0, 79) . '-' . md5($machine_name); + } + return $machine_name; +} + +/** * Changes the machine name in vocabulary's permissions. * * @param $old @@ -407,6 +428,7 @@ function taxonomy_vocabulary_permissions_machine_name_change($old, $new) { if ($old == $new) { return; } + $new = _taxonomy_vocabulary_permissions_machine_name_hash($new); $prefixes = array( 'edit terms in ', 'delete terms in ',