0

I need some roles to be able to edit and add terms of specific vocabularies, but not to reorder them. How can I add the permission reorder foo vocabulary terms, reorder bar vocabulary terms... with a module or programmatically ?

AFAIK edit terms permissions immediately give you the permissions to reorder terms also.

I already tried these modules below but none implements such permission.

Vocabulary Permissions Per Role

Allows adding to/editing terms of/removing terms from vocabularies per role... adding terms to a vocabulary but not to another, reordering/editing terms of a vocabulary but not another's, etc.

Says so, but reordering /editing come together.

Taxonomy access fix

  • adds 1 permission per vocabulary: "add terms in X"
  • changes the way vocabulary specific permissions are handled
  • changes the Taxonomy admin pages' access checks
  • alters the vocabularies overview table to show only what you have access to edit or delete

The module does what native Taxonomy lacks: more specific Taxonomy permissions (and checking them correctly).

Thank you.

2 Answers 2

1

You need to implement hook_form_alter and remove the Sort alphabetically button based on the role.

Edit: Something like this (tested)

function mymod_form_alter(&$form, &$form_state, $form_id) {
  if (in_array('userrole', $user->roles) && ($form_id == 'taxonomy_overview_terms') {
    unset($form['actions']['reset_alphabetical']);
    drupal_add_css(drupal_get_path('module','mymod').'/css/mymod.css');
  }
}

and in css/mymod.css, do

.handle,.tabledrag-toggle-weight {display:none;}

This hides the Reset to alphabetical button, drag handles, and Show row weights link.

5
  • Thank you. What about the drag and drop UI to reorder almost anything in Drupal including taxonomy terms ? And its alter ego "show row weight" ?
    – Kojo
    Jul 10, 2015 at 14:25
  • You can also use hook_form_alter for that.
    – Kartagis
    Jul 10, 2015 at 14:27
  • @Kojo I updated my answer.
    – Kartagis
    Jul 10, 2015 at 19:05
  • @Kojo Edits should not change an answer's code in a radical way. If you have better code, write your own answer.
    – apaderno
    Jul 14, 2015 at 12:21
  • Thanks Kartagis, for this turn around. By the way, anybody with Firebug or similar could reorder the terms anyway. I posted another solution which really gives or not a permission to reorder vocabulary terms
    – Kojo
    Jul 15, 2015 at 17:22
0

After digging a bit more into permission implementation, this is how I solved this issue, in combination with Taxonomy access fix.

/**
 * Implements hook_permission();
 */
function MYMODULE_permission() {
  return array(
    'reorder_taxonomy_terms' => array(
      'title' => t('Reorder taxonomy terms'),
      'description' => t('Allows users to reorder taxonomy terms.'),
    ),
  );
}

/**
 * Implements hook_js_alter().
 */
function MYMODULE_js_alter(&$javascript) {
  if (!user_access('reorder_taxonomy_terms')) {
    unset($javascript['misc/tabledrag.js']);
  }
}

/**
 * Implements hook_form_FORM_ID_alter();
 */
function MYMODULE_form_taxonomy_overview_terms_alter(&$form, &$form_state, $form_id) {
  global $user;
  if (!user_access('reorder_taxonomy_terms')) {
    foreach($form as $k=>$v){
      if(substr($k, 0, 3) == 'tid'){ 
        unset($form[$k]['weight']);
      }
    }
    unset($form['actions']['reset_alphabetical']);
    drupal_add_css(drupal_get_path('module','vts_taxonomy_permissions').'/MYMODULE.css');

  }
}

/**
 * Implements hook_FORM_ID_alter();
 */
function MYMODULE_form_taxonomy_form_term_alter(&$form, &$form_state, $form_id) {
  global $user; 
  if (!user_access('reorder_taxonomy_terms')){
    unset($form['relations']['weight']);
  }
}

In MYMODULE.css

/* Hide reorder help text */
#block-system-help {
  display: none;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.