Commit 4d166e5e authored by catch's avatar catch

Issue #2134967 by plopesc, swentel, chx: FieldDefinitionInterface should...

Issue #2134967 by plopesc, swentel, chx: FieldDefinitionInterface should include a getTargetEntityTypeId().
parent c9164063
...@@ -309,8 +309,12 @@ public function getFieldDefinitions($entity_type_id, $bundle = NULL) { ...@@ -309,8 +309,12 @@ public function getFieldDefinitions($entity_type_id, $bundle = NULL) {
$entity_type = $this->getDefinition($entity_type_id); $entity_type = $this->getDefinition($entity_type_id);
$class = $entity_type->getClass(); $class = $entity_type->getClass();
$base_definitions = $class::baseFieldDefinitions($entity_type_id);
foreach ($base_definitions as &$base_definition) {
$base_definition->setTargetEntityTypeId($entity_type_id);
}
$this->entityFieldInfo[$entity_type_id] = array( $this->entityFieldInfo[$entity_type_id] = array(
'definitions' => $class::baseFieldDefinitions($entity_type_id), 'definitions' => $base_definitions,
// Contains definitions of optional (per-bundle) fields. // Contains definitions of optional (per-bundle) fields.
'optional' => array(), 'optional' => array(),
// An array keyed by bundle name containing the optional fields added // An array keyed by bundle name containing the optional fields added
......
...@@ -285,6 +285,27 @@ public function getDefaultValue(EntityInterface $entity) { ...@@ -285,6 +285,27 @@ public function getDefaultValue(EntityInterface $entity) {
return $this->getSetting('default_value'); return $this->getSetting('default_value');
} }
/**
* {@inheritdoc}
*/
public function getTargetEntityTypeId() {
return isset($this->definition['entity_type']) ? $this->definition['entity_type'] : NULL;
}
/**
* Sets the ID of the type of the entity this field is attached to.
*
* @param string $entity_type_id
* The name of the target entity type to set.
*
* @return static
* The object itself for chaining.
*/
public function setTargetEntityTypeId($entity_type_id) {
$this->definition['entity_type'] = $entity_type_id;
return $this;
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
......
...@@ -255,6 +255,22 @@ public function isMultiple(); ...@@ -255,6 +255,22 @@ public function isMultiple();
*/ */
public function getDefaultValue(EntityInterface $entity); public function getDefaultValue(EntityInterface $entity);
/**
* Returns the ID of the type of the entity this field is attached to.
*
* This method should not be confused with EntityInterface::entityType()
* (configurable fields are config entities, and thus implement both
* interfaces):
* - FieldDefinitionInterface::getTargetEntityTypeId() answers "as a field,
* which entity type are you attached to?".
* - EntityInterface::getEntityTypeId() answers "as a (config) entity, what
* is your own entity type".
*
* @return string
* The name of the entity type.
*/
public function getTargetEntityTypeId();
/** /**
* Returns the field schema. * Returns the field schema.
* *
......
...@@ -641,6 +641,13 @@ public function getDisplayOptions($display_context) { ...@@ -641,6 +641,13 @@ public function getDisplayOptions($display_context) {
return array('type' => 'hidden'); return array('type' => 'hidden');
} }
/**
* {@inheritdoc}
*/
public function getTargetEntityTypeId() {
return $this->entity_type;
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
......
...@@ -598,6 +598,13 @@ public function getDisplayOptions($display_context) { ...@@ -598,6 +598,13 @@ public function getDisplayOptions($display_context) {
return array('type' => 'hidden'); return array('type' => 'hidden');
} }
/**
* {@inheritdoc}
*/
public function getTargetEntityTypeId() {
return $this->entity_type;
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment