Postponed until resolution of #2784495: Normalize block place and outside-in experiences

Follow-up to #2787641: Add non-UI mechanism for setting block weight through block forms

Problem/Motivation

To support the expected user interaction in #2739079: Reduce visual clutter of Place Block module we need to have the block at least show up at the top of the region.

Proposed resolution

#2787641: Add non-UI mechanism for setting block weight through block forms
Added support for a weight query string.

In this patch we populate the query string during the Place Block flow so that each new block shows up at the top of the region as suggested by the link position in the UI.

Place block is an experimental module https://www.drupal.org/core/experimental and has different requirements for inclusion in core https://www.drupal.org/core/experimental#requirements,
this is an rc-eligible change per: https://www.drupal.org/core/d8-allowed-changes#rc

Remaining tasks

User interface changes

The newly placed block is always at the top of the region, instead of sometimes appearing in the middle or below existing blocks.

Manual Steps to Reproduce

  1. install drupal 8
  2. enable block_place module (drush en -y block_place)
  3. add a block (click place block in the toolbar, scroll to footer, click +, add who's online block)

API changes

none

Data model changes

none

Comments

pwolanin created an issue. See original summary.

pwolanin’s picture

Here's a patch on top of the patch from comment #9 in #2787641: Add non-UI mechanism for setting block weight through block forms. It only works in combination with that patch, but doesn't cause any harm by itself. Probably needs some tests added.

It's so trivial it might be worth combining it with the prior issue..

Screen shot also attached so show query string being populated. Note that this doesn't have the styling changes yet from #2739079: Reduce visual clutter of Place Block module

pwolanin’s picture

Issue tags: -MWDS2016

Status: Needs review » Needs work

The last submitted patch, 2: 2791305-2.patch, failed testing.

pwolanin’s picture

Status: Needs work » Needs review
StatusFileSize
new1.07 KB
new964 bytes

Hmm, ok let's check that #weight is set.

yesct’s picture

Issue tags: +Usability
pwolanin’s picture

StatusFileSize
new1.07 KB

re-roll for conflict in context

pwolanin’s picture

StatusFileSize
new5.31 KB
new4.24 KB

ok, here's a first pass at a new test method. Might need to DRY up a little.

The increment is also the test-only patch which should fail.

The last submitted patch, 8: 2791305-8.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 8: increment-2791305-8.patch, failed testing.

pwolanin’s picture

Sporadic fail in big pipe tests?

Should maybe change the initial block creation to just use entity calls and not the UI in the test?

yesct’s picture

Since this isn't about testing the block creation ui, yes, I think block creation can use entity calls.

pwolanin’s picture

@YesCT well, it's about the UI for the 2 blocks created at the end to verify the links end up making them with lower weights, but yeah, the 2 initial blocks don't need to use the UI, or maybe even shouldn't.

pwolanin’s picture

Status: Needs work » Needs review
StatusFileSize
new4.4 KB
new2.81 KB

Ok, fund a test trait to use for block creation, which makes this test method much cleaner.

yesct’s picture

That looks really great (fewer lines when using the trait).

I'm gonna review this.

yesct’s picture

StatusFileSize
new3.33 KB

in the meantime, here is a tests only patch with the new trait changes.

Status: Needs review » Needs work

The last submitted patch, 16: 2791305-16-tests-only.patch, failed testing.

yesct’s picture

Status: Needs work » Needs review
+++ b/core/modules/block_place/tests/src/Functional/BlockPlaceTest.php
@@ -69,8 +72,53 @@ public function testPlacingBlocksUnprivileged() {
+    $this->placeBlock($block_plugin_id, ['region' => 'sidebar_first', 'weight' => -5]);
+    $this->placeBlock($block_plugin_id, ['region' => 'sidebar_second', 'weight' => 3]);
...
+    foreach (['sidebar_first' => -6, 'sidebar_second' => 2] as $region => $expected_weight) {

There is only one fail in the test.

fail: [Other] Line 83 of core/modules/block_place/tests/src/Functional/BlockPlaceTest.php:
Failed asserting that 0 matches expected -6.

Is this because for the weight == 3 case, the default happened to be.. 0? so it was added first in that case anyway? I want to make sure we have (all) the fails we were expecting.

Reading the test, (and this might be ok), it seems the test is testing for weight of block added being a specific weight (one less than the lightest block existing in the region), and not that the block is "listed first". Listed first is probably more difficult to test.

yesct’s picture

Issue summary: View changes
StatusFileSize
new151.94 KB

Manual test of adding who's online block to the footer, shows that without this patch, it gets added in the middle, and with this patch, it gets added first in that region.

yesct’s picture

StatusFileSize
new639 bytes
new4.39 KB

just whitespace nits.

https://www.drupal.org/node/608152#indenting

(while it says what to do between a class and property/method, and doesn't say there what to do between a class and use trait, a grep shows there is much more often in core a newline between the class and use trait.)

11022 → ag -B3 "class.*\n.*\n.*use.*Trait" core  | wc -l
    2322
11032 → ag -B3 "class.*\n.*use.*Trait" core  | wc -l
     470

the removed empty line before the class closing brace, though, should be put back (though also not blocking)

--

I looked but could not (re)find the issue for (proposed, and thus non-blocking) standard on ordering (alphabetical, with case complications) of use statements

--

Only potential real block here, is question about test fails in #18

pwolanin’s picture

@YesCT - since this is a phpunit-based web test, I believe it stops at the first failure, so you will only ever see the first failed assertion (unlike simpletest)

pwolanin’s picture

StatusFileSize
new4.66 KB
new4.29 KB
new3.6 KB

Ok, rewrote the test a little to use a data provider so each expected assertion failure should show up in the test only patch.

Status: Needs review » Needs work

The last submitted patch, 22: 2791305-22-TEST_ONLY.patch, failed testing.

pwolanin’s picture

Status: Needs work » Needs review

hmm, bot now sets to CNW if the 2nd patch fails?

dawehner’s picture

hmm, bot now sets to CNW if the 2nd patch fails?

Yeah, the test only patch has to be the first one.

dawehner’s picture

+++ b/core/modules/block_place/tests/src/Functional/BlockPlaceTest.php
@@ -69,8 +73,69 @@ public function testPlacingBlocksUnprivileged() {
+    $links = $this->xpath('//a[contains(@href, :href)]', [':href' => $block_library_url->toString()]);
+    $this->assertEquals(1, count($links));
...
+    $links = $this->xpath('//a[contains(@href, :href)]', [':href' => $block_add_url->toString()]);
+    $this->assertEquals(1, count($links));

Couldn't you use $this->assertSession()->linkByHrefExists() and then simply use $this->drupalGet($block_library_url)?

pwolanin’s picture

@dawehner - not really, since we are using "contains" and finding the full link with additional query parameters is necessary for the drupalGet() to go to the correct URL.

You may complain instead that this is a bit fragile since it would break if the region is not the 1st query parameter.

dawehner’s picture

Ah that makes sense!
What about doing some quick comment about that?

pwolanin’s picture

StatusFileSize
new4.79 KB
new1.35 KB

ok, minor simplification and new code comment requested by dawehner in IRC

dawehner’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs tests

Thank you @pwolanin!

xjm’s picture

Issue tags: +rc eligible

As a change to a new experimental module, his is an rc-eligible change per: https://www.drupal.org/core/d8-allowed-changes#rc

yesct’s picture

  1. +++ b/core/modules/block_place/tests/src/Functional/BlockPlaceTest.php
    @@ -69,8 +73,69 @@ public function testPlacingBlocksUnprivileged() {
    +    // Enable a standard block in first and second sidebars with set weights.
    

    with the change to use data provider, this comment probably needs to be changed and/or moved to the provider.

  2. +++ b/core/modules/block_place/tests/src/Functional/BlockPlaceTest.php
    @@ -69,8 +73,69 @@ public function testPlacingBlocksUnprivileged() {
    +    $this->placeBlock($block_plugin_id, ['region' => $region, 'weight' => $weight]);
    +    if ($extra_block_at_zero) {
    +      $this->placeBlock($block_plugin_id, ['region' => $region, 'weight' => 0]);
    

    what is $extra_block_at_zero for?

pwolanin’s picture

@YesCT - so we can add one at weight 3, and an extra one at 0, and check that the added block is at -1 not +2 as it was in the prior example.

Could add a 4th example to show that extra block doesn't change the negative weight case.

xjm’s picture

Status: Reviewed & tested by the community » Needs review

For #32 and #33.

yesct’s picture

Issue summary: View changes
StatusFileSize
new2.76 KB
new5.23 KB

Did 1.

I think the answer to 2. is that was a way to have two blocks sometimes in the test, and that zero can be a special case sometimes, so made sense to have a test case with a block whose weight is zero.

I also added a period to the comment in the data provider. Grepping says we almost always do that (152 out of 164 have the period).

10300 → ag "Data provider for.*\." core | wc -l
     152
10301 → ag "Data provider for" core | wc -l
     164

The added test (and data for it) didn't mention anywhere what the expected weight meant (on top). So I added that, and an @see to the method where the weight of "on top" is set.

Took out the custom message in the assert (the default message having the values is nice), moved the info to comments. [edit: or ... did we fix that, so we always get the default message (with the values) now.]

[edit: re #33, I see. I think that's fine.]

yesct’s picture

+++ b/core/modules/block_place/tests/src/Functional/BlockPlaceTest.php
@@ -69,8 +73,81 @@ public function testPlacingBlocksUnprivileged() {
+    $this->assertEquals(1, count($links));
...
+    $this->assertEquals(1, count($links));

I'm not clear on why we have asserts here that the links are found. Is what we are testing (asserting) that the weight is in the urls as a query param?

pwolanin’s picture

We are asserting we found the link with the REGION in the query param, but the test will fail if the weight query param isn't present in the full link we use for drupalGet()

pwolanin’s picture

Status: Needs review » Reviewed & tested by the community

Interdiff looks fine to me, thanks. Good especially to remove the one stale comment.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 35: 2791305-33.patch, failed testing.

Bojhan’s picture

Great work, love these small improvements!

yesct’s picture

patch still applies. not sure what the test fail was. sending for retesting.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

nerdstein’s picture

Component: block.module » block_place.module

Updating the component of this issue to "block_place.module", which was added at drupalcon baltimore.

I'm attempting to sort out how this issue relates to https://www.drupal.org/node/2735277, which is a "must have" to graduate the place_block module (found here: https://www.drupal.org/node/2739075).

Bojhan’s picture

Assigned: Unassigned » tedbow

@ted Can you take a look at this?

nerdstein’s picture

The status of the issue appears to be correct as-is.

I have applied the patch found in comment #35.

I can confirm that the block is first when originally placed into a region after saving. Upon saving, the weight of the block differs from that of what was attempted to be saved. This can be demonstrated by just clicking "save" on the block layout form without changing the block weight (it should be first).

Here is a video to show what I've found: https://youtu.be/n9oiXzO7QKU

nerdstein’s picture

Issue summary: View changes
Status: Needs work » Postponed

It may be worthwhile revisiting this issue if #2784495: Normalize block place and outside-in experiences gets committed. The workflow will be changing some and it's not clear to me how it will impact the work done here.

As such, I'm marking this as "Postponed" and updating the issue status.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave’s picture

Project: Drupal core » Place blocks
Version: 9.4.x-dev » 2.x-dev
Component: block_place.module » Code

Block place was superseded by layout builder in 8.7 moving to contrib,