You are here

function taxonomy_access_enable_vocab in Taxonomy Access Control 7

Enables a vocabulary for the given role.

Parameters

int $vid: The vocabulary ID to enable.

int $rid: The role ID.

Return value

bool TRUE on success, or FALSE on failure.

See also

taxnomomy_access_enable_role()

4 calls to taxonomy_access_enable_vocab()
TaxonomyAccessConfigTest::testTermConfig in ./taxonomy_access.test
Tests configuring specific terms.
TaxonomyAccessConfigTest::testTermWithChildren in ./taxonomy_access.test
Tests adding a term configuration with children.
TaxonomyAccessConfigTest::testVocabularyDefaultConfig in ./taxonomy_access.test
Tests configuring vocabulary defaults.
taxonomy_access_enable_vocab_submit in ./taxonomy_access.admin.inc
Form submission handler for taxonomy_access_admin_role().

File

./taxonomy_access.module, line 461
Allows administrators to specify access control for taxonomy categories.

Code

function taxonomy_access_enable_vocab($vid, $rid) {
  $rid = intval($rid);
  $vid = intval($vid);

  // All valid role IDs are > 0, and we do not enable the global default here.
  if (!$rid || !$vid) {
    return FALSE;
  }

  // Take no action if the vocabulary is already enabled for the role.
  $vocab_status = db_query('SELECT 1
       FROM {taxonomy_access_default}
       WHERE rid = :rid AND vid = :vid', array(
    ':rid' => $rid,
    ':vid' => $vid,
  ))
    ->fetchField();
  if ($vocab_status) {
    return FALSE;
  }

  // Otherwise, initialize the vocabulary default with the global default.
  // Use our API functions so that node access gets updated as needed.
  $global_default = db_query('SELECT grant_view, grant_update, grant_delete, grant_create, grant_list
       FROM {taxonomy_access_default}
       WHERE vid = :vid AND rid = :rid', array(
    ':rid' => $rid,
    ':vid' => TAXONOMY_ACCESS_GLOBAL_DEFAULT,
  ))
    ->fetchAssoc();
  $record = _taxonomy_access_format_grant_record($vid, $rid, $global_default, TRUE);
  return taxonomy_access_set_default_grants(array(
    $vid => $record,
  ));
}