Problem/Motivation

By doing this I'm able to do even more useful filtering when adding blocks.

Here are some suggested use cases where this would be helpful:

a) You would like to filter blocks on the delta(s). For instance, you may only add a Header block in the first section (as per example, in the test case)
b) This could also be used to ensure that you only add X number of a block to a section.
c) We would like to filter down the blocks per layout. You may only use these blocks in this layout, etc.

So, the point is that we need the Section delta, to retrieve the section to be able to adjust the blocks available to be added in that section, or apply rules given the section position.

Proposed resolution

Add delta :)

Remaining tasks

Review patch.

User interface changes

API changes

Data model changes

Comments

johndevman created an issue. See original summary.

johnwebdev’s picture

StatusFileSize
new2.44 KB
new3.2 KB
johnwebdev’s picture

Status: Active » Needs review
johnwebdev’s picture

StatusFileSize
new2.61 KB
new3.37 KB

Patch above cancelled because some obvious mistakes. Here is a new one.

It looks like:

   * @param int $delta
   *   The delta of the section to splice.

is actually a string, and not a int. Probably something to be fixed as well, but for now I just checked it as a string.

The last submitted patch, 2: 2973615-2.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

The last submitted patch, 2: 2973615-2--testonly.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

The last submitted patch, 4: 2973615-3--testonly.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

tim.plunkett’s picture

I'm shocked that $delta is a string!

-  public function build(SectionStorageInterface $section_storage, $delta, $region) {
+  public function build(SectionStorageInterface $section_storage, int $delta, $region) {

This change fixes everything, but is invalid in PHP 5.

For now I guess we should do $delta = (int) $delta; with a code comment of some sort.


I debated when adding this hook about passing delta, but couldn't think of a use case where knowing the numeric delta would actually help.
Can you expand the Issue Summary to better explain the use case?

johnwebdev’s picture

Issue summary: View changes
johnwebdev’s picture

StatusFileSize
new3.58 KB
new2.61 KB
johnwebdev’s picture

StatusFileSize
new1.29 KB

Forgot interdiff. I also updated IS with some use cases.

Status: Needs review » Needs work

The last submitted patch, 10: 2973615-10--testonly.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

johnwebdev’s picture

Status: Needs work » Needs review
johnzzon’s picture

  1. +++ b/core/modules/layout_builder/src/Controller/ChooseBlockController.php
    @@ -63,8 +63,12 @@ public function build(SectionStorageInterface $section_storage, $delta, $region)
    +    // Currently delta is passed as a string, so we'll explicitily convert it to a integer.
    

    Line exceeds 80 chars.

  2. +++ b/core/modules/layout_builder/tests/src/Functional/LayoutBuilderTest.php
    @@ -351,6 +351,24 @@ public function testLayoutBuilderChooseBlocksAlter() {
    +    //Verify that Changed block is present on second section.
    

    Missing space at start of comment.

Other than that, this patch looks great! Works perfectly to allow me to filter the available blocks in my layouts.

johnwebdev’s picture

StatusFileSize
new3.59 KB
new1.33 KB

Adressed feedback in #14.

tim.plunkett’s picture

Status: Needs review » Needs work

I still can't personally envision using the specific delta, especially for anything other than $delta===0.
But there's nothing wrong with adding this, and if it's useful for others, might as well!

+++ b/core/modules/layout_builder/src/Controller/ChooseBlockController.php
@@ -63,8 +63,13 @@ public function build(SectionStorageInterface $section_storage, $delta, $region)
+    // Currently delta is passed as a string, so we'll explicitily convert it
+    // to a integer.
+    $delta = (int) $delta;

Explicitly is misspelled. Can we get an @todo for an issue to remove this cast?

johnwebdev’s picture

johnwebdev’s picture

StatusFileSize
new3.66 KB
new830 bytes
johnwebdev’s picture

Status: Needs work » Needs review
tim.plunkett’s picture

Looks great, just a minor doc nit

  1. +++ b/core/modules/layout_builder/src/Controller/ChooseBlockController.php
    @@ -63,8 +63,14 @@ public function build(SectionStorageInterface $section_storage, $delta, $region)
    +    // Currently delta is passed as a string, so we'll explicitly convert it
    +    // to a integer.
    +    // @TODO Fix in https://www.drupal.org/project/drupal/issues/2984509
    

    Can you rewrite this to:

        // @todo Explicitly cast delta to an integer, remove this in
        //   https://www.drupal.org/project/drupal/issues/2984509.
    

    (note the lowercase todo, the indent for the second line, and the trailing period)

  2. +++ b/core/modules/layout_builder/tests/modules/layout_builder_test/layout_builder_test.module
    @@ -26,4 +31,5 @@ function layout_builder_test_plugin_filter_block__layout_builder_alter(array &$d
       }
    +
     }
    

    Extra blank line

tim.plunkett’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new3.47 KB
new1.54 KB

Since these were minor changes, doing it myself and RTBCing.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed 0c3ea72 and pushed to 8.6.x. Thanks!

  • alexpott committed 0c3ea72 on 8.6.x
    Issue #2973615 by johndevman, tim.plunkett, johnzzon: Add Section delta...

Status: Fixed » Closed (fixed)

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

jdleonard’s picture

The patch committed only partially resolved this issue (it addressed non-inline blocks, but did not address inline blocks). I have provided a follow-up patch in #3038981: Inline blocks missing section delta extra data on filtered block definitions

tim.plunkett’s picture

Issue tags: +Blocks-Layouts

Retroactively tagging