Same name in this branch
- 10 core/modules/taxonomy/src/Entity/Term.php \Drupal\taxonomy\Entity\Term
- 10 core/modules/taxonomy/src/Plugin/migrate/source/d6/Term.php \Drupal\taxonomy\Plugin\migrate\source\d6\Term
- 10 core/modules/taxonomy/src/Plugin/migrate/source/d7/Term.php \Drupal\taxonomy\Plugin\migrate\source\d7\Term
Same name and namespace in other branches
- 8.9.x core/modules/taxonomy/src/Entity/Term.php \Drupal\taxonomy\Entity\Term
- 9 core/modules/taxonomy/src/Entity/Term.php \Drupal\taxonomy\Entity\Term
Defines the taxonomy term entity.
Plugin annotation
@ContentEntityType(
id = "taxonomy_term",
label = @Translation("Taxonomy term"),
label_collection = @Translation("Taxonomy terms"),
label_singular = @Translation("taxonomy term"),
label_plural = @Translation("taxonomy terms"),
label_count = @PluralTranslation(
singular = "@count taxonomy term",
plural = "@count taxonomy terms",
),
bundle_label = @Translation("Vocabulary"),
handlers = {
"storage" = "Drupal\taxonomy\TermStorage",
"storage_schema" = "Drupal\taxonomy\TermStorageSchema",
"view_builder" = "Drupal\Core\Entity\EntityViewBuilder",
"list_builder" = "Drupal\Core\Entity\EntityListBuilder",
"access" = "Drupal\taxonomy\TermAccessControlHandler",
"views_data" = "Drupal\taxonomy\TermViewsData",
"form" = {
"default" = "Drupal\taxonomy\TermForm",
"delete" = "Drupal\taxonomy\Form\TermDeleteForm",
"revision-delete" = \Drupal\Core\Entity\Form\RevisionDeleteForm::class,
"revision-revert" = \Drupal\Core\Entity\Form\RevisionRevertForm::class,
},
"route_provider" = {
"revision" = \Drupal\Core\Entity\Routing\RevisionHtmlRouteProvider::class,
},
"translation" = "Drupal\taxonomy\TermTranslationHandler"
},
base_table = "taxonomy_term_data",
data_table = "taxonomy_term_field_data",
revision_table = "taxonomy_term_revision",
revision_data_table = "taxonomy_term_field_revision",
show_revision_ui = TRUE,
translatable = TRUE,
entity_keys = {
"id" = "tid",
"revision" = "revision_id",
"bundle" = "vid",
"label" = "name",
"langcode" = "langcode",
"uuid" = "uuid",
"published" = "status",
},
revision_metadata_keys = {
"revision_user" = "revision_user",
"revision_created" = "revision_created",
"revision_log_message" = "revision_log_message",
},
bundle_entity_type = "taxonomy_vocabulary",
field_ui_base_route = "entity.taxonomy_vocabulary.overview_form",
common_reference_target = TRUE,
links = {
"canonical" = "/taxonomy/term/{taxonomy_term}",
"delete-form" = "/taxonomy/term/{taxonomy_term}/delete",
"edit-form" = "/taxonomy/term/{taxonomy_term}/edit",
"create" = "/taxonomy/term",
"revision" = "/taxonomy/term/{taxonomy_term}/revision/{taxonomy_term_revision}/view",
"revision-delete-form" = "/taxonomy/term/{taxonomy_term}/revision/{taxonomy_term_revision}/delete",
"revision-revert-form" = "/taxonomy/term/{taxonomy_term}/revision/{taxonomy_term_revision}/revert",
"version-history" = "/taxonomy/term/{taxonomy_term}/revisions",
},
permission_granularity = "bundle",
collection_permission = "access taxonomy overview",
constraints = {
"TaxonomyHierarchy" = {}
}
)
Hierarchy
- class \Drupal\Core\Entity\EditorialContentEntityBase extends \Drupal\Core\Entity\ContentEntityBase implements EntityChangedInterface, EntityPublishedInterface, RevisionLogInterface uses EntityChangedTrait, EntityPublishedTrait, RevisionLogEntityTrait
- class \Drupal\taxonomy\Entity\Term implements TermInterface
Expanded class hierarchy of Term
51 files declare their use of Term
- CommentTokenReplaceTest.php in core/
modules/ comment/ tests/ src/ Functional/ CommentTokenReplaceTest.php - ContentEntityTest.php in core/
modules/ migrate_drupal/ tests/ src/ Kernel/ Plugin/ migrate/ source/ ContentEntityTest.php - DefaultViewsTest.php in core/
modules/ views/ tests/ src/ Functional/ DefaultViewsTest.php - EntityCrudHookTest.php in core/
tests/ Drupal/ KernelTests/ Core/ Entity/ EntityCrudHookTest.php - EntityFilteringThemeTest.php in core/
modules/ system/ tests/ src/ Functional/ Theme/ EntityFilteringThemeTest.php
2 string references to 'Term'
- forum_views_data in core/
modules/ forum/ forum.views.inc - Implements hook_views_data().
- TermViewsData::getViewsData in core/
modules/ taxonomy/ src/ TermViewsData.php - Returns views data for the entity type.
File
- core/
modules/ taxonomy/ src/ Entity/ Term.php, line 84
Namespace
Drupal\taxonomy\EntityView source
class Term extends EditorialContentEntityBase implements TermInterface {
/**
* {@inheritdoc}
*/
public static function postDelete(EntityStorageInterface $storage, array $entities) {
parent::postDelete($storage, $entities);
// See if any of the term's children are about to be become orphans.
$orphans = [];
/** @var \Drupal\taxonomy\TermInterface $term */
foreach ($entities as $tid => $term) {
if ($children = $storage
->getChildren($term)) {
/** @var \Drupal\taxonomy\TermInterface $child */
foreach ($children as $child) {
$parent = $child
->get('parent');
// Update child parents item list.
$parent
->filter(function ($item) use ($tid) {
return $item->target_id != $tid;
});
// If the term has multiple parents, we don't delete it.
if ($parent
->count()) {
$child
->save();
}
else {
$orphans[] = $child;
}
}
}
}
if (!empty($orphans)) {
$storage
->delete($orphans);
}
}
/**
* {@inheritdoc}
*/
public function preSave(EntityStorageInterface $storage) {
parent::preSave($storage);
// Terms with no parents are mandatory children of <root>.
if (!$this
->get('parent')
->count()) {
$this->parent->target_id = 0;
}
}
/**
* {@inheritdoc}
*/
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
/** @var \Drupal\Core\Field\BaseFieldDefinition[] $fields */
$fields = parent::baseFieldDefinitions($entity_type);
// @todo Remove the usage of StatusItem in
// https://www.drupal.org/project/drupal/issues/2936864.
$fields['status']
->getItemDefinition()
->setClass(StatusItem::class);
$fields['tid']
->setLabel(t('Term ID'))
->setDescription(t('The term ID.'));
$fields['uuid']
->setDescription(t('The term UUID.'));
$fields['status']
->setDisplayOptions('form', [
'type' => 'boolean_checkbox',
'settings' => [
'display_label' => TRUE,
],
'weight' => 100,
])
->setDisplayConfigurable('form', TRUE);
$fields['vid']
->setLabel(t('Vocabulary'))
->setDescription(t('The vocabulary to which the term is assigned.'));
$fields['langcode']
->setDescription(t('The term language code.'));
$fields['name'] = BaseFieldDefinition::create('string')
->setLabel(t('Name'))
->setTranslatable(TRUE)
->setRevisionable(TRUE)
->setRequired(TRUE)
->setSetting('max_length', 255)
->setDisplayOptions('view', [
'label' => 'hidden',
'type' => 'string',
'weight' => -5,
])
->setDisplayOptions('form', [
'type' => 'string_textfield',
'weight' => -5,
])
->setDisplayConfigurable('form', TRUE);
$fields['description'] = BaseFieldDefinition::create('text_long')
->setLabel(t('Description'))
->setTranslatable(TRUE)
->setRevisionable(TRUE)
->setDisplayOptions('view', [
'label' => 'hidden',
'type' => 'text_default',
'weight' => 0,
])
->setDisplayConfigurable('view', TRUE)
->setDisplayOptions('form', [
'type' => 'text_textfield',
'weight' => 0,
])
->setDisplayConfigurable('form', TRUE);
$fields['weight'] = BaseFieldDefinition::create('integer')
->setLabel(t('Weight'))
->setDescription(t('The weight of this term in relation to other terms.'))
->setDefaultValue(0);
$fields['parent'] = BaseFieldDefinition::create('entity_reference')
->setLabel(t('Term Parents'))
->setDescription(t('The parents of this term.'))
->setSetting('target_type', 'taxonomy_term')
->setCardinality(BaseFieldDefinition::CARDINALITY_UNLIMITED);
$fields['changed'] = BaseFieldDefinition::create('changed')
->setLabel(t('Changed'))
->setDescription(t('The time that the term was last edited.'))
->setTranslatable(TRUE)
->setRevisionable(TRUE);
// @todo Keep this field hidden until we have a revision UI for terms.
// @see https://www.drupal.org/project/drupal/issues/2936995
$fields['revision_log_message']
->setDisplayOptions('form', [
'region' => 'hidden',
]);
return $fields;
}
/**
* {@inheritdoc}
*/
public static function bundleFieldDefinitions(EntityTypeInterface $entity_type, $bundle, array $base_field_definitions) {
// Only terms in the same bundle can be a parent.
$fields['parent'] = clone $base_field_definitions['parent'];
$fields['parent']
->setSetting('handler_settings', [
'target_bundles' => [
$bundle => $bundle,
],
]);
return $fields;
}
/**
* {@inheritdoc}
*/
public function getDescription() {
return $this
->get('description')->value;
}
/**
* {@inheritdoc}
*/
public function setDescription($description) {
$this
->set('description', $description);
return $this;
}
/**
* {@inheritdoc}
*/
public function getFormat() {
return $this
->get('description')->format;
}
/**
* {@inheritdoc}
*/
public function setFormat($format) {
$this
->get('description')->format = $format;
return $this;
}
/**
* {@inheritdoc}
*/
public function getName() {
return $this
->label() ?? '';
}
/**
* {@inheritdoc}
*/
public function setName($name) {
$this
->set('name', $name);
return $this;
}
/**
* {@inheritdoc}
*/
public function getWeight() {
return (int) $this
->get('weight')->value;
}
/**
* {@inheritdoc}
*/
public function setWeight($weight) {
$this
->set('weight', $weight);
return $this;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AccessibleInterface:: |
public | function | Checks data value access. | 6 |
CacheableDependencyInterface:: |
public | function | The cache contexts associated with this object. | 19 |
CacheableDependencyInterface:: |
public | function | The maximum age for which this object may be cached. | 19 |
CacheableDependencyInterface:: |
public | function | The cache tags associated with this object. | 12 |
EntityChangedTrait:: |
public | function | Gets the timestamp of the last entity change for the current translation. | |
EntityChangedTrait:: |
public | function | Returns the timestamp of the last entity change across all translations. | |
EntityChangedTrait:: |
public | function | Sets the timestamp of the last entity change for the current translation. | |
EntityInterface:: |
public | function | Gets the bundle of the entity. | 1 |
EntityInterface:: |
public static | function | Constructs a new entity object, without permanently saving it. | 1 |
EntityInterface:: |
public | function | Creates a duplicate of the entity. | 2 |
EntityInterface:: |
public | function | Deletes an entity permanently. | 1 |
EntityInterface:: |
public | function | Enforces an entity to be new. | 1 |
EntityInterface:: |
public | function | Returns the cache tags that should be used to invalidate caches. | 3 |
EntityInterface:: |
public | function | Gets the key that is used to store configuration dependencies. | 1 |
EntityInterface:: |
public | function | Gets the configuration dependency name. | 1 |
EntityInterface:: |
public | function | Gets the configuration target identifier for the entity. | 1 |
EntityInterface:: |
public | function | Gets the ID of the type of the entity. | 1 |
EntityInterface:: |
public | function | Gets the original ID. | 1 |
EntityInterface:: |
public | function | Gets a typed data object for this entity object. | 1 |
EntityInterface:: |
public | function | Indicates if a link template exists for a given key. | 1 |
EntityInterface:: |
public | function | Gets the identifier. | 1 |
EntityInterface:: |
public | function | Determines whether the entity is new. | 1 |
EntityInterface:: |
public | function | Gets the label of the entity. | 3 |
EntityInterface:: |
public | function | Gets the language of the entity. | 1 |
EntityInterface:: |
public static | function | Loads an entity. | 1 |
EntityInterface:: |
public static | function | Loads one or more entities. | 1 |
EntityInterface:: |
public | function | Acts on a created entity before hooks are invoked. | 1 |
EntityInterface:: |
public static | function | Acts on loaded entities. | 2 |
EntityInterface:: |
public | function | Acts on a saved entity before the insert or update hook is invoked. | 8 |
EntityInterface:: |
public static | function | Changes the values of an entity before it is created. | 4 |
EntityInterface:: |
public static | function | Acts on entities before they are deleted and before hooks are invoked. | 6 |
EntityInterface:: |
public | function | Gets a list of entities referenced by this entity. | 2 |
EntityInterface:: |
public | function | Saves an entity permanently. | 3 |
EntityInterface:: |
public | function | Sets the original ID. | 1 |
EntityInterface:: |
public | function | Gets an array of all property values. | 2 |
EntityInterface:: |
public | function | Generates the HTML for a link to this entity. | 1 |
EntityInterface:: |
public | function | Gets the URL object for the entity. | 1 |
EntityInterface:: |
public | function | Gets a list of URI relationships supported by this entity. | 1 |
EntityInterface:: |
public | function | Gets the entity UUID (Universally Unique Identifier). | 1 |
EntityPublishedTrait:: |
public | function | ||
EntityPublishedTrait:: |
public static | function | Returns an array of base field definitions for publishing status. | |
EntityPublishedTrait:: |
public | function | ||
EntityPublishedTrait:: |
public | function | ||
FieldableEntityInterface:: |
public | function | Gets a field item list. | |
FieldableEntityInterface:: |
public | function | Gets the definition of a contained field. | |
FieldableEntityInterface:: |
public | function | Gets an array of field definitions of all contained fields. | |
FieldableEntityInterface:: |
public | function | Gets an array of all field item lists. | |
FieldableEntityInterface:: |
public | function | Gets an array of field item lists for translatable fields. | |
FieldableEntityInterface:: |
public | function | Determines whether the entity has a field with the given name. | |
FieldableEntityInterface:: |
public | function | Checks whether entity validation is required before saving the entity. | |
FieldableEntityInterface:: |
public | function | Reacts to changes to a field. | |
FieldableEntityInterface:: |
public | function | Sets a field value. | |
FieldableEntityInterface:: |
public | function | Sets whether entity validation is required before saving the entity. | |
FieldableEntityInterface:: |
public | function | Validates the currently set values. | 1 |
RefinableCacheableDependencyInterface:: |
public | function | Adds a dependency on an object: merges its cacheability metadata. | |
RefinableCacheableDependencyInterface:: |
public | function | Adds cache contexts. | |
RefinableCacheableDependencyInterface:: |
public | function | Adds cache tags. | |
RefinableCacheableDependencyInterface:: |
public | function | Merges the maximum age (in seconds) with the existing maximum age. | |
RevisionableInterface:: |
public | function | Gets the loaded Revision ID of the entity. | |
RevisionableInterface:: |
public | function | Gets the revision identifier of the entity. | |
RevisionableInterface:: |
public | function | Checks if this entity is the default revision. | |
RevisionableInterface:: |
public | function | Checks if this entity is the latest revision. | |
RevisionableInterface:: |
public | function | Determines whether a new revision should be created on save. | |
RevisionableInterface:: |
public | function | Acts on a revision before it gets saved. | 3 |
RevisionableInterface:: |
public | function | Enforces an entity to be saved as a new revision. | |
RevisionableInterface:: |
public | function | Updates the loaded Revision ID with the revision ID. | |
RevisionableInterface:: |
public | function | Checks whether the entity object was a default revision when it was saved. | |
RevisionLogEntityTrait:: |
abstract public | function | Gets the entity type definition. | |
RevisionLogEntityTrait:: |
public | function | Implements \Drupal\Core\Entity\RevisionLogInterface::getRevisionCreationTime(). | |
RevisionLogEntityTrait:: |
public | function | Implements \Drupal\Core\Entity\RevisionLogInterface::getRevisionLogMessage(). | |
RevisionLogEntityTrait:: |
public | function | Implements \Drupal\Core\Entity\RevisionLogInterface::getRevisionUser(). | |
RevisionLogEntityTrait:: |
public | function | Implements \Drupal\Core\Entity\RevisionLogInterface::getRevisionUserId(). | |
RevisionLogEntityTrait:: |
public static | function | Provides revision-related base field definitions for an entity type. | |
RevisionLogEntityTrait:: |
public | function | Implements \Drupal\Core\Entity\RevisionLogInterface::setRevisionCreationTime(). | |
RevisionLogEntityTrait:: |
public | function | Implements \Drupal\Core\Entity\RevisionLogInterface::setRevisionLogMessage(). | |
RevisionLogEntityTrait:: |
public | function | Implements \Drupal\Core\Entity\RevisionLogInterface::setRevisionUser(). | |
RevisionLogEntityTrait:: |
public | function | Implements \Drupal\Core\Entity\RevisionLogInterface::setRevisionUserId(). | |
SynchronizableInterface:: |
public | function | Returns whether this entity is being changed as part of a synchronization. | |
SynchronizableInterface:: |
public | function | Sets the status of the synchronization flag. | |
Term:: |
public static | function |
Provides base field definitions for an entity type. Overrides EditorialContentEntityBase:: |
|
Term:: |
public static | function |
Provides field definitions for a specific bundle. Overrides FieldableEntityInterface:: |
|
Term:: |
public | function |
Gets the term description. Overrides TermInterface:: |
|
Term:: |
public | function |
Gets the text format name for the term description. Overrides TermInterface:: |
|
Term:: |
public | function |
Gets the term name. Overrides TermInterface:: |
|
Term:: |
public | function |
Gets the term weight. Overrides TermInterface:: |
|
Term:: |
public static | function |
Acts on deleted entities before the delete hook is invoked. Overrides EntityInterface:: |
|
Term:: |
public | function |
Acts on an entity before the presave hook is invoked. Overrides EntityInterface:: |
|
Term:: |
public | function |
Sets the term description. Overrides TermInterface:: |
|
Term:: |
public | function |
Sets the text format name for the term description. Overrides TermInterface:: |
|
Term:: |
public | function |
Sets the term name. Overrides TermInterface:: |
|
Term:: |
public | function |
Sets the term weight. Overrides TermInterface:: |
|
TranslatableInterface:: |
public | function | Adds a new translation to the translatable object. | |
TranslatableInterface:: |
public | function | Gets a translation of the data. | |
TranslatableInterface:: |
public | function | Returns the languages the data is translated to. | |
TranslatableInterface:: |
public | function | Returns the translatable object in the language it was created. | |
TranslatableInterface:: |
public | function | Checks there is a translation for the given language code. | |
TranslatableInterface:: |
public | function | Determines if the current translation of the entity has unsaved changes. | |
TranslatableInterface:: |
public | function | Checks whether the translation is the default one. | |
TranslatableInterface:: |
public | function | Checks whether the translation is new. | |
TranslatableInterface:: |
public | function | Returns the translation support status. | |
TranslatableInterface:: |
public | function | Removes the translation identified by the given language code. | |
TranslatableRevisionableInterface:: |
public | function | Checks if untranslatable fields should affect only the default translation. | |
TranslatableRevisionableInterface:: |
public | function | Checks whether this is the latest revision affecting this translation. | |
TranslatableRevisionableInterface:: |
public | function | Checks whether the current translation is affected by the current revision. | |
TranslatableRevisionableInterface:: |
public | function | Checks if the revision translation affected flag value has been enforced. | |
TranslatableRevisionableInterface:: |
public | function | Marks the current revision translation as affected. | |
TranslatableRevisionableInterface:: |
public | function | Enforces the revision translation affected flag value. |