diff -r 07239de796bb -r e756a8c72c3d cms/drupal/sites/all/modules/vppr/vppr.module --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cms/drupal/sites/all/modules/vppr/vppr.module Fri Sep 08 12:04:06 2017 +0200 @@ -0,0 +1,131 @@ +machine_name . ' vocabulary terms')) { + return TRUE; + } + return FALSE; +} + +/** + * Return edit access for a given term. + */ +function vppr_access_term_edit($term) { + if (taxonomy_term_edit_access($term) || user_access('administer ' . $term->vocabulary_machine_name . ' vocabulary terms')) { + return TRUE; + } + return FALSE; +} + +/** + * Return delete access for a given term. + */ +function vppr_access_term_delete($term) { + if (user_access('administer taxonomy') || user_access("delete terms in $term->vid") || user_access('administer ' . $term->vocabulary_machine_name . ' vocabulary terms')) { + return TRUE; + } + return FALSE; +} + +/** + * Implements hook_form_FORM_ID_alter(). + */ +function vppr_form_taxonomy_form_term_alter(&$form, &$form_state) { + if (isset($form['tid']['#value']) && isset($form['actions']['delete']['#access']) && isset($form['#term'])) { + $form['actions']['delete']['#access'] = vppr_access_term_delete((object) $form['#term']); + } +} + +/** + * Implements hook_permission(). + */ +function vppr_permission() { + $perms = array(); + $vocabularies = taxonomy_get_vocabularies(); + foreach ($vocabularies as $vocabulary) { + $perms['administer ' . $vocabulary->machine_name . ' vocabulary terms'] = array( + 'title' => t('Administer %name vocabulary terms', array('%name' => $vocabulary->name)), + ); + } + return $perms; +} + +/** + * Implements hook_taxonomy_vocabulary_update(). + */ +function vppr_taxonomy_vocabulary_update($vocabulary) { + if ($vocabulary->old_machine_name != $vocabulary->machine_name) { + db_update('role_permission') + ->fields(array( + 'permission' => 'administer ' . $vocabulary->machine_name . ' vocabulary terms', + )) + ->condition('permission', 'administer ' . $vocabulary->old_machine_name . ' vocabulary terms') + ->execute(); + + // Clear the user access cache. + drupal_static_reset('user_access'); + drupal_static_reset('user_role_permissions'); + } +} + +/** + * Implements hook_taxonomy_vocabulary_delete(). + */ +function vppr_taxonomy_vocabulary_delete($vocabulary) { + db_delete('role_permission') + ->condition('permission', 'administer ' . $vocabulary->machine_name . ' vocabulary terms') + ->execute(); + + // Clear the user access cache. + drupal_static_reset('user_access'); + drupal_static_reset('user_role_permissions'); +}