Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
project
drupal
Commits
8ea359c4
Commit
8ea359c4
authored
Sep 28, 2014
by
webchick
Browse files
Issue
#2346421
by yched: Fixed WTF with getTargetEntityId() / getBundle().
parent
6d27e11a
Changes
10
Hide whitespace changes
Inline
Side-by-side
core/lib/Drupal/Core/Entity/EntityManager.php
View file @
8ea359c4
...
...
@@ -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
->
set
Target
Bundle
(
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
->
set
Target
Bundle
(
$bundle
);
}
}
...
...
core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php
View file @
8ea359c4
...
...
@@ -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
->
getTar
getBundle
())
->
execute
();
if
(
$this
->
entityType
->
isRevisionable
())
{
$this
->
database
->
update
(
$revision_name
)
->
fields
(
array
(
'deleted'
=>
1
))
->
condition
(
'bundle'
,
$field_definition
->
getBundle
())
->
condition
(
'bundle'
,
$field_definition
->
getTar
getBundle
())
->
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
->
getTar
getBundle
())
->
range
(
0
,
$batch_size
);
// Create a map of field data table column names to field column names.
...
...
core/lib/Drupal/Core/Field/BaseFieldDefinition.php
View file @
8ea359c4
...
...
@@ -519,7 +519,7 @@ public function setTargetEntityTypeId($entity_type_id) {
/**
* {@inheritdoc}
*/
public
function
getBundle
()
{
public
function
getTar
getBundle
()
{
return
isset
(
$this
->
definition
[
'bundle'
])
?
$this
->
definition
[
'bundle'
]
:
NULL
;
}
...
...
@@ -531,7 +531,7 @@ public function getBundle() {
*
* @return $this
*/
public
function
setBundle
(
$bundle
)
{
public
function
set
Target
Bundle
(
$bundle
)
{
$this
->
definition
[
'bundle'
]
=
$bundle
;
return
$this
;
}
...
...
core/lib/Drupal/Core/Field/FieldConfigBase.php
View file @
8ea359c4
...
...
@@ -219,7 +219,7 @@ public function getTargetEntityTypeId() {
/**
* {@inheritdoc}
*/
public
function
t
argetBundle
()
{
public
function
getT
argetBundle
()
{
return
$this
->
bundle
;
}
...
...
@@ -425,13 +425,6 @@ public function getItemDefinition() {
return
$this
->
itemDefinition
;
}
/**
* {@inheritdoc}
*/
public
function
getBundle
()
{
return
$this
->
bundle
;
}
/**
* {@inheritdoc}
*/
...
...
core/lib/Drupal/Core/Field/FieldConfigInterface.php
View file @
8ea359c4
...
...
@@ -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.
*
...
...
core/lib/Drupal/Core/Field/FieldDefinitionInterface.php
View file @
8ea359c4
...
...
@@ -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
getTar
getBundle
();
/**
* Returns whether the display for the field can be configured.
...
...
core/lib/Drupal/Core/Field/FieldStorageDefinitionInterface.php
View file @
8ea359c4
...
...
@@ -198,18 +198,18 @@ public function getPropertyNames();
public
function
getMainPropertyName
();
/**
* Returns the ID of the
type of the
entity t
his
field is attached to.
* Returns the ID of the entity t
ype 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
();
...
...
core/modules/config_translation/src/ConfigFieldMapper.php
View file @
8ea359c4
...
...
@@ -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
->
t
argetBundle
();
$parameters
[
$base_entity_info
->
getBundleEntityType
()]
=
$this
->
entity
->
getT
argetBundle
();
return
$parameters
;
}
...
...
core/modules/system/src/Tests/Entity/EntityFieldTest.php
View file @
8ea359c4
...
...
@@ -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'
]
->
getTar
getBundle
());
$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'
]
->
getTar
getBundle
(),
'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'
]
->
getTar
getBundle
(),
'some_test_bundle'
);
$this
->
assertFalse
(
$field_definitions
[
'name'
]
->
isTranslatable
());
}
...
...
core/modules/system/tests/modules/entity_schema_test/entity_schema_test.module
View file @
8ea359c4
...
...
@@ -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
);
->
set
Target
Bundle
(
$bundle
);
// Notify the entity storage that our field is gone.
\
Drupal
::
entityManager
()
->
getStorage
(
$entity_type_id
)
->
onFieldDefinitionDelete
(
$field_definitions
[
'custom_bundle_field'
]);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment