diff --git a/core/lib/Drupal/Core/Entity/ContentEntityBase.php b/core/lib/Drupal/Core/Entity/ContentEntityBase.php index 5ecff41..82e5241 100644 --- a/core/lib/Drupal/Core/Entity/ContentEntityBase.php +++ b/core/lib/Drupal/Core/Entity/ContentEntityBase.php @@ -987,7 +987,7 @@ public function referencedEntities() { /** * {@inheritdoc} */ - public static function fieldDefinitionsByBundle(EntityTypeInterface $entity_type, $bundle, array $base_field_definitions) { + public static function bundleFieldDefinitions(EntityTypeInterface $entity_type, $bundle, array $base_field_definitions) { return array(); } diff --git a/core/lib/Drupal/Core/Entity/ContentEntityInterface.php b/core/lib/Drupal/Core/Entity/ContentEntityInterface.php index 9478b4e..d6c1e0f 100644 --- a/core/lib/Drupal/Core/Entity/ContentEntityInterface.php +++ b/core/lib/Drupal/Core/Entity/ContentEntityInterface.php @@ -62,7 +62,7 @@ public function initTranslation($langcode); * name. * * @see \Drupal\Core\Entity\EntityManagerInterface::getFieldDefinitions() - * @see \Drupal\Core\Entity\ContentEntityInterface::fieldDefinitionsByBundle() + * @see \Drupal\Core\Entity\ContentEntityInterface::bundleFieldDefinitions() */ public static function baseFieldDefinitions(EntityTypeInterface $entity_type); @@ -82,15 +82,15 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type); * @param string $bundle * The bundle. * @param \Drupal\Core\Field\FieldDefinitionInterface[] $base_field_definitions - * The list of field definitions for the bundle. + * The list of base field definitions. * * @return \Drupal\Core\Field\FieldDefinitionInterface[] - * An array of field definitions for the bundle, keyed by field name. + * An array of bundle field definitions, keyed by field name. * * @see \Drupal\Core\Entity\EntityManagerInterface::getFieldDefinitions() * @see \Drupal\Core\Entity\ContentEntityInterface::baseFieldDefinitions() */ - public static function fieldDefinitionsByBundle(EntityTypeInterface $entity_type, $bundle, array $base_field_definitions); + public static function bundleFieldDefinitions(EntityTypeInterface $entity_type, $bundle, array $base_field_definitions); /** * Returns whether the entity has a field with the given name. diff --git a/core/lib/Drupal/Core/Entity/EntityManager.php b/core/lib/Drupal/Core/Entity/EntityManager.php index 4b3d812..8014f14 100644 --- a/core/lib/Drupal/Core/Entity/EntityManager.php +++ b/core/lib/Drupal/Core/Entity/EntityManager.php @@ -89,7 +89,7 @@ class EntityManager extends PluginManagerBase implements EntityManagerInterface * * @var array */ - protected $fieldDefinitionsByBundle; + protected $fieldDefinitions; /** * The root paths. @@ -361,24 +361,24 @@ protected function buildBaseFieldDefinitions($entity_type_id) { * {@inheritdoc} */ public function getFieldDefinitions($entity_type_id, $bundle) { - if (!isset($this->fieldDefinitionsByBundle[$entity_type_id][$bundle])) { + if (!isset($this->fieldDefinitions[$entity_type_id][$bundle])) { // Not prepared, try to load from cache. $cid = 'entity_field_definitions_bundle:' . $entity_type_id . ':' . $bundle . ':' . $this->languageManager->getCurrentLanguage()->id; if ($cache = $this->cache->get($cid)) { - $field_definitions_by_bundle = $cache->data; + $bundle_field_definitions = $cache->data; } else { // Rebuild the definitions and put it into the cache. - $field_definitions_by_bundle = $this->buildFieldDefinitionsByBundle($entity_type_id, $bundle); - $this->cache->set($cid, $field_definitions_by_bundle, Cache::PERMANENT, array('entity_types' => TRUE, 'entity_field_info' => TRUE)); + $bundle_field_definitions = $this->buildBuildFieldDefinitions($entity_type_id, $bundle); + $this->cache->set($cid, $bundle_field_definitions, Cache::PERMANENT, array('entity_types' => TRUE, 'entity_field_info' => TRUE)); } // Field definitions consist of the bundle specific overrides and the // base fields, merge them together. Use array_replace() to replace base // fields with by bundle overrides and keep them in order, append // additional by bundle fields. - $this->fieldDefinitionsByBundle[$entity_type_id][$bundle] = array_replace($this->getBaseFieldDefinitions($entity_type_id), $field_definitions_by_bundle); + $this->fieldDefinitions[$entity_type_id][$bundle] = array_replace($this->getBaseFieldDefinitions($entity_type_id), $bundle_field_definitions); } - return $this->fieldDefinitionsByBundle[$entity_type_id][$bundle]; + return $this->fieldDefinitions[$entity_type_id][$bundle]; } /** @@ -391,23 +391,23 @@ public function getFieldDefinitions($entity_type_id, $bundle) { * The bundle. * * @return \Drupal\Core\Field\FieldDefinitionInterface[] - * An array of field definitions for the bundle, keyed by field name. Does + * An array of bundle field definitions, keyed by field name. Does * not include base fields. */ - protected function buildFieldDefinitionsByBundle($entity_type_id, $bundle) { + protected function buildBuildFieldDefinitions($entity_type_id, $bundle) { $entity_type = $this->getDefinition($entity_type_id); $class = $entity_type->getClass(); // Allow the entity class to override the base fields. $base_field_definitions = $this->getBaseFieldDefinitions($entity_type_id); - $field_definitions = $class::fieldDefinitionsByBundle($entity_type, $bundle, $base_field_definitions); + $bundle_field_definitions = $class::bundleFieldDefinitions($entity_type, $bundle, $base_field_definitions); // Invoke 'per bundle' hook. - $result = $this->moduleHandler->invokeAll('entity_field_info_by_bundle', array($entity_type, $bundle, $base_field_definitions)); - $field_definitions = NestedArray::mergeDeep($field_definitions, $result); + $result = $this->moduleHandler->invokeAll('entity_bundle_field_info', array($entity_type, $bundle, $base_field_definitions)); + $bundle_field_definitions = NestedArray::mergeDeep($bundle_field_definitions, $result); // Automatically set the field name for non-configurable fields. - foreach ($field_definitions as $field_name => $field_definition) { + foreach ($bundle_field_definitions as $field_name => $field_definition) { if ($field_definition instanceof FieldDefinition) { $field_definition->setName($field_name); $field_definition->setTargetEntityTypeId($entity_type_id); @@ -415,9 +415,9 @@ protected function buildFieldDefinitionsByBundle($entity_type_id, $bundle) { } // Invoke 'per bundle' alter hook. - $this->moduleHandler->alter('entity_field_info_by_bundle', $field_definitions, $entity_type, $bundle); + $this->moduleHandler->alter('entity_bundle_field_info', $bundle_field_definitions, $entity_type, $bundle); - return $field_definitions; + return $bundle_field_definitions; } /** @@ -425,7 +425,7 @@ protected function buildFieldDefinitionsByBundle($entity_type_id, $bundle) { */ public function clearCachedFieldDefinitions() { $this->baseFieldDefinitions = array(); - $this->fieldDefinitionsByBundle = array(); + $this->fieldDefinitions = array(); Cache::deleteTags(array('entity_field_info' => TRUE)); } diff --git a/core/modules/content_translation/content_translation.module b/core/modules/content_translation/content_translation.module index 4d980cb..931c879 100644 --- a/core/modules/content_translation/content_translation.module +++ b/core/modules/content_translation/content_translation.module @@ -153,7 +153,7 @@ function content_translation_entity_base_field_info_alter(&$fields, EntityTypeIn if ($translation_settings) { // Currently field translatability is defined per-field but we may want to // make it per-instance instead. In that case, we will need to implement - // hook_entity_field_info_by_bundle_alter() instead. + // hook_bundle_field_info_alter() instead. $field_settings = array(); foreach ($translation_settings as $bundle => $settings) { $field_settings += !empty($settings['content_translation']['fields']) ? $settings['content_translation']['fields'] : array(); diff --git a/core/modules/field/field.module b/core/modules/field/field.module index 492b7dc..0305928 100644 --- a/core/modules/field/field.module +++ b/core/modules/field/field.module @@ -191,9 +191,9 @@ function field_system_info_alter(&$info, $file, $type) { } /** - * Implements hook_entity_field_info_by_bundle(). + * Implements hook_entity_bundle_field_info(). */ -function field_entity_field_info_by_bundle(EntityTypeInterface $entity_type, $bundle, array $base_field_definitions) { +function field_entity_bundle_field_info(EntityTypeInterface $entity_type, $bundle, array $base_field_definitions) { if ($entity_type->isFieldable()) { // Configurable fields, which are always attached to a specific bundle, are // added 'by bundle'. diff --git a/core/modules/node/lib/Drupal/node/Entity/Node.php b/core/modules/node/lib/Drupal/node/Entity/Node.php index 1924e06..62f697f 100644 --- a/core/modules/node/lib/Drupal/node/Entity/Node.php +++ b/core/modules/node/lib/Drupal/node/Entity/Node.php @@ -452,7 +452,7 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { /** * {@inheritdoc} */ - public static function fieldDefinitionsByBundle(EntityTypeInterface $entity_type, $bundle, array $base_field_definitions) { + public static function bundleFieldDefinitions(EntityTypeInterface $entity_type, $bundle, array $base_field_definitions) { $node_type = node_type_load($bundle); $fields = array(); if (isset($node_type->title_label)) { diff --git a/core/modules/system/entity.api.php b/core/modules/system/entity.api.php index 7bc974d..aefb73b 100644 --- a/core/modules/system/entity.api.php +++ b/core/modules/system/entity.api.php @@ -668,8 +668,8 @@ function hook_entity_form_display_alter(\Drupal\Core\Entity\Display\EntityFormDi * An array of field definitions, keyed by field name. * * @see hook_entity_base_field_info_alter() - * @see hook_entity_field_info_by_bundle() - * @see hook_entity_field_info_by_bundle_alter() + * @see hook_entity_bundle_field_info() + * @see hook_entity_bundle_field_info_alter() * @see \Drupal\Core\Field\FieldDefinitionInterface * @see \Drupal\Core\Entity\EntityManagerInterface::getFieldDefinitions() */ @@ -695,8 +695,8 @@ function hook_entity_base_field_info(\Drupal\Core\Entity\EntityTypeInterface $en * The entity type definition. * * @see hook_entity_base_field_info() - * @see hook_entity_field_info_by_bundle() - * @see hook_entity_field_info_by_bundle_alter() + * @see hook_entity_bundle_field_info() + * @see hook_entity_bundle_field_info_alter() */ function hook_entity_base_field_info_alter(&$fields, \Drupal\Core\Entity\EntityTypeInterface $entity_type) { // Alter the mymodule_text field to use a custom class. @@ -706,25 +706,25 @@ function hook_entity_base_field_info_alter(&$fields, \Drupal\Core\Entity\EntityT } /** - * Provides custom field definitions for a specific bundle within an entity type. + * Provides field definitions for a specific bundle within an entity type. * * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type * The entity type definition. * @param string $bundle * The bundle. * @param \Drupal\Core\Field\FieldDefinitionInterface[] $base_field_definitions - * The list of field definitions for the bundle. + * The list of base field definitions for the entity type. * * @return \Drupal\Core\Field\FieldDefinitionInterface[] - * An array of field definitions, keyed by field name. + * An array of bundle field definitions, keyed by field name. * * @see hook_entity_base_field_info() * @see hook_entity_base_field_info_alter() - * @see hook_entity_field_info_by_bundle_alter() + * @see hook_entity_bundle_field_info_alter() * @see \Drupal\Core\Field\FieldDefinitionInterface * @see \Drupal\Core\Entity\EntityManagerInterface::getFieldDefinitions() */ -function hook_entity_field_info_by_bundle(\Drupal\Core\Entity\EntityTypeInterface $entity_type, $bundle, array $base_field_definitions) { +function hook_entity_bundle_field_info(\Drupal\Core\Entity\EntityTypeInterface $entity_type, $bundle, array $base_field_definitions) { // Add a property only to nodes of the 'article' bundle. if ($entity_type->id() == 'node' && $bundle == 'article') { $fields = array(); @@ -737,10 +737,10 @@ function hook_entity_field_info_by_bundle(\Drupal\Core\Entity\EntityTypeInterfac } /** - * Alters bundle-specific field definitions. + * Alters bundle field definitions. * * @param \Drupal\Core\Field\FieldDefinitionInterface[] $fields - * The array of field definitions for the entity type and bundle. + * The array of bundle field definitions. * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type * The entity type definition. * @param string $bundle @@ -748,9 +748,9 @@ function hook_entity_field_info_by_bundle(\Drupal\Core\Entity\EntityTypeInterfac * * @see hook_entity_base_field_info() * @see hook_entity_base_field_info_alter() - * @see hook_entity_field_info_by_bundle() + * @see hook_entity_bundle_field_info() */ -function hook_entity_field_info_by_bundle_alter(&$fields, \Drupal\Core\Entity\EntityTypeInterface $entity_type, $bundle) { +function hook_entity_bundle_field_info_alter(&$fields, \Drupal\Core\Entity\EntityTypeInterface $entity_type, $bundle) { if ($entity_type->id() == 'node' && $bundle == 'article' && !empty($fields['mymodule_text'])) { // Alter the mymodule_text field to use a custom class. $fields['mymodule_text']->setClass('\Drupal\anothermodule\EntityComputedText'); diff --git a/core/tests/Drupal/Tests/Core/Entity/EntityManagerTest.php b/core/tests/Drupal/Tests/Core/Entity/EntityManagerTest.php index aaf189c..73f1869 100644 --- a/core/tests/Drupal/Tests/Core/Entity/EntityManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/EntityManagerTest.php @@ -820,7 +820,7 @@ public function setDiscovery(DiscoveryInterface $discovery) { */ public function testClearEntityFieldInfo() { $this->baseFieldDefinitions = array(); - $this->fieldDefinitionsByBundle = array(); + $this->fieldDefinitions = array(); } }