Skip to content
Snippets Groups Projects
Commit e8eb6b8f authored by jurgenhaas's avatar jurgenhaas
Browse files

Revert a patch update for Drupal 10.2

parent 96068d3e
No related branches found
No related tags found
1 merge request!155Merging develop into main
......@@ -51,7 +51,7 @@
"#2647292 Date/time Views filter tries strotime() relative to Unix epoch": "https://www.drupal.org/files/issues/2024-03-17/with-dependency-injection-2647292-75.patch",
"#2884879 Ignore empty fields for REST export": "https://www.drupal.org/files/issues/2884879-11.patch",
"#2966735 Workaround for DateTime exposed filter": "https://gitlab.lakedrops.com/composer/plugin/drupal-environment/-/raw/main/patches/d10/2966735.diff",
"#3043879 Layout Builder Config": "https://gitlab.lakedrops.com/composer/plugin/drupal-environment/-/raw/main/patches/d10/3043879.diff?v=2",
"#3043879 Layout Builder Config": "https://gitlab.lakedrops.com/composer/plugin/drupal-environment/-/raw/main/patches/d10/3043879-new.diff",
"#3195171 Fix view header group rendering": "https://www.drupal.org/files/issues/2022-01-05/3195171-7-fix-view-header-group-rendering.patch",
"#3180227 Missing options for entity refernces in views": "https://www.drupal.org/files/issues/2020-11-02/3180227-2.patch",
"#local Json API and entity reference warnings": "https://gitlab.lakedrops.com/composer/plugin/drupal-environment/-/raw/main/patches/jsonapi-entityref-warning.patch?v=3",
......
diff --git a/core/lib/Drupal/Core/Layout/LayoutDefault.php b/core/lib/Drupal/Core/Layout/LayoutDefault.php
index bd3780987a..8fc99d76ea 100644
--- a/core/lib/Drupal/Core/Layout/LayoutDefault.php
+++ b/core/lib/Drupal/Core/Layout/LayoutDefault.php
@@ -8,6 +8,7 @@
use Drupal\Core\Plugin\ContextAwarePluginTrait;
use Drupal\Core\Plugin\PluginBase;
use Drupal\Core\Plugin\PluginFormInterface;
+use Drupal\Core\Plugin\PluginWithFormsTrait;
use Drupal\Core\Plugin\PreviewAwarePluginInterface;
/**
@@ -17,6 +18,7 @@ class LayoutDefault extends PluginBase implements LayoutInterface, PluginFormInt
use ContextAwarePluginAssignmentTrait;
use ContextAwarePluginTrait;
+ use PluginWithFormsTrait;
/**
* Whether the plugin is being rendered in preview mode.
@@ -127,6 +129,13 @@ public function submitConfigurationForm(array &$form, FormStateInterface $form_s
$this->configuration['label'] = $form_state->getValue('label');
}
+ /**
+ * {@inheritdoc}
+ */
+ public function getFormClass($operation) {
+ return $this->getPluginDefinition()->get('forms')[$operation] ?? static::class;
+ }
+
/**
* {@inheritdoc}
*/
diff --git a/core/lib/Drupal/Core/Layout/LayoutInterface.php b/core/lib/Drupal/Core/Layout/LayoutInterface.php
index 33858a546d..2e62ba85da 100644
--- a/core/lib/Drupal/Core/Layout/LayoutInterface.php
+++ b/core/lib/Drupal/Core/Layout/LayoutInterface.php
@@ -7,11 +7,12 @@
use Drupal\Component\Plugin\ConfigurableInterface;
use Drupal\Component\Plugin\DependentPluginInterface;
use Drupal\Core\Plugin\ContextAwarePluginInterface;
+use Drupal\Core\Plugin\PluginWithFormsInterface;
/**
* Provides an interface for static Layout plugins.
*/
-interface LayoutInterface extends PluginInspectionInterface, DerivativeInspectionInterface, ConfigurableInterface, DependentPluginInterface, ContextAwarePluginInterface {
+interface LayoutInterface extends PluginInspectionInterface, DerivativeInspectionInterface, ConfigurableInterface, DependentPluginInterface, ContextAwarePluginInterface, PluginWithFormsInterface {
/**
* Build a render array for layout with regions.
diff --git a/core/modules/layout_builder/src/Controller/ChooseSectionController.php b/core/modules/layout_builder/src/Controller/ChooseSectionController.php
index 46b969e2f8..bc22d1f004 100644
--- a/core/modules/layout_builder/src/Controller/ChooseSectionController.php
+++ b/core/modules/layout_builder/src/Controller/ChooseSectionController.php
@@ -4,8 +4,10 @@
use Drupal\Core\Ajax\AjaxHelperTrait;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
+use Drupal\Core\Layout\LayoutInterface;
use Drupal\Core\Layout\LayoutPluginManagerInterface;
use Drupal\Core\Plugin\PluginFormInterface;
+use Drupal\Core\Plugin\PluginWithFormsInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\Url;
use Drupal\layout_builder\Context\LayoutBuilderContextTrait;
@@ -52,6 +54,23 @@ public static function create(ContainerInterface $container) {
);
}
+ /**
+ * Determines if the layout provides a configuration form.
+ *
+ * @param \Drupal\Core\Layout\LayoutInterface $layout
+ * The layout plugin.
+ *
+ * @return bool
+ * TRUE if the layout has a configure form, FALSE otherwise.
+ */
+ protected function hasConfigurationForm(LayoutInterface $layout) {
+ if ($layout instanceof PluginWithFormsInterface && $layout->hasFormClass('configure')) {
+ return TRUE;
+ }
+
+ return $layout instanceof PluginFormInterface;
+ }
+
/**
* Choose a layout plugin to add as a section.
*
@@ -78,7 +97,7 @@ public function build(SectionStorageInterface $section_storage, int $delta) {
],
],
'#url' => Url::fromRoute(
- $layout instanceof PluginFormInterface ? 'layout_builder.configure_section' : 'layout_builder.add_section',
+ $this->hasConfigurationForm($layout) ? 'layout_builder.configure_section' : 'layout_builder.add_section',
[
'section_storage_type' => $section_storage->getStorageType(),
'section_storage' => $section_storage->getStorageId(),
diff --git a/core/modules/layout_builder/src/Element/LayoutBuilder.php b/core/modules/layout_builder/src/Element/LayoutBuilder.php
index 451927e540..8234a476ab 100644
--- a/core/modules/layout_builder/src/Element/LayoutBuilder.php
+++ b/core/modules/layout_builder/src/Element/LayoutBuilder.php
@@ -3,8 +3,10 @@
namespace Drupal\layout_builder\Element;
use Drupal\Core\Ajax\AjaxHelperTrait;
+use Drupal\Core\Layout\LayoutInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Plugin\PluginFormInterface;
+use Drupal\Core\Plugin\PluginWithFormsInterface;
use Drupal\Core\Render\Attribute\RenderElement;
use Drupal\Core\Render\Element;
use Drupal\Core\Render\Element\RenderElement as RenderElementBase;
@@ -325,6 +327,7 @@ protected function buildAdministrativeSection(SectionStorageInterface $section_s
$build['#attributes']['class'][] = 'layout-builder__layout';
$build['#attributes']['data-layout-builder-highlight-id'] = $this->sectionUpdateHighlightId($delta);
+ $has_configure_form = $this->hasConfigurationForm($layout);
return [
'#type' => 'container',
'#attributes' => [
@@ -354,12 +357,12 @@ protected function buildAdministrativeSection(SectionStorageInterface $section_s
// link, and is only visible when the move block dialog is open.
'section_label' => [
'#markup' => $this->t('<span class="layout-builder__section-label" aria-hidden="true">@section</span>', ['@section' => $section_label]),
- '#access' => !$layout instanceof PluginFormInterface,
+ '#access' => !$has_configure_form,
],
'configure' => [
'#type' => 'link',
'#title' => $this->t('Configure @section', ['@section' => $section_label]),
- '#access' => $layout instanceof PluginFormInterface,
+ '#access' => $has_configure_form,
'#url' => Url::fromRoute('layout_builder.configure_section', [
'section_storage_type' => $storage_type,
'section_storage' => $storage_id,
@@ -379,4 +382,21 @@ protected function buildAdministrativeSection(SectionStorageInterface $section_s
];
}
+ /**
+ * Determines if the layout provides a configuration form.
+ *
+ * @param \Drupal\Core\Layout\LayoutInterface $layout
+ * The layout plugin.
+ *
+ * @return bool
+ * TRUE if the layout has a configure form, FALSE otherwise.
+ */
+ protected function hasConfigurationForm(LayoutInterface $layout) {
+ if ($layout instanceof PluginWithFormsInterface && $layout->hasFormClass('configure')) {
+ return TRUE;
+ }
+
+ return $layout instanceof PluginFormInterface;
+ }
+
}
diff --git a/core/modules/layout_builder/tests/modules/layout_builder_test/layout_builder_test.module b/core/modules/layout_builder/tests/modules/layout_builder_test/layout_builder_test.module
index fa027a6b01..443bbcfdfa 100644
--- a/core/modules/layout_builder/tests/modules/layout_builder_test/layout_builder_test.module
+++ b/core/modules/layout_builder/tests/modules/layout_builder_test/layout_builder_test.module
@@ -13,6 +13,7 @@
use Drupal\Core\Link;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Url;
+use Drupal\layout_builder_test\PluginForm\CustomLayoutForm;
/**
* Implements hook_plugin_filter_TYPE__CONSUMER_alter().
@@ -177,6 +178,27 @@ function layout_builder_test_module_implements_alter(&$implementations, $hook) {
}
}
+/**
+ * Implements hook_layout_alter().
+ */
+function layout_builder_test_layout_alter(&$definitions) {
+ /** @var \Drupal\Core\Layout\LayoutDefinition[] $definitions */
+ $forms['configure'] = CustomLayoutForm::class;
+ $definitions['layout_builder_test_no_form_plugin']->set('forms', $forms);
+ if (isset($definitions['layout_test_plugin'])) {
+ $definitions['layout_test_plugin']->set('forms', $forms);
+ }
+}
+
+/**
+ * Implements hook_preprocess_HOOK() for layout templates.
+ */
+function layout_builder_test_preprocess_layout(&$variables) {
+ if (isset($variables['settings']['custom_element'])) {
+ $variables['content']['main']['custom_element']['#markup'] = $variables['settings']['custom_element'];
+ }
+}
+
/**
* Implements hook_theme().
*/
diff --git a/core/modules/layout_builder/tests/src/Functional/LayoutBuilderTest.php b/core/modules/layout_builder/tests/src/Functional/LayoutBuilderTest.php
index 631159a8b3..24f0ff05e7 100644
--- a/core/modules/layout_builder/tests/src/Functional/LayoutBuilderTest.php
+++ b/core/modules/layout_builder/tests/src/Functional/LayoutBuilderTest.php
@@ -458,6 +458,46 @@ public function testPreviewAwareTemplates() {
$assert_session->pageTextNotContains('This is a preview, indeed');
}
+ /**
+ * Tests a layout with a custom form.
+ */
+ public function testCustomForm() {
+ $assert_session = $this->assertSession();
+ $page = $this->getSession()->getPage();
+
+ $this->drupalLogin($this->drupalCreateUser(['configure any layout']));
+
+ LayoutBuilderEntityViewDisplay::load('node.bundle_with_section_field.default')
+ ->enableLayoutBuilder()
+ ->setOverridable()
+ ->save();
+
+ $this->drupalGet('node/1');
+ $page->clickLink('Layout');
+
+ // Test a custom plugin form that is specified by the plugin annotation.
+ $page->clickLink('Add section');
+ $page->clickLink('Layout Builder Test Custom Form Plugin');
+ $page->fillField('layout_settings[custom_element]', 'This is a custom form specified by the plugin');
+ $page->pressButton('Add section');
+ $assert_session->pageTextContains('This is a custom form specified by the plugin');
+
+ // Test a custom plugin form that is altered onto a plugin that has no form.
+ $page->clickLink('Add section');
+ $page->clickLink('Layout Builder Test No Form Plugin');
+ $page->fillField('layout_settings[custom_element]', 'This had no form now it does');
+ $page->pressButton('Add section');
+ $assert_session->pageTextContains('This had no form now it does');
+
+ // Test a custom plugin form that is altered onto a plugin that has an
+ // existing form.
+ $page->clickLink('Add section');
+ $page->clickLink('Layout Builder Test No Form Plugin');
+ $page->fillField('layout_settings[custom_element]', 'This had an existing form now it has more');
+ $page->pressButton('Add section');
+ $assert_session->pageTextContains('This had an existing form now it has more');
+ }
+
/**
* Tests that extra fields work before and after enabling Layout Builder.
*/
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment