Commit 8ea359c4 authored by webchick's avatar webchick

Issue #2346421 by yched: Fixed WTF with getTargetEntityId() / getBundle().

parent 6d27e11a
......@@ -405,7 +405,7 @@ protected function buildBaseFieldDefinitions($entity_type_id) {
if ($base_field_definition instanceof BaseFieldDefinition) {
$base_field_definition->setName($field_name);
$base_field_definition->setTargetEntityTypeId($entity_type_id);
$base_field_definition->setBundle(NULL);
$base_field_definition->setTargetBundle(NULL);
}
}
......@@ -518,7 +518,7 @@ protected function buildBundleFieldDefinitions($entity_type_id, $bundle, array $
if ($field_definition instanceof BaseFieldDefinition) {
$field_definition->setName($field_name);
$field_definition->setTargetEntityTypeId($entity_type_id);
$field_definition->setBundle($bundle);
$field_definition->setTargetBundle($bundle);
}
}
......
......@@ -1531,12 +1531,12 @@ public function onFieldDefinitionDelete(FieldDefinitionInterface $field_definiti
$revision_name = $table_mapping->getDedicatedRevisionTableName($storage_definition);
$this->database->update($table_name)
->fields(array('deleted' => 1))
->condition('bundle', $field_definition->getBundle())
->condition('bundle', $field_definition->getTargetBundle())
->execute();
if ($this->entityType->isRevisionable()) {
$this->database->update($revision_name)
->fields(array('deleted' => 1))
->condition('bundle', $field_definition->getBundle())
->condition('bundle', $field_definition->getTargetBundle())
->execute();
}
}
......@@ -1606,7 +1606,7 @@ protected function readFieldItemsToPurge(FieldDefinitionInterface $field_definit
$entity_query
->distinct(TRUE)
->fields('t', array('entity_id'))
->condition('bundle', $field_definition->getBundle())
->condition('bundle', $field_definition->getTargetBundle())
->range(0, $batch_size);
// Create a map of field data table column names to field column names.
......
......@@ -519,7 +519,7 @@ public function setTargetEntityTypeId($entity_type_id) {
/**
* {@inheritdoc}
*/
public function getBundle() {
public function getTargetBundle() {
return isset($this->definition['bundle']) ? $this->definition['bundle'] : NULL;
}
......@@ -531,7 +531,7 @@ public function getBundle() {
*
* @return $this
*/
public function setBundle($bundle) {
public function setTargetBundle($bundle) {
$this->definition['bundle'] = $bundle;
return $this;
}
......
......@@ -219,7 +219,7 @@ public function getTargetEntityTypeId() {
/**
* {@inheritdoc}
*/
public function targetBundle() {
public function getTargetBundle() {
return $this->bundle;
}
......@@ -425,13 +425,6 @@ public function getItemDefinition() {
return $this->itemDefinition;
}
/**
* {@inheritdoc}
*/
public function getBundle() {
return $this->bundle;
}
/**
* {@inheritdoc}
*/
......
......@@ -51,14 +51,6 @@ public function setTranslatable($translatable);
*/
public function allowBundleRename();
/**
* Returns the name of the bundle this field is attached to.
*
* @return string
* The name of the bundle this field is attached to.
*/
public function targetBundle();
/**
* Sets a default value.
*
......
......@@ -75,6 +75,22 @@ public function getName();
*/
public function getType();
/**
* Returns the ID of the entity type the 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 entity type ID.
*/
public function getTargetEntityTypeId();
/**
* Gets the bundle the field is defined for.
*
......@@ -82,7 +98,7 @@ public function getType();
* The bundle the field is defined for, or NULL if it is a base field; i.e.,
* it is not bundle-specific.
*/
public function getBundle();
public function getTargetBundle();
/**
* Returns whether the display for the field can be configured.
......
......@@ -198,18 +198,18 @@ public function getPropertyNames();
public function getMainPropertyName();
/**
* Returns the ID of the type of the entity this field is attached to.
* Returns the ID of the entity type the field is attached to.
*
* This method should not be confused with EntityInterface::entityType()
* (configurable fields are config entities, and thus implement both
* interfaces):
* - FieldStorageDefinitionInterface::getTargetEntityTypeId() answers "as a
* field, which entity type are you attached to?".
* field storage, which entity type are you attached to?".
* - EntityInterface::getEntityTypeId() answers "as a (config) entity, what
* is your own entity type".
* is your own entity type?".
*
* @return string
* The name of the entity type.
* The entity type ID.
*/
public function getTargetEntityTypeId();
......
......@@ -30,7 +30,7 @@ class ConfigFieldMapper extends ConfigEntityMapper {
public function getBaseRouteParameters() {
$parameters = parent::getBaseRouteParameters();
$base_entity_info = $this->entityManager->getDefinition($this->pluginDefinition['base_entity_type']);
$parameters[$base_entity_info->getBundleEntityType()] = $this->entity->targetBundle();
$parameters[$base_entity_info->getBundleEntityType()] = $this->entity->getTargetBundle();
return $parameters;
}
......
......@@ -594,11 +594,11 @@ public function testFieldOverrideBundleField() {
entity_test_create_bundle('some_test_bundle', 'Some test bundle', 'entity_test_field_override');
$field_definitions = $this->entityManager->getFieldDefinitions('entity_test_field_override', 'entity_test_field_override');
$this->assertEqual($field_definitions['name']->getDescription(), 'The default description.');
$this->assertNull($field_definitions['name']->getBundle());
$this->assertNull($field_definitions['name']->getTargetBundle());
$field_definitions = $this->entityManager->getFieldDefinitions('entity_test_field_override', 'some_test_bundle');
$this->assertEqual($field_definitions['name']->getDescription(), 'Custom description.');
$this->assertEqual($field_definitions['name']->getBundle(), 'some_test_bundle');
$this->assertEqual($field_definitions['name']->getTargetBundle(), 'some_test_bundle');
// Now create a config override of the bundle field.
$field_config = $field_definitions['name']->getConfig('some_test_bundle');
......@@ -609,7 +609,7 @@ public function testFieldOverrideBundleField() {
$this->entityManager->clearCachedFieldDefinitions();
$field_definitions = $this->entityManager->getFieldDefinitions('entity_test_field_override', 'some_test_bundle');
$this->assertEqual($field_definitions['name']->getDescription(), 'Custom description.');
$this->assertEqual($field_definitions['name']->getBundle(), 'some_test_bundle');
$this->assertEqual($field_definitions['name']->getTargetBundle(), 'some_test_bundle');
$this->assertFalse($field_definitions['name']->isTranslatable());
}
......
......@@ -71,7 +71,7 @@ function entity_schema_test_entity_bundle_delete($entity_type_id, $bundle) {
$field_definitions = entity_schema_test_entity_bundle_field_info($entity_type, $bundle);
$field_definitions['custom_bundle_field']
->setTargetEntityTypeId($entity_type_id)
->setBundle($bundle);
->setTargetBundle($bundle);
// Notify the entity storage that our field is gone.
\Drupal::entityManager()->getStorage($entity_type_id)
->onFieldDefinitionDelete($field_definitions['custom_bundle_field']);
......
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