Provides specific access control for the taxonomy_term entity type.
@Plugin(
id = "taxonomy_term_default",
module = "taxonomy",
label = @Translation("Taxonomy Term selection"),
entity_types = {"taxonomy_term"},
group = "default",
weight = 1
)
Expanded class hierarchy of TermSelection
class TermSelection extends SelectionBase {
/**
* Overrides SelectionBase::entityQueryAlter().
*/
public function entityQueryAlter(SelectInterface $query) {
// @todo: How to set access, as vocabulary is now config?
}
/**
* Overrides SelectionBase::settingsForm().
*/
public static function settingsForm(&$field, &$instance) {
$form = parent::settingsForm($field, $instance);
// @todo: Currently allow auto-create only on taxonomy terms.
$form['auto_create'] = array(
'#type' => 'checkbox',
'#title' => t("Create referenced entities if they don't already exist"),
'#default_value' => $instance['settings']['handler_settings']['auto_create'],
);
return $form;
}
/**
* Overrides SelectionBase::getReferencableEntities().
*/
public function getReferencableEntities($match = NULL, $match_operator = 'CONTAINS', $limit = 0) {
if ($match || $limit) {
return parent::getReferencableEntities($match, $match_operator, $limit);
}
$options = array();
$bundles = entity_get_bundles('taxonomy_term');
$bundle_names = !empty($this->instance['settings']['handler_settings']['target_bundles']) ? $this->instance['settings']['handler_settings']['target_bundles'] : array_keys($bundles);
foreach ($bundle_names as $bundle) {
if ($vocabulary = entity_load('taxonomy_vocabulary', $bundle)) {
if ($terms = taxonomy_get_tree($vocabulary
->id(), 0)) {
foreach ($terms as $term) {
$options[$vocabulary
->id()][$term
->id()] = str_repeat('-', $term->depth) . check_plain($term->name);
}
}
}
}
return $options;
}
}
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
SelectionBase:: |
protected | property | The entity object, or NULL | |
SelectionBase:: |
protected | property | The field array. | |
SelectionBase:: |
protected | property | The instance array. | |
SelectionBase:: |
public | function | Builds an EntityQuery to get referencable entities. | 4 |
SelectionBase:: |
public | function |
Implements SelectionInterface::countReferencableEntities(). Overrides SelectionInterface:: |
|
SelectionBase:: |
protected | function | Helper method: Passes a query to the alteration system again. | |
SelectionBase:: |
public | function |
Implements SelectionInterface::validateAutocompleteInput(). Overrides SelectionInterface:: |
|
SelectionBase:: |
public | function |
Implements SelectionInterface::validateReferencableEntities(). Overrides SelectionInterface:: |
|
SelectionBase:: |
public | function | Constructs a SelectionBase object. | |
TermSelection:: |
public | function |
Overrides SelectionBase::entityQueryAlter(). Overrides SelectionBase:: |
|
TermSelection:: |
public | function |
Overrides SelectionBase::getReferencableEntities(). Overrides SelectionBase:: |
|
TermSelection:: |
public static | function |
Overrides SelectionBase::settingsForm(). Overrides SelectionBase:: |