diff --git a/core/modules/layout_builder/src/Plugin/Block/FieldBlock.php b/core/modules/layout_builder/src/Plugin/Block/FieldBlock.php index 385673f896..f011e32a78 100644 --- a/core/modules/layout_builder/src/Plugin/Block/FieldBlock.php +++ b/core/modules/layout_builder/src/Plugin/Block/FieldBlock.php @@ -11,7 +11,6 @@ use Drupal\Core\Entity\EntityFieldManagerInterface; use Drupal\Core\Entity\FieldableEntityInterface; use Drupal\Core\Extension\ModuleHandlerInterface; -use Drupal\Core\Field\FieldConfigInterface; use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\Core\Field\FormatterInterface; use Drupal\Core\Field\FormatterPluginManager; @@ -374,17 +373,4 @@ protected function getFormatter(array $parents, FormStateInterface $form_state) ]); } - /** - * {@inheritdoc} - */ - public function calculateDependencies() { - $dependencies = []; - - $field_definition = $this->getFieldDefinition(); - if ($field_definition instanceof FieldConfigInterface) { - $dependencies[$field_definition->getConfigDependencyKey()][] = $field_definition->getConfigDependencyName(); - } - return $dependencies; - } - } diff --git a/core/modules/layout_builder/src/Plugin/Derivative/FieldBlockDeriver.php b/core/modules/layout_builder/src/Plugin/Derivative/FieldBlockDeriver.php index 3591d97a38..14d7b1bb0c 100644 --- a/core/modules/layout_builder/src/Plugin/Derivative/FieldBlockDeriver.php +++ b/core/modules/layout_builder/src/Plugin/Derivative/FieldBlockDeriver.php @@ -6,6 +6,7 @@ use Drupal\Component\Plugin\PluginBase; use Drupal\Core\Entity\EntityFieldManagerInterface; use Drupal\Core\Entity\EntityTypeRepositoryInterface; +use Drupal\Core\Field\FieldConfigInterface; use Drupal\Core\Field\FieldTypePluginManagerInterface; use Drupal\Core\Field\FormatterPluginManager; use Drupal\Core\Plugin\Context\ContextDefinition; @@ -132,9 +133,13 @@ public function getDerivativeDefinitions($base_plugin_definition) { $derivative['category'] = $this->t('@entity', ['@entity' => $entity_type_labels[$entity_type_id]]); $derivative['admin_label'] = $admin_label; + $field_definition = $this->entityFieldManager->getFieldDefinitions($entity_type_id, $bundle)[$field_name]; + // Add a dependency on the field if it is configurable. + if ($field_definition instanceof FieldConfigInterface) { + $derivative['config_dependencies'][$field_definition->getConfigDependencyKey()][] = $field_definition->getConfigDependencyName(); + } // For any field that is not display configurable, mark it as // unavailable to place in the block UI. - $field_definition = $this->entityFieldManager->getFieldDefinitions($entity_type_id, $bundle)[$field_name]; $derivative['_block_ui_hidden'] = !$field_definition->isDisplayConfigurable('view'); // @todo Use EntityContextDefinition after resolving diff --git a/core/modules/layout_builder/tests/src/FunctionalJavascript/FieldBlockTest.php b/core/modules/layout_builder/tests/src/FunctionalJavascript/FieldBlockTest.php index c5ba527126..4f086d6a96 100644 --- a/core/modules/layout_builder/tests/src/FunctionalJavascript/FieldBlockTest.php +++ b/core/modules/layout_builder/tests/src/FunctionalJavascript/FieldBlockTest.php @@ -112,6 +112,7 @@ public function testFieldBlock() { ]; $config = $this->container->get('config.factory')->get('block.block.datefield'); $this->assertEquals($expected, $config->get('settings.formatter')); + $this->assertEquals(['field.field.user.user.field_date'], $config->get('dependencies.config')); // Assert that the block is displaying the user field. $this->drupalGet('admin');