Add new term and add new level are useful permissions, but don't provide as much flexibility as desirable. In order to keep shs itself free of clutter of extra settings to better specify, how about adding an access hook so other's can hook into and determine access/level limits/whatever how they want?

Attach patch adds hook and checks in json callbacks and js whether to add Term. It's done in a way to avoid extra ajax calls or avoiding changing any of the behaviour/performance for those not using this hook.

Comments

stborchert’s picture

Status: Needs review » Fixed

Wow this works like a charm.
Thanks for the patch, I've committed it right now.

Here is a sample implementation of hook_shs_add_term_access():

<?php
/**
 * Implements hook_shs_add_term_access().
 */
function shs_access_shs_add_term_access($vid, $parent, $account) {
  if ($parent == 2 || $parent == 0) {
    return FALSE;
  }
  return TRUE;
}
?>

Status: Fixed » Closed (fixed)

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

Grayside’s picture

Status: Closed (fixed) » Needs work
StatusFileSize
new11.19 KB

Something in the logic of how this is called is broken. I have a term (with tid 24) that I am trying to use to represent an "Other" option to which you can add more elements.

/**
 * Implements hook_shs_add_term_access().
 */
function custom_shs_add_term_access($vid, $tid, $account) {
  $vocab = taxonomy_vocabulary_load($vid);
  if ($vocab->machine_name == 'article_type') {
  	return $tid && $tid == variable_get('sn_article_other_term_tid', 24);
  }
}

Here are the field settings I am using. I have tried this with and without allowing the creation of new levels.
SHS Field Settings

When a view the JS settings, I see that the create new option appears to be set to false, despite

shs_add_term_access()

returning TRUE when it is given the correct $tid. My working theory is that somewhere there is a caching problem or that somewhere the tid is not being passed along.

Having beaten my head against a wall for a while on this, I am documenting this here to return later.

stborchert’s picture

Status: Needs work » Fixed

There was a small error that generally disables creating new terms if other modules tries to control access. I've committed a fix so it works now as expected.

Grayside’s picture

I just downloaded latest -dev and it worked.

Status: Fixed » Closed (fixed)

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