Problem/Motivation

The LayoutBuilderTaskDeriver hardcodes local tasks for sectionStorage plugins.

Proposed resolution

The LayoutBuilderTaskDeriver should let the plugins build their own local tasks.

Remaining tasks

N/A

User interface changes

N/A

API changes

API addition: section storage plugins are now directly consulted when building local tasks (similar to how it is consulted for route building).

Data model changes

N/A

Comments

sugaroverflow created an issue. See original summary.

sugaroverflow’s picture

StatusFileSize
new11.68 KB

Worked on this patch with @tim.plunkett at mwds

sugaroverflow’s picture

Issue summary: View changes
tim.plunkett’s picture

Issue summary: View changes
Status: Active » Needs work
  1. +++ b/core/modules/layout_builder/src/Plugin/Derivative/LayoutBuilderLocalTaskDeriver.php
    @@ -8,7 +8,9 @@
    +use Symfony\Component\Routing\RouteCollection;
    

    I think this is unused.

  2. +++ b/core/modules/layout_builder/src/Plugin/Derivative/LayoutBuilderLocalTaskDeriver.php
    @@ -28,14 +30,26 @@ class LayoutBuilderLocalTaskDeriver extends DeriverBase implements ContainerDeri
    +  public function __construct(
    +    EntityTypeManagerInterface $entity_type_manager,
    +    SectionStorageManagerInterface $section_storage_manager) {
    

    Nit: Keep this on one line, please

  3. +++ b/core/modules/layout_builder/src/Plugin/Derivative/LayoutBuilderLocalTaskDeriver.php
    @@ -51,84 +66,11 @@ public static function create(ContainerInterface $container, $base_plugin_id) {
    -  protected function getEntityTypesForDefaults() {
    ...
    -  protected function getEntityTypesForOverrides() {
    

    It's so great to remove this duplicate code!

sugaroverflow’s picture

Status: Needs work » Needs review
StatusFileSize
new11.75 KB
new1.56 KB

Thank you for reviewing!

Uploading a new patch and interdiff. Running phpcs also removed two unused use statements from the deriver.

tim.plunkett’s picture

Status: Needs review » Reviewed & tested by the community

Yay! Thanks.

This is a great refactor that will allow other implementations of LB to participate in the local tasks building.

tim.plunkett’s picture

Assigned: sugaroverflow » Unassigned
damienmckenna’s picture

Is this something that could be backported to 8.6, or is it sufficient of an internal API change that it's out of consideration?

tim.plunkett’s picture

I see no reason this couldn't be backported, but that's up to the committers.

larowlan’s picture

Status: Reviewed & tested by the community » Needs review
+++ b/core/modules/layout_builder/src/SectionStorageInterface.php
@@ -78,6 +78,17 @@ public function getSectionListFromId($id);
+  public function buildLocalTasks($base_plugin_definition);

So I think this is an API change, as we don't have a base class so can't apply the 1:1 rule.

So I think we need a BC shim, which would be a new interface with this method and an instanceof check with a fall back.

tim.plunkett’s picture

Add an empty implementation to the base class, Drupal\layout_builder\Plugin\SectionStorage\SectionStorageBase.

larowlan’s picture

Perfect

samuel.mortenson’s picture

Status: Needs review » Reviewed & tested by the community

LGTM.

larowlan’s picture

Status: Reviewed & tested by the community » Needs review
Issue tags: +Needs change record

Thanks, can we get a change record here?

tim.plunkett’s picture

While trying to write the CR, I had a realization that while we absolutely need to provide Local Tasks in the current iteration of Layout Builder, we have no explicit need for them in the final designs. We're only using local tasks until #2936655: Layout Builder should use the toolbar modes system once it exists. is resolved.

So even though adding to the interface is supported by the BC policy, we don't want to.

CR is at https://www.drupal.org/node/2999418

jibran’s picture

Status: Needs review » Reviewed & tested by the community

This refactoring makes more sense IMO.

larowlan’s picture

Adding review credit

  • larowlan committed 58b776b on 8.7.x
    Issue #2995071 by tim.plunkett, sugaroverflow: Refactor...
larowlan’s picture

Status: Reviewed & tested by the community » Fixed

Committed 58b776b and pushed to 8.7.x. Thanks!

Published change record

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

webchick’s picture

Backported to 8.6.x also.

tim.plunkett’s picture

Issue tags: +Blocks-Layouts

Retroactively tagging