diff --git a/core/lib/Drupal/Core/Entity/EntityManager.php b/core/lib/Drupal/Core/Entity/EntityManager.php index 1bdebcb..0a524b0 100644 --- a/core/lib/Drupal/Core/Entity/EntityManager.php +++ b/core/lib/Drupal/Core/Entity/EntityManager.php @@ -328,29 +328,26 @@ protected function buildBaseFieldDefinitions($entity_type_id) { $entity_type = $this->getDefinition($entity_type_id); $class = $entity_type->getClass(); - $provider = $entity_type->getProvider(); + // Retrieve base field definitions and assign them the entity type provider. $base_field_definitions = $class::baseFieldDefinitions($entity_type); + $provider = $entity_type->getProvider(); foreach ($base_field_definitions as $definition) { $definition->setProvider($provider); } // Retrieve base field definitions from modules. - $base_field_module_definitions = array(); - $hook = 'entity_base_field_info'; - foreach ($this->moduleHandler->getImplementations($hook) as $module) { - $module_definitions = call_user_func($module . '_' . $hook, $entity_type); - if (isset($module_definitions) && is_array($module_definitions)) { - // Ensure the module key actually matches the name of the module defining - // the field. + foreach ($this->moduleHandler->getImplementations('entity_base_field_info') as $module) { + $module_definitions = $this->moduleHandler->invoke($module, 'entity_base_field_info', $entity_type); + if (!empty($module_definitions)) { + // Ensure the provider key actually matches the name of the provider + // defining the field. foreach ($module_definitions as $definition) { $definition->setProvider($provider); } - $return = NestedArray::mergeDeep($base_field_module_definitions, $module_definitions); + $base_field_definitions = NestedArray::mergeDeep($base_field_definitions, $module_definitions); } } - $base_field_definitions = NestedArray::mergeDeep($base_field_definitions, $base_field_module_definitions); - // Automatically set the field name for non-configurable fields. foreach ($base_field_definitions as $field_name => $base_field_definition) { if ($base_field_definition instanceof FieldDefinition) { @@ -360,7 +357,7 @@ protected function buildBaseFieldDefinitions($entity_type_id) { } // Invoke alter hook. - $this->moduleHandler->alter($hook, $base_field_definitions, $entity_type); + $this->moduleHandler->alter('entity_base_field_info', $base_field_definitions, $entity_type); // Ensure all basic fields are not defined as translatable. $keys = array_intersect_key(array_filter($entity_type->getKeys()), array_flip(array('id', 'revision', 'uuid', 'bundle'))); @@ -426,23 +423,18 @@ protected function buildBundleFieldDefinitions($entity_type_id, $bundle, array $ } // Retrieve base field definitions from modules. - $bundle_field_module_definitions = array(); - $hook = 'entity_bundle_field_info'; - foreach ($this->moduleHandler->getImplementations($hook) as $module) { - $module_definitions = call_user_func($module . '_' . $hook, $entity_type, $bundle, $bundle_field_module_definitions); - if (isset($module_definitions) && is_array($module_definitions)) { - // Ensure the module key actually matches the name of the module defining - // the field. + foreach ($this->moduleHandler->getImplementations('entity_bundle_field_info') as $module) { + $module_definitions = $this->moduleHandler->invoke($module, 'entity_bundle_field_info', $entity_type, $bundle, $bundle_field_module_definitions); + if (!empty($module_definitions)) { + // Ensure the provider key actually matches the name of the provider + // defining the field. foreach ($module_definitions as $definition) { $definition->setProvider($provider); } - $return = NestedArray::mergeDeep($bundle_field_module_definitions, $module_definitions); + $bundle_field_definitions = NestedArray::mergeDeep($bundle_field_definitions, $module_definitions); } } - // Invoke 'per bundle' hook. - $bundle_field_definitions = NestedArray::mergeDeep($bundle_field_definitions, $bundle_field_module_definitions); - // Automatically set the field name for non-configurable fields. foreach ($bundle_field_definitions as $field_name => $field_definition) { if ($field_definition instanceof FieldDefinition) { diff --git a/core/lib/Drupal/Core/Field/FieldDefinition.php b/core/lib/Drupal/Core/Field/FieldDefinition.php index c0732ad..e9c7f60 100644 --- a/core/lib/Drupal/Core/Field/FieldDefinition.php +++ b/core/lib/Drupal/Core/Field/FieldDefinition.php @@ -161,7 +161,7 @@ public function getProvider() { * @param string $provider * The provider name. * - * @return static + * @return $this * The object itself for chaining. */ public function setProvider($provider) { @@ -477,7 +477,7 @@ public static function getReservedColumns() { /** * {@inheritdoc} */ - public function isCustomStorage() { + public function hasCustomStorage() { return !empty($this->definition['custom_storage']); } @@ -488,7 +488,7 @@ public function isCustomStorage() { * Pass TRUE if the field module will take care of storing field values, * FALSE otherwise. * - * @return static + * @return $this * The object itself for chaining. */ public function setCustomStorage($custom_storage) { diff --git a/core/lib/Drupal/Core/Field/FieldDefinitionInterface.php b/core/lib/Drupal/Core/Field/FieldDefinitionInterface.php index cfc497b..f18071f 100644 --- a/core/lib/Drupal/Core/Field/FieldDefinitionInterface.php +++ b/core/lib/Drupal/Core/Field/FieldDefinitionInterface.php @@ -347,13 +347,14 @@ public function getColumns(); /** * Returns the storage behavior for this field. * - * This indicates whether the storage controller should take care of storing - * the field values or whether the field module will do it. + * Indicates whether the entity type's storage controller should take care of + * storing the field values or whether the module providing the field will do + * that. * * @return bool * TRUE if the field module takes care of storing field values, FALSE * otherwise. */ - public function isCustomStorage(); + public function hasCustomStorage(); } diff --git a/core/modules/field/lib/Drupal/field/Entity/FieldConfig.php b/core/modules/field/lib/Drupal/field/Entity/FieldConfig.php index 1b8b5bc..fd6eda1 100644 --- a/core/modules/field/lib/Drupal/field/Entity/FieldConfig.php +++ b/core/modules/field/lib/Drupal/field/Entity/FieldConfig.php @@ -478,7 +478,7 @@ public function getSchema() { /** * {@inheritdoc} */ - public function isCustomStorage() { + public function hasCustomStorage() { return FALSE; } @@ -593,11 +593,12 @@ public function getProvider() { * @param string $provider * The provider name. * - * @return static + * @return $this * The object itself for chaining. */ public function setProvider($provider) { - // Do nothing: provider is readonly property. + // Do nothing: provider is a readonly property here. + return $this; } /** diff --git a/core/modules/field/lib/Drupal/field/Entity/FieldInstanceConfig.php b/core/modules/field/lib/Drupal/field/Entity/FieldInstanceConfig.php index 65f6c76..f3b361d 100644 --- a/core/modules/field/lib/Drupal/field/Entity/FieldInstanceConfig.php +++ b/core/modules/field/lib/Drupal/field/Entity/FieldInstanceConfig.php @@ -511,7 +511,7 @@ public function getProvider() { * @param string $provider * The provider name. * - * @return static + * @return $this * The object itself for chaining. */ public function setProvider($provider) { @@ -788,8 +788,8 @@ public function getColumns() { /** * {@inheritdoc} */ - public function isCustomStorage() { - return $this->field->isCustomStorage(); + public function hasCustomStorage() { + return $this->field->hasCustomStorage(); } }