Issue #3432874 by acbramley, catch, alexpott: Replace "Expose all fields as blocks to Layout Builder" configuration with a feature flag module
parent
3600680828
commit
41e2fd078e
|
@ -1 +0,0 @@
|
|||
expose_all_field_blocks: false
|
|
@ -89,11 +89,3 @@ layout_plugin.settings.layout_twocol_section:
|
|||
|
||||
layout_plugin.settings.layout_threecol_section:
|
||||
type: layout_builder_multi_width
|
||||
|
||||
layout_builder.settings:
|
||||
type: config_object
|
||||
label: 'Layout builder settings'
|
||||
mapping:
|
||||
expose_all_field_blocks:
|
||||
type: boolean
|
||||
label: 'Expose all field blocks'
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
name: 'Layout Builder'
|
||||
type: module
|
||||
description: 'Allows users to add and arrange blocks and content fields directly on the content.'
|
||||
configure: layout_builder.settings
|
||||
package: Core
|
||||
version: VERSION
|
||||
dependencies:
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
layout_builder.settings:
|
||||
title: 'Layout Builder'
|
||||
parent: system.admin_config_content
|
||||
description: 'Configure Layout Builder settings.'
|
||||
route_name: layout_builder.settings
|
|
@ -1,6 +1,3 @@
|
|||
administer layout builder:
|
||||
title: 'Administer layout builder'
|
||||
restrict access: true
|
||||
configure any layout:
|
||||
title: 'Configure any layout'
|
||||
restrict access: true
|
||||
|
|
|
@ -71,10 +71,8 @@ function layout_builder_post_update_timestamp_formatter(array &$sandbox = NULL):
|
|||
}
|
||||
|
||||
/**
|
||||
* Configure the default expose all fields setting.
|
||||
* Enable the expose all fields feature flag module.
|
||||
*/
|
||||
function layout_builder_post_update_default_expose_field_block_setting(): void {
|
||||
\Drupal::configFactory()->getEditable('layout_builder.settings')
|
||||
->set('expose_all_field_blocks', TRUE)
|
||||
->save(TRUE);
|
||||
function layout_builder_post_update_enable_expose_field_block_feature_flag(): void {
|
||||
\Drupal::service('module_installer')->install(['layout_builder_expose_all_field_blocks']);
|
||||
}
|
||||
|
|
|
@ -1,11 +1,3 @@
|
|||
layout_builder.settings:
|
||||
path: '/admin/config/content/layout-builder'
|
||||
defaults:
|
||||
_form: '\Drupal\layout_builder\Form\LayoutBuilderSettingsForm'
|
||||
_title: 'Layout Builder'
|
||||
requirements:
|
||||
_permission: 'administer layout builder'
|
||||
|
||||
layout_builder.choose_section:
|
||||
path: '/layout_builder/choose/section/{section_storage_type}/{section_storage}/{delta}'
|
||||
defaults:
|
||||
|
|
|
@ -68,6 +68,3 @@ services:
|
|||
layout_builder.element.prepare_layout:
|
||||
class: Drupal\layout_builder\EventSubscriber\PrepareLayout
|
||||
arguments: ['@layout_builder.tempstore_repository', '@messenger']
|
||||
layout_builder.config_subscriber:
|
||||
class: Drupal\layout_builder\EventSubscriber\LayoutBuilderConfigSubscriber
|
||||
arguments: ['@plugin.manager.block']
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
name: 'Layout Builder Expose All Field Blocks'
|
||||
type: module
|
||||
description: 'When enabled, this module exposes all fields for all entity view displays. When disabled, only entity type bundles that have layout builder enabled will have their fields exposed. Enabling this module could significantly decrease performance on sites with a large number of entity types and bundles.'
|
||||
package: Core
|
||||
version: VERSION
|
||||
dependencies:
|
||||
- drupal:layout_builder
|
||||
lifecycle: deprecated
|
||||
lifecycle_link: "https://www.drupal.org/node/3223395#s-layout-builder-expose-all-field-blocks"
|
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Module implementation file.
|
||||
*/
|
||||
|
||||
use Drupal\Core\Routing\RouteMatchInterface;
|
||||
|
||||
/**
|
||||
* Implements hook_help().
|
||||
*/
|
||||
function layout_builder_expose_all_field_blocks_help($route_name, RouteMatchInterface $route_match) {
|
||||
switch ($route_name) {
|
||||
case 'help.page.layout_builder_expose_all_field_blocks':
|
||||
$output = '<h2>' . t('About') . '</h2>';
|
||||
$output .= '<p>' . t('The Layout Builder Expose All Field Blocks module is a Feature Flag module which, when enabled, exposes all fields on all bundles as field blocks for use in Layout Builder.') . '</p>';
|
||||
$output .= '<p>' . t('Leaving this module enabled can significantly affect the performance of medium to large sites due to the number of Field Block plugins that will be created. It is recommended to turn it off if possible.') . '</p>';
|
||||
$output .= '<p>' . t('While it is recommended to turn this module off, note that this may remove blocks that are already being used in existing site configurations.') . '</p>';
|
||||
$output .= '<p>' . t("For example, if you have Layout Builder enabled on a Node bundle (Content type), and that bundle's display is using field blocks from the User entity (e.g the Author's name), but Layout Builder is not enabled for the User bundle, then that field block would no longer exist after disabling this module.") . '</p>';
|
||||
$output .= '<p>' . t('For more information, see the <a href=":href">online documentation for the Layout Builder Expose All Field Blocks module</a>.', [':href' => 'https://www.drupal.org/node/3223395#s-layout-builder-expose-all-field-blocks']) . '</p>';
|
||||
return $output;
|
||||
}
|
||||
return NULL;
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Drupal\Tests\layout_builder_expose_all_field_blocks\Functional;
|
||||
|
||||
use Drupal\Tests\system\Functional\Module\GenericModuleTestBase;
|
||||
|
||||
/**
|
||||
* Generic module test for layout_builder_expose_all_field_blocks.
|
||||
*
|
||||
* @group layout_builder_expose_all_field_blocks
|
||||
* @group legacy
|
||||
*/
|
||||
class GenericTest extends GenericModuleTestBase {}
|
|
@ -164,7 +164,7 @@ class LayoutBuilderEntityViewDisplay extends BaseEntityViewDisplay implements La
|
|||
*/
|
||||
public function save(): int {
|
||||
$return = parent::save();
|
||||
if (!\Drupal::config('layout_builder.settings')->get('expose_all_field_blocks')) {
|
||||
if (!\Drupal::moduleHandler()->moduleExists('layout_builder_expose_all_field_blocks')) {
|
||||
// Invalidate the block cache in order to regenerate field block
|
||||
// definitions.
|
||||
\Drupal::service('plugin.manager.block')->clearCachedDefinitions();
|
||||
|
|
|
@ -1,46 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Drupal\layout_builder\EventSubscriber;
|
||||
|
||||
use Drupal\Core\Block\BlockManagerInterface;
|
||||
use Drupal\Core\Config\ConfigCrudEvent;
|
||||
use Drupal\Core\Config\ConfigEvents;
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
|
||||
/**
|
||||
* Layout Builder Config subscriber.
|
||||
*/
|
||||
final class LayoutBuilderConfigSubscriber implements EventSubscriberInterface {
|
||||
|
||||
/**
|
||||
* Constructs a LayoutBuilderConfigSubscriber.
|
||||
*/
|
||||
public function __construct(
|
||||
protected BlockManagerInterface $blockManager,
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the block plugin cache when expose_all_field_blocks changes.
|
||||
*
|
||||
* @param \Drupal\Core\Config\ConfigCrudEvent $event
|
||||
* The configuration event.
|
||||
*/
|
||||
public function onConfigSave(ConfigCrudEvent $event): void {
|
||||
$saved_config = $event->getConfig();
|
||||
if ($saved_config->getName() == 'layout_builder.settings' && $event->isChanged('expose_all_field_blocks')) {
|
||||
$this->blockManager->clearCachedDefinitions();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function getSubscribedEvents(): array {
|
||||
$events[ConfigEvents::SAVE][] = ['onConfigSave'];
|
||||
return $events;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,40 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Drupal\layout_builder\Form;
|
||||
|
||||
use Drupal\Core\Form\ConfigFormBase;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Form\RedundantEditableConfigNamesTrait;
|
||||
|
||||
/**
|
||||
* Configure layout builder settings for this site.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
final class LayoutBuilderSettingsForm extends ConfigFormBase {
|
||||
|
||||
use RedundantEditableConfigNamesTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFormId(): string {
|
||||
return 'layout_builder_settings';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(array $form, FormStateInterface $form_state): array {
|
||||
$form['expose_all_field_blocks'] = [
|
||||
'#type' => 'checkbox',
|
||||
'#title' => $this->t('Expose all fields as blocks to layout builder'),
|
||||
'#description' => $this->t('When enabled, this setting exposes all fields for all entity view displays.<br/> When disabled, only entity type bundles that have layout builder enabled will have their fields exposed.<br/> Enabling this setting could <strong>significantly decrease performance</strong> on sites with a large number of entity types and bundles.'),
|
||||
'#config_target' => 'layout_builder.settings:expose_all_field_blocks',
|
||||
];
|
||||
return parent::buildForm($form, $form_state);
|
||||
}
|
||||
|
||||
}
|
|
@ -4,11 +4,11 @@ namespace Drupal\layout_builder\Plugin\Derivative;
|
|||
|
||||
use Drupal\Component\Plugin\Derivative\DeriverBase;
|
||||
use Drupal\Component\Plugin\PluginBase;
|
||||
use Drupal\Core\Config\ConfigFactoryInterface;
|
||||
use Drupal\Core\Entity\EntityFieldManagerInterface;
|
||||
use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
|
||||
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||
use Drupal\Core\Entity\FieldableEntityInterface;
|
||||
use Drupal\Core\Extension\ModuleHandlerInterface;
|
||||
use Drupal\Core\Plugin\Context\EntityContextDefinition;
|
||||
use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
|
||||
use Drupal\Core\StringTranslation\StringTranslationTrait;
|
||||
|
@ -64,15 +64,15 @@ class ExtraFieldBlockDeriver extends DeriverBase implements ContainerDeriverInte
|
|||
* The entity type bundle info.
|
||||
* @param \Drupal\Core\Entity\EntityTypeRepositoryInterface $entity_type_repository
|
||||
* The entity type repository.
|
||||
* @param \Drupal\Core\Config\ConfigFactoryInterface $configFactory
|
||||
* The config factory.
|
||||
* @param \Drupal\Core\Extension\ModuleHandlerInterface $moduleHandler
|
||||
* The module handler.
|
||||
*/
|
||||
public function __construct(
|
||||
EntityFieldManagerInterface $entity_field_manager,
|
||||
EntityTypeManagerInterface $entity_type_manager,
|
||||
EntityTypeBundleInfoInterface $entity_type_bundle_info,
|
||||
EntityTypeRepositoryInterface $entity_type_repository,
|
||||
protected ConfigFactoryInterface $configFactory,
|
||||
protected ModuleHandlerInterface $moduleHandler,
|
||||
) {
|
||||
$this->entityFieldManager = $entity_field_manager;
|
||||
$this->entityTypeManager = $entity_type_manager;
|
||||
|
@ -89,7 +89,7 @@ class ExtraFieldBlockDeriver extends DeriverBase implements ContainerDeriverInte
|
|||
$container->get('entity_type.manager'),
|
||||
$container->get('entity_type.bundle.info'),
|
||||
$container->get('entity_type.repository'),
|
||||
$container->get('config.factory')
|
||||
$container->get('module_handler')
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -99,7 +99,7 @@ class ExtraFieldBlockDeriver extends DeriverBase implements ContainerDeriverInte
|
|||
public function getDerivativeDefinitions($base_plugin_definition) {
|
||||
$entity_type_labels = $this->entityTypeRepository->getEntityTypeLabels();
|
||||
$enabled_bundle_ids = $this->bundleIdsWithLayoutBuilderDisplays();
|
||||
$expose_all_fields = $this->configFactory->get('layout_builder.settings')->get('expose_all_field_blocks');
|
||||
$expose_all_fields = $this->moduleHandler->moduleExists('layout_builder_expose_all_field_blocks');
|
||||
foreach ($this->entityTypeManager->getDefinitions() as $entity_type_id => $entity_type) {
|
||||
// Only process fieldable entity types.
|
||||
if (!$entity_type->entityClassImplements(FieldableEntityInterface::class)) {
|
||||
|
|
|
@ -4,10 +4,10 @@ namespace Drupal\layout_builder\Plugin\Derivative;
|
|||
|
||||
use Drupal\Component\Plugin\Derivative\DeriverBase;
|
||||
use Drupal\Component\Plugin\PluginBase;
|
||||
use Drupal\Core\Config\ConfigFactoryInterface;
|
||||
use Drupal\Core\Config\Entity\ConfigEntityStorageInterface;
|
||||
use Drupal\Core\Entity\EntityFieldManagerInterface;
|
||||
use Drupal\Core\Entity\EntityTypeRepositoryInterface;
|
||||
use Drupal\Core\Extension\ModuleHandlerInterface;
|
||||
use Drupal\Core\Field\FieldConfigInterface;
|
||||
use Drupal\Core\Field\FieldTypePluginManagerInterface;
|
||||
use Drupal\Core\Field\FormatterPluginManager;
|
||||
|
@ -70,8 +70,8 @@ class FieldBlockDeriver extends DeriverBase implements ContainerDeriverInterface
|
|||
* The formatter manager.
|
||||
* @param \Drupal\Core\Config\Entity\ConfigEntityStorageInterface $entityViewDisplayStorage
|
||||
* The entity view display storage.
|
||||
* @param \Drupal\Core\Config\ConfigFactoryInterface $configFactory
|
||||
* The config factory.
|
||||
* @param \Drupal\Core\Extension\ModuleHandlerInterface $moduleHandler
|
||||
* The module handler.
|
||||
*/
|
||||
public function __construct(
|
||||
EntityTypeRepositoryInterface $entity_type_repository,
|
||||
|
@ -79,7 +79,7 @@ class FieldBlockDeriver extends DeriverBase implements ContainerDeriverInterface
|
|||
FieldTypePluginManagerInterface $field_type_manager,
|
||||
FormatterPluginManager $formatter_manager,
|
||||
protected ConfigEntityStorageInterface $entityViewDisplayStorage,
|
||||
protected ConfigFactoryInterface $configFactory,
|
||||
protected ModuleHandlerInterface $moduleHandler,
|
||||
) {
|
||||
$this->entityTypeRepository = $entity_type_repository;
|
||||
$this->entityFieldManager = $entity_field_manager;
|
||||
|
@ -97,7 +97,7 @@ class FieldBlockDeriver extends DeriverBase implements ContainerDeriverInterface
|
|||
$container->get('plugin.manager.field.field_type'),
|
||||
$container->get('plugin.manager.field.formatter'),
|
||||
$container->get('entity_type.manager')->getStorage('entity_view_display'),
|
||||
$container->get('config.factory')
|
||||
$container->get('module_handler')
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -170,7 +170,7 @@ class FieldBlockDeriver extends DeriverBase implements ContainerDeriverInterface
|
|||
|
||||
// If all fields are exposed as field blocks, just return the field map
|
||||
// without any further processing.
|
||||
if ($this->configFactory->get('layout_builder.settings')->get('expose_all_field_blocks')) {
|
||||
if ($this->moduleHandler->moduleExists('layout_builder_expose_all_field_blocks')) {
|
||||
return $field_map;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,52 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Drupal\Tests\layout_builder\Functional;
|
||||
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
|
||||
/**
|
||||
* Tests the Layout Builder settings form.
|
||||
*
|
||||
* @coversDefaultClass \Drupal\layout_builder\Form\LayoutBuilderSettingsForm
|
||||
* @group layout_builder
|
||||
*/
|
||||
class SettingsFormTest extends BrowserTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $modules = ['layout_builder'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $defaultTheme = 'stark';
|
||||
|
||||
/**
|
||||
* Tests the Layout Builder settings form.
|
||||
*/
|
||||
public function testSettingsForm(): void {
|
||||
$this->drupalLogin($this->drupalCreateUser([
|
||||
'access administration pages',
|
||||
'administer layout builder',
|
||||
]));
|
||||
|
||||
$this->drupalGet(Url::fromRoute('layout_builder.settings'));
|
||||
$this->assertSession()->statusCodeEquals(200);
|
||||
$this->submitForm([
|
||||
'expose_all_field_blocks' => 1,
|
||||
], 'Save configuration');
|
||||
|
||||
$this->assertSession()->pageTextContains('The configuration options have been saved');
|
||||
$this->assertSession()->checkboxChecked('expose_all_field_blocks');
|
||||
$this->submitForm([
|
||||
'expose_all_field_blocks' => 0,
|
||||
], 'Save configuration');
|
||||
$this->assertSession()->pageTextContains('The configuration options have been saved');
|
||||
$this->assertSession()->checkboxNotChecked('expose_all_field_blocks');
|
||||
}
|
||||
|
||||
}
|
|
@ -1,44 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Drupal\Tests\layout_builder\Functional\Update;
|
||||
|
||||
use Drupal\FunctionalTests\Update\UpdatePathTestBase;
|
||||
|
||||
/**
|
||||
* Tests creation of layout_builder settings.
|
||||
*
|
||||
* @see layout_builder_post_update_default_expose_field_block_setting()
|
||||
*
|
||||
* @group Update
|
||||
*/
|
||||
class LayoutBuilderSettingsUpdateTest extends UpdatePathTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setDatabaseDumpFiles() {
|
||||
$this->databaseDumpFiles = [
|
||||
__DIR__ . '/../../../../../system/tests/fixtures/update/drupal-9.4.0.bare.standard.php.gz',
|
||||
__DIR__ . '/../../../fixtures/update/layout-builder.php',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests layout_builder_post_update_default_expose_field_block_setting().
|
||||
*/
|
||||
public function testLayoutBuilderPostUpdateExposeFieldBlockSetting(): void {
|
||||
// Ensure config is not present.
|
||||
$config = $this->config('layout_builder.settings');
|
||||
$this->assertTrue($config->isNew());
|
||||
|
||||
$this->runUpdates();
|
||||
|
||||
// Ensure config is present and setting is enabled.
|
||||
$updated_config = $this->config('layout_builder.settings');
|
||||
$this->assertFalse($updated_config->isNew());
|
||||
$this->assertTrue($updated_config->get('expose_all_field_blocks'));
|
||||
}
|
||||
|
||||
}
|
|
@ -12,6 +12,7 @@ use Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay;
|
|||
* Tests the JavaScript functionality of the block add filter.
|
||||
*
|
||||
* @group layout_builder
|
||||
* @group legacy
|
||||
*/
|
||||
class BlockFilterTest extends WebDriverTestBase {
|
||||
|
||||
|
@ -23,6 +24,7 @@ class BlockFilterTest extends WebDriverTestBase {
|
|||
'node',
|
||||
'datetime',
|
||||
'layout_builder',
|
||||
'layout_builder_expose_all_field_blocks',
|
||||
'user',
|
||||
];
|
||||
|
||||
|
@ -37,12 +39,6 @@ class BlockFilterTest extends WebDriverTestBase {
|
|||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
||||
// This test makes assertions on lists of blocks, this includes a derived
|
||||
// block from the user entity.
|
||||
\Drupal::configFactory()->getEditable('layout_builder.settings')
|
||||
->set('expose_all_field_blocks', TRUE)
|
||||
->save();
|
||||
|
||||
$this->drupalLogin($this->drupalCreateUser([
|
||||
'configure any layout',
|
||||
]));
|
||||
|
|
|
@ -14,6 +14,7 @@ use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
|
|||
* @coversDefaultClass \Drupal\layout_builder\Plugin\Block\FieldBlock
|
||||
*
|
||||
* @group field
|
||||
* @group legacy
|
||||
*/
|
||||
class FieldBlockTest extends WebDriverTestBase {
|
||||
|
||||
|
@ -27,6 +28,7 @@ class FieldBlockTest extends WebDriverTestBase {
|
|||
'user',
|
||||
// See \Drupal\layout_builder_fieldblock_test\Plugin\Block\FieldBlock.
|
||||
'layout_builder_fieldblock_test',
|
||||
'layout_builder_expose_all_field_blocks',
|
||||
];
|
||||
|
||||
/**
|
||||
|
@ -40,9 +42,6 @@ class FieldBlockTest extends WebDriverTestBase {
|
|||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
||||
\Drupal::configFactory()->getEditable('layout_builder.settings')
|
||||
->set('expose_all_field_blocks', TRUE)
|
||||
->save();
|
||||
$field_storage = FieldStorageConfig::create([
|
||||
'field_name' => 'field_date',
|
||||
'entity_type' => 'user',
|
||||
|
|
|
@ -11,6 +11,7 @@ use Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay;
|
|||
* Tests field block plugin derivatives.
|
||||
*
|
||||
* @group layout_builder
|
||||
* @group legacy
|
||||
*/
|
||||
class FieldBlockDeriverTest extends EntityKernelTestBase {
|
||||
|
||||
|
@ -57,9 +58,7 @@ class FieldBlockDeriverTest extends EntityKernelTestBase {
|
|||
$this->assertNotContains('extra_field_block:user:user:member_for', $plugins);
|
||||
|
||||
// Exposing all field blocks adds them for the user entity type.
|
||||
\Drupal::configFactory()->getEditable('layout_builder.settings')
|
||||
->set('expose_all_field_blocks', TRUE)
|
||||
->save();
|
||||
\Drupal::service('module_installer')->install(['layout_builder_expose_all_field_blocks']);
|
||||
$plugins = $this->getBlockPluginIds();
|
||||
$this->assertContains('field_block:user:user:name', $plugins);
|
||||
$this->assertContains('extra_field_block:user:user:member_for', $plugins);
|
||||
|
|
Loading…
Reference in New Issue