diff --git a/core/modules/layout_builder/src/Plugin/Derivative/ExtraFieldBlockDeriver.php b/core/modules/layout_builder/src/Plugin/Derivative/ExtraFieldBlockDeriver.php index bb61ccc156..8de394c349 100644 --- a/core/modules/layout_builder/src/Plugin/Derivative/ExtraFieldBlockDeriver.php +++ b/core/modules/layout_builder/src/Plugin/Derivative/ExtraFieldBlockDeriver.php @@ -12,6 +12,7 @@ use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface; use Drupal\Core\StringTranslation\StringTranslationTrait; use Symfony\Component\DependencyInjection\ContainerInterface; +use Drupal\Core\Entity\EntityTypeRepositoryInterface; /** * Provides entity field block definitions for every field. @@ -44,6 +45,13 @@ class ExtraFieldBlockDeriver extends DeriverBase implements ContainerDeriverInte */ protected $entityTypeBundleInfo; + /** + * The entity type repository. + * + * @var \Drupal\Core\Entity\EntityTypeRepositoryInterface + */ + protected $entityTypeRepository; + /** * Constructs new FieldBlockDeriver. * @@ -53,11 +61,14 @@ class ExtraFieldBlockDeriver extends DeriverBase implements ContainerDeriverInte * The entity type manager. * @param \Drupal\Core\Entity\EntityTypeBundleInfoInterface $entity_type_bundle_info * The entity type bundle info. + * @param \Drupal\Core\Entity\EntityTypeRepositoryInterface $entity_type_repository + * The entity type repository. */ - public function __construct(EntityFieldManagerInterface $entity_field_manager, EntityTypeManagerInterface $entity_type_manager, EntityTypeBundleInfoInterface $entity_type_bundle_info) { + public function __construct(EntityFieldManagerInterface $entity_field_manager, EntityTypeManagerInterface $entity_type_manager, EntityTypeBundleInfoInterface $entity_type_bundle_info, EntityTypeRepositoryInterface $entity_type_repository) { $this->entityFieldManager = $entity_field_manager; $this->entityTypeManager = $entity_type_manager; $this->entityTypeBundleInfo = $entity_type_bundle_info; + $this->entityTypeRepository = $entity_type_repository; } /** @@ -67,7 +78,8 @@ public static function create(ContainerInterface $container, $base_plugin_id) { return new static( $container->get('entity_field.manager'), $container->get('entity_type.manager'), - $container->get('entity_type.bundle.info') + $container->get('entity_type.bundle.info'), + $container->get('entity_type.repository') ); } @@ -75,6 +87,7 @@ public static function create(ContainerInterface $container, $base_plugin_id) { * {@inheritdoc} */ public function getDerivativeDefinitions($base_plugin_definition) { + $entity_type_labels = $this->entityTypeRepository->getEntityTypeLabels(); foreach ($this->entityTypeManager->getDefinitions() as $entity_type_id => $entity_type) { // Only process fieldable entity types. if (!$entity_type->entityClassImplements(FieldableEntityInterface::class)) { @@ -92,7 +105,7 @@ public function getDerivativeDefinitions($base_plugin_definition) { foreach ($extra_fields['display'] as $extra_field_id => $extra_field) { $derivative = $base_plugin_definition; - $derivative['category'] = $entity_type->getLabel(); + $derivative['category'] = $this->t('@entity fields', ['@entity' => $entity_type_labels[$entity_type_id]]); $derivative['admin_label'] = $extra_field['label']; diff --git a/core/modules/layout_builder/tests/src/Functional/LayoutBuilderTest.php b/core/modules/layout_builder/tests/src/Functional/LayoutBuilderTest.php index 5629dc9982..9aa88b0d0c 100644 --- a/core/modules/layout_builder/tests/src/Functional/LayoutBuilderTest.php +++ b/core/modules/layout_builder/tests/src/Functional/LayoutBuilderTest.php @@ -688,13 +688,24 @@ public function testLayoutBuilderChooseBlocksAlter() { public function testExtraFields() { $assert_session = $this->assertSession(); - $this->drupalLogin($this->drupalCreateUser(['administer node display'])); + $this->drupalLogin($this->drupalCreateUser([ + 'configure any layout', + 'administer node display', + ])); $this->drupalGet('node'); $assert_session->linkExists('Read more'); $this->drupalPostForm('admin/structure/types/manage/bundle_with_section_field/display/default', ['layout[enabled]' => TRUE], 'Save'); + // Extra fields display under "Content fields". + $this->drupalGet("admin/structure/types/manage/bundle_with_section_field/display/default/layout"); + $this->clickLink('Add block'); + $page = $this->getSession()->getPage(); + $content_fields_category = $page->find('xpath', '//details/summary[contains(text(),"Content fields")]/parent::details'); + $extra_field = strpos($content_fields_category->getText(), 'Extra label'); + $this->assertTrue($extra_field !== FALSE); + $this->drupalGet('node'); $assert_session->linkExists('Read more'); }