diff --git a/core/lib/Drupal/Component/Plugin/DependentPluginInterface.php b/core/lib/Drupal/Component/Plugin/DependentPluginInterface.php index 736596a..780c120 100644 --- a/core/lib/Drupal/Component/Plugin/DependentPluginInterface.php +++ b/core/lib/Drupal/Component/Plugin/DependentPluginInterface.php @@ -23,18 +23,19 @@ * dependencies listing the specified roles. * * @return array - * An array of dependencies grouped by type (module, theme, entity). For - * example: + * An array of dependencies grouped by type (config, content, module, + * theme). For example: * @code * array( - * 'entity' => array('user.role.anonymous', 'user.role.authenticated'), + * 'config' => array('user.role.anonymous', 'user.role.authenticated'), + * 'content' => array('node:article:f0a189e6-55fb-47fb-8005-5bef81c44d6d'), * 'module' => array('node', 'user'), * 'theme' => array('seven'), * ); * @endcode * * @see \Drupal\Core\Config\Entity\ConfigDependencyManager - * @see \Drupal\Core\Config\Entity\ConfigEntityInterface::getConfigDependencyName() + * @see \Drupal\Core\Entity\EntityInterface::getConfigDependencyName() */ public function calculateDependencies(); diff --git a/core/lib/Drupal/Core/Field/FieldConfigBase.php b/core/lib/Drupal/Core/Field/FieldConfigBase.php index b34c56a..7f7e6be 100644 --- a/core/lib/Drupal/Core/Field/FieldConfigBase.php +++ b/core/lib/Drupal/Core/Field/FieldConfigBase.php @@ -229,9 +229,9 @@ public function getTargetBundle() { */ public function calculateDependencies() { parent::calculateDependencies(); - // Add dependencies from field item. We can not use - // self::calculatePluginDependencies() because instantiating a field type - // plugin without the entity is not possible. + // Add dependencies from the field type plugin. We can not use + // self::calculatePluginDependencies() because instantiation of a field item + // plugin requires a parent entity. /** @var $field_type_manager \Drupal\Core\Field\FieldTypePluginManagerInterface */ $field_type_manager = \Drupal::service('plugin.manager.field.field_type'); $definition = $field_type_manager->getDefinition($this->getType()); @@ -240,12 +240,14 @@ public function calculateDependencies() { if (isset($definition['config_dependencies'])) { $this->addDependencies($definition['config_dependencies']); } + // Let the field type plugin specify its own dependencies. + // @see \Drupal\Core\Field\FieldItemInterface::calculateDependencies() $this->addDependencies($definition['class']::calculateDependencies($this)); + // If the target entity type uses entities to manage its bundles then + // depend on the bundle entity. $bundle_entity_type_id = $this->entityManager()->getDefinition($this->entity_type)->getBundleEntityType(); if ($bundle_entity_type_id != 'bundle') { - // If the target entity type uses entities to manage its bundles then - // depend on the bundle entity. $bundle_entity = $this->entityManager()->getStorage($bundle_entity_type_id)->load($this->bundle); $this->addDependency('config', $bundle_entity->getConfigDependencyName()); } diff --git a/core/lib/Drupal/Core/Field/FieldItemBase.php b/core/lib/Drupal/Core/Field/FieldItemBase.php index d2a4770..ed4124a 100644 --- a/core/lib/Drupal/Core/Field/FieldItemBase.php +++ b/core/lib/Drupal/Core/Field/FieldItemBase.php @@ -26,13 +26,6 @@ abstract class FieldItemBase extends Map implements FieldItemInterface { /** - * The data definition. - * - * @var \Drupal\Core\Field\TypedData\FieldItemDataDefinitionInterface - */ - protected $definition; - - /** * {@inheritdoc} */ public static function defaultStorageSettings() { diff --git a/core/lib/Drupal/Core/Field/FieldItemInterface.php b/core/lib/Drupal/Core/Field/FieldItemInterface.php index 25435a6..62aecbc 100644 --- a/core/lib/Drupal/Core/Field/FieldItemInterface.php +++ b/core/lib/Drupal/Core/Field/FieldItemInterface.php @@ -373,22 +373,23 @@ public function storageSettingsForm(array &$form, FormStateInterface $form_state public function fieldSettingsForm(array $form, FormStateInterface $form_state); /** - * Calculates dependencies for the configured plugin. + * Calculates dependencies for field items. * - * Dependencies are saved in the plugin's configuration entity and are used to - * determine configuration synchronization order. For example, if the plugin - * integrates with specific user roles, this method should return an array of - * dependencies listing the specified roles. + * Dependencies are saved in the field configuration entity and are used to + * determine configuration synchronization order. For example, if the field + * type's default value is a content entity, this method should return an + * array of dependencies listing the content entities. * * @param \Drupal\Core\Field\FieldDefinitionInterface $definition * The field definition. * * @return array - * An array of dependencies grouped by type (module, theme, entity). For - * example: + * An array of dependencies grouped by type (config, content, module, + * theme). For example: * @code * array( - * 'entity' => array('user.role.anonymous', 'user.role.authenticated'), + * 'config' => array('user.role.anonymous', 'user.role.authenticated'), + * 'content' => array('node:article:f0a189e6-55fb-47fb-8005-5bef81c44d6d'), * 'module' => array('node', 'user'), * 'theme' => array('seven'), * ); diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EntityReferenceItem.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EntityReferenceItem.php index 53e4399..1e71c38 100644 --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EntityReferenceItem.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EntityReferenceItem.php @@ -249,22 +249,9 @@ public function hasUnsavedEntity() { public static function calculateDependencies(FieldDefinitionInterface $definition) { $dependencies = []; - // Public access of default_value and we're not using - // $definition->getDefaultValue() because we don't have an entity - // which is problematic because we're ignoring default value callbacks. But - // since callback can vary depending on the entity perhaps they should not - // by supported anyway. if (is_array($definition->default_value) && count($definition->default_value)) { $target_entity_type = \Drupal::entityManager()->getDefinition($definition->getFieldStorageDefinition()->getSetting('target_type')); - if ($target_entity_type instanceof ConfigEntityType) { - $key = 'config'; - } - else { - $key = 'content'; - } - $dependencies = [ - $key => [] - ]; + $key = $target_entity_type instanceof ConfigEntityType ? 'config' : 'content'; foreach ($definition->default_value as $default_value) { if (is_array($default_value) && isset($default_value['target_uuid'])) { $entity = \Drupal::entityManager()->loadEntityByUuid($target_entity_type->id(), $default_value['target_uuid']);