function EntityReferenceItem::schema
Same name in other branches
- 9 core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EntityReferenceItem.php \Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem::schema()
- 8.9.x core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EntityReferenceItem.php \Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem::schema()
- 11.x core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EntityReferenceItem.php \Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem::schema()
1 method overrides EntityReferenceItem::schema()
- FileItem::schema in core/
modules/ file/ src/ Plugin/ Field/ FieldType/ FileItem.php
File
-
core/
lib/ Drupal/ Core/ Field/ Plugin/ Field/ FieldType/ EntityReferenceItem.php, line 166
Class
- EntityReferenceItem
- Defines the 'entity_reference' entity field type.
Namespace
Drupal\Core\Field\Plugin\Field\FieldTypeCode
public static function schema(FieldStorageDefinitionInterface $field_definition) {
$target_type = $field_definition->getSetting('target_type');
try {
$target_type_info = \Drupal::entityTypeManager()->getDefinition($target_type);
} catch (PluginNotFoundException $e) {
throw new FieldException(sprintf("Field '%s' on entity type '%s' references a target entity type '%s' which does not exist.", $field_definition->getName(), $field_definition->getTargetEntityTypeId(), $target_type));
}
$properties = static::propertyDefinitions($field_definition)['target_id'];
if ($target_type_info->entityClassImplements(FieldableEntityInterface::class) && $properties->getDataType() === 'integer') {
$columns = [
'target_id' => [
'description' => 'The ID of the target entity.',
'type' => 'int',
'unsigned' => TRUE,
],
];
}
else {
$columns = [
'target_id' => [
'description' => 'The ID of the target entity.',
'type' => 'varchar_ascii',
// If the target entities act as bundles for another entity type,
// their IDs should not exceed the maximum length for bundles.
'length' => $target_type_info->getBundleOf() ? EntityTypeInterface::BUNDLE_MAX_LENGTH : 255,
],
];
}
$schema = [
'columns' => $columns,
'indexes' => [
'target_id' => [
'target_id',
],
],
];
return $schema;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.