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
- install drupal 8
- enable block_place module (
drush en -y block_place) - 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
| Comment | File | Size | Author |
|---|---|---|---|
| #35 | 2791305-33.patch | 5.23 KB | yesct |
| #35 | interdiff.2791305.29.33.txt | 2.76 KB | yesct |
| #29 | increment-2791305-29.txt | 1.35 KB | pwolanin |
| #29 | 2791305-29.patch | 4.79 KB | pwolanin |
| #22 | 2791305-22-TEST_ONLY.patch | 3.6 KB | pwolanin |
Comments
Comment #2
pwolanin commentedHere'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
Comment #3
pwolanin commentedComment #5
pwolanin commentedHmm, ok let's check that #weight is set.
Comment #6
yesct commentedComment #7
pwolanin commentedre-roll for conflict in context
Comment #8
pwolanin commentedok, 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.
Comment #11
pwolanin commentedSporadic fail in big pipe tests?
Should maybe change the initial block creation to just use entity calls and not the UI in the test?
Comment #12
yesct commentedSince this isn't about testing the block creation ui, yes, I think block creation can use entity calls.
Comment #13
pwolanin commented@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.
Comment #14
pwolanin commentedOk, fund a test trait to use for block creation, which makes this test method much cleaner.
Comment #15
yesct commentedThat looks really great (fewer lines when using the trait).
I'm gonna review this.
Comment #16
yesct commentedin the meantime, here is a tests only patch with the new trait changes.
Comment #18
yesct commentedThere is only one fail in the test.
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.
Comment #19
yesct commentedManual 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.
Comment #20
yesct commentedjust 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.)
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
Comment #21
pwolanin commented@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)
Comment #22
pwolanin commentedOk, rewrote the test a little to use a data provider so each expected assertion failure should show up in the test only patch.
Comment #24
pwolanin commentedhmm, bot now sets to CNW if the 2nd patch fails?
Comment #25
dawehnerYeah, the test only patch has to be the first one.
Comment #26
dawehnerCouldn't you use
$this->assertSession()->linkByHrefExists()and then simply use$this->drupalGet($block_library_url)?Comment #27
pwolanin commented@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.
Comment #28
dawehnerAh that makes sense!
What about doing some quick comment about that?
Comment #29
pwolanin commentedok, minor simplification and new code comment requested by dawehner in IRC
Comment #30
dawehnerThank you @pwolanin!
Comment #31
xjmAs a change to a new experimental module, his is an rc-eligible change per: https://www.drupal.org/core/d8-allowed-changes#rc
Comment #32
yesct commentedwith the change to use data provider, this comment probably needs to be changed and/or moved to the provider.
what is $extra_block_at_zero for?
Comment #33
pwolanin commented@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.
Comment #34
xjmFor #32 and #33.
Comment #35
yesct commentedDid 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).
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.]
Comment #36
yesct commentedI'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?
Comment #37
pwolanin commentedWe 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()
Comment #38
pwolanin commentedInterdiff looks fine to me, thanks. Good especially to remove the one stale comment.
Comment #40
Bojhan commentedGreat work, love these small improvements!
Comment #41
yesct commentedpatch still applies. not sure what the test fail was. sending for retesting.
Comment #43
nerdsteinUpdating 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).
Comment #44
Bojhan commented@ted Can you take a look at this?
Comment #45
nerdsteinThe 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
Comment #46
nerdsteinIt 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.
Comment #55
smustgrave commentedBlock place was superseded by layout builder in 8.7 moving to contrib,