public static function SchemeForm::tacLiteTermSelect in Taxonomy Access Control Lite 8
Helper function to build a taxonomy term select element for a form.
Parameters
object $v: A vocabulary object containing a vid and name.
array $default_values: An array of values to use for the default_value argument for this form element.
2 calls to SchemeForm::tacLiteTermSelect()
- SchemeForm::buildForm in src/
Form/ SchemeForm.php - Form constructor.
- UserAccessForm::buildForm in src/
Form/ UserAccessForm.php - Form constructor.
File
- src/
Form/ SchemeForm.php, line 174
Class
- SchemeForm
- Builds the scheme configuration form.
Namespace
Drupal\tac_lite\FormCode
public static function tacLiteTermSelect($v, $default_values = []) {
$tree = \Drupal::service('entity_type.manager')
->getStorage('taxonomy_term')
->loadTree($v
->get('vid'));
$options = [
0 => '<none>',
];
if ($tree) {
foreach ($tree as $term) {
$choice = new \stdClass();
$choice->option = [
$term->tid => str_repeat('-', $term->depth) . $term->name,
];
$options[] = $choice;
}
}
$field_array = [
'#type' => 'select',
'#title' => $v
->get('name'),
'#default_value' => $default_values,
'#options' => $options,
'#multiple' => TRUE,
'#description' => $v
->get('description'),
];
return $field_array;
}