I'm having trouble setting a validation constraint on the name of the taxonomy term.
function MYMODULE_entity_bundle_field_info_alter(&$fields, $entity_type, $bundle) {
if ($entity_type->id() === 'taxonomy_term' && $bundle === 'my_taxonomy_type') {
kint($fields['name']);
if (isset($fields['name'])) {
kint('found name');
}
}
}
When I rebuild the cache with drush, kint()
outputs the value of $fields['name']
as null
.
When I use kint()
to output the value of $fields
, I see this:
array (4) [
'parent' => Drupal\Core\Field\BaseFieldDefinition (7) (
protected 'type' -> string (16) "entity_reference"
protected 'propertyDefinitions' -> null
protected 'schema' -> null
protected 'indexes' -> array (0) []
protected 'itemDefinition' -> Drupal\Core\Field\TypedData\FieldItemDataDefinition (3) (
protected 'fieldDefinition' -> Drupal\Core\Field\BaseFieldDefinition (7) RECURSION
protected 'definition' -> array (2) [
'type' => string (27) "field_item:entity_reference"
'settings' => array (3) [
'target_type' => string (13) "taxonomy_term"
'handler' => string (7) "default"
'handler_settings' => array (1) [
'target_bundles' => array (1) DEPTH LIMIT
]
]
]
protected 'typedDataManager' -> null
)
protected 'definition' -> array (7) [
'label' => Drupal\Core\StringTranslation\TranslatableMarkup (5) (
protected 'translatedMarkup' -> null
protected 'options' -> array (0) []
protected 'stringTranslation' -> null
protected 'string' -> string (12) "Term Parents"
protected 'arguments' -> array (0) []
)
'description' => Drupal\Core\StringTranslation\TranslatableMarkup (5) (
protected 'translatedMarkup' -> null
protected 'options' -> array (0) []
protected 'stringTranslation' -> null
protected 'string' -> string (25) "The parents of this term."
protected 'arguments' -> array (0) []
)
'cardinality' => integer -1
'provider' => string (8) "taxonomy"
'field_name' => string (6) "parent"
'entity_type' => string (13) "taxonomy_term"
'bundle' => string (18) "my_taxonomy_type"
]
protected 'typedDataManager' -> null
)
'field_int_count' => Drupal\field\Entity\FieldConfig (35) (
protected 'deleted' -> boolean false
... cut
protected 'id' -> string (56) "taxonomy_term.card_group_private.field_term_date_created"
protected 'field_name' -> string (23) "field_term_date_created"
protected 'field_type' -> string (8) "datetime"
... cut
"taxonomy_term.card_group_private.field_term_ref_author"
protected 'field_name' -> string (21) "field_term_ref_author"
protected 'field_type' -> string (16) "entity_reference"
]
The name
field is nowhere to be found. How can I add a constraint to taxonomy term names?