function workbench_access_example_taxonomy in Workbench Access 7
Install a test vocabulary.
Multistep process: 1) Tell the user to configure this module. 2) Create our vocabulary. 3) Create some sample terms. 4) Set the active schema for the site. 5) Set all sections to active. 6) Assign the super-user to the main section. 7) Assign all nodes to the main section.
5 calls to workbench_access_example_taxonomy()
- drush_workbench_access_test in ./
workbench_access.drush.inc - Installs the test configuration.
- WorkbenchAccessRoleTestCase::testWorkbenchAccessRoles in tests/
workbench_access.test - WorkbenchAccessTaxonomyTestCase::testWorkbenchAccessTaxonomy in tests/
workbench_access.test - WorkbenchAccessTokenTestCase::testTaxonomyTokens in tests/
workbench_access.test - workbench_access_install_form_submit in ./
workbench_access.admin.inc - Install the sample configuration.
File
- ./
workbench_access.admin.inc, line 912 - Workbench Access admin file.
Code
function workbench_access_example_taxonomy() {
$vocabulary = workbench_access_sample_vocabulary();
$exists = workbench_access_vocabulary_exists($vocabulary);
// If the vocabulary exists, do not create any terms for it.
if ($exists) {
drupal_set_message(t('Workbench Access vocabulary has already been installed.'));
return;
}
// Save.
taxonomy_vocabulary_save($vocabulary);
// Use the proper translation function, in case this is run from the install.
$t = get_t();
// Create some terms.
$terms = array(
$t('Exhibits'),
$t('Library'),
$t('Gift Shop'),
);
$children = array(
$t('Staff'),
$t('Visitors'),
);
// Get the proper filter format for taxonomy descriptions.
$account = new stdClass();
$account->uid = 0;
$account->roles = array(
DRUPAL_ANONYMOUS_RID,
);
$format = filter_default_format($account);
$ids = array(
'workbench_access',
);
$i = -5;
foreach ($terms as $name) {
$term = new stdClass();
$term->name = $name;
$term->vocabulary_machine_name = 'workbench_access';
$term->vid = $vocabulary->vid;
$term->description = $t('Test term for Workbench Access.');
$term->format = $format;
$term->weight = $i;
taxonomy_term_save($term);
$i = $i + 5;
$ids[] = $term->tid;
// Create child terms.
foreach ($children as $child) {
$item = new stdClass();
$item->name = $name . ' ' . $child;
$item->parent = $term->tid;
$item->vocabulary_machine_name = 'workbench_access';
$item->vid = $vocabulary->vid;
$item->format = $format;
$item->description = $t('Test child term for Workbench Access.');
taxonomy_term_save($item);
$ids[] = $item->tid;
}
}
// Set our vocabulary as the default.
variable_set('workbench_access_taxonomy', array(
$vocabulary->machine_name => $vocabulary->machine_name,
));
// Set taxonomy as the active scheme.
variable_set('workbench_access', 'taxonomy');
// Set up the sections.
$section = array(
'access_scheme' => 'taxonomy',
'access_type' => 'taxonomy',
'access_type_id' => $vocabulary->machine_name,
);
foreach ($ids as $id) {
$section['access_id'] = $id;
workbench_access_section_save($section);
}
// Give the admin account access to all sections.
workbench_access_user_section_save(1, 'workbench_access', 'taxonomy');
// Get all nodes and save them to {workbench_access_node}.
$nids = db_query("SELECT nid FROM {node}")
->fetchAll();
$values = array();
foreach ($nids as $nid) {
$values[] = array(
'nid' => $nid->nid,
'access_id' => 'workbench_access',
'access_scheme' => 'taxonomy',
);
}
if (empty($values)) {
return;
}
$query = db_insert('workbench_access_node')
->fields(array(
'nid',
'access_id',
'access_scheme',
));
foreach ($values as $record) {
$query
->values($record);
}
$query
->execute();
drupal_set_message('Sample configuration installed.');
}