Problem/Motivation

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

In general, we want to be able to place a block at an arbitrary place in the set of blocks in the region.

Proposed resolution

The 1st place block modal goes to a link like:

/admin/structure/block/library/bartik?region=content

Add support for a weight query string. In the controller pass the query string along to the second modal at a path like:

/admin/structure/block/add/search_form_block/bartik?region=content&destination=/admin/structure/block/library/bartik

Add a hidden input to BlockForm and poppulate it from the query string, and make sure it's an int in validate/submit

Remaining tasks

Patch
Tests

User interface changes

none

API changes

none

Data model changes

none

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

pwolanin created an issue. See original summary.

xjm’s picture

Priority: Critical » Normal
pwolanin’s picture

Status: Active » Needs review
FileSize
1.9 KB

Quick start. NR for bot only.

Status: Needs review » Needs work

The last submitted patch, 3: 2787641-3.patch, failed testing.

pwolanin’s picture

Status: Needs work » Needs review
FileSize
2.4 KB
2.34 KB

Was setting the weight into the settings which is not needed.

How about this.

pwolanin’s picture

Issue tags: +Needs tests

Looks like this is working. Just needs some test coverage now.

Bojhan’s picture

Yes! Can we get a screenshot?

pwolanin’s picture

@Bojhan - screenshot of what? All it's doing it manipulating the query string at this point and using the data in the form. A follow-on would leverage that to make block_place work more consistently.

pwolanin’s picture

Some test coverage for the weight query string, plus a test that all the expected regions are in the block admin UI. The latter is just a bonus (I started there but then found a better place to add the weight test).

pwolanin’s picture

@Bojhan - this is the follow-up issue that will make the small UI behavior tweak: #2791305: Set block weight during Place Block flow so it's always at the top

pwolanin’s picture

Issue tags: -Needs tests
YesCT’s picture

  1. +++ b/core/modules/block/src/BlockForm.php
    @@ -180,6 +180,13 @@ public function form(array $form, FormStateInterface $form_state) {
    +    // Hidden weight setting.
    

    not a sentence. oh, I see this is the pattern in this method already. ok.

  2. +++ b/core/modules/block/src/Controller/BlockLibraryController.php
    @@ -119,6 +119,8 @@ public function listBlocks(Request $request, $theme) {
    +    $destination = $this->redirectDestination->get();
    
    @@ -144,7 +146,9 @@ public function listBlocks(Request $request, $theme) {
    -      $destination = $this->redirectDestination->get();
    

    this seems like an unrelated improvement.

  3. +++ b/core/modules/block/src/Tests/BlockTest.php
    @@ -172,6 +172,51 @@ public function testAddBlockFromLibrary() {
    +    foreach (['7', '-9'] as $weight) {
    

    oh, these are the only two values... maybe add zero, zero sometimes is a "funny" special case.

  4. +++ b/core/modules/block/src/Tests/BlockTest.php
    @@ -172,6 +172,51 @@ public function testAddBlockFromLibrary() {
    +      $links = $this->xpath('//a[contains(@href, :href)]', [':href' => $add_url->toString()]);
    +      $this->assertEqual(1, count($links), 'Found one matching link');
    

    this assert seems like a sanity check, and not anything to do with the weight.

  5. +++ b/core/modules/block/src/Tests/BlockTest.php
    @@ -172,6 +172,51 @@ public function testAddBlockFromLibrary() {
    +      $this->assertEqual(t('Place block'), (string) $links[0]);
    +      $this->assertEqual($weight, $query_parts['weight'], 'Expected weight query string is in href');
    

    are these two asserting the same thing? that the weight query is in the link?

  6. +++ b/core/modules/block/src/Tests/BlockTest.php
    @@ -172,6 +172,51 @@ public function testAddBlockFromLibrary() {
    +      // Ensure that the block was created.
    +      /** @var \Drupal\block\BlockInterface $block */
    +      $block = Block::load($block_id);
    +      $this->assertEqual($title, $block->label(), 'Found the block with expected title.');
    +      $this->assertEqual($weight, $block->getWeight(), 'Found the block with expected weight.');
    

    this test was copied from testAddBlockFromLibrary(), so that's where this comment came from, but I think the point in this test, is to ensure it has the weight, not only that it was created.

  7. +++ b/core/modules/block/src/Tests/BlockUiTest.php
    @@ -270,6 +271,27 @@ public function testMachineNameSuggestion() {
    +   * Tests the block placement UI.
    +   */
    +  public function testBlockPlacementUI() {
    

    this seems like unrelated improved test coverage, separate issue.

pwolanin’s picture

Ok, removed the "extra" test method and addressing other comments.

YesCT’s picture

Status: Needs review » Reviewed & tested by the community

I looked at every line changed in the patch, and discussed things with @pwolanin in IRC.

I think the changes here are now within scope (though related issues would be nice for the removed improvements)
and make sense to me.

Also looked at https://www.drupal.org/core/d8-allowed-changes#beta
allowed changes in beta, and I think this is 8.2.x because either
"minor API additions or ..., if the impact outweighs the disruption"
or
"Certain other issues with high impact and low disruption at committer discretion only."

so... good from me for now, rtbc.

pwolanin’s picture

This probably needs a trivial re-roll since #2791335: Optimize repeated method call in PlaceBlockPageVariant::build, use service instead of direct query string went in a changed a line within the diff context.

pwolanin’s picture

actually - never mind - BlockLibraryController also needs the optimization to move the destination call out of the foreach, but there is no conflict with the patch that went in.

Looks like this patch still applies fine at the moment.

alexpott’s picture

Is this enough? When ordering blocks in the current block UI we also change the weights of the surrounding blocks.

tim.plunkett’s picture

Title: Support setting block weight through place block modal dialogs and BlockForm » Add non-UI mechanism for setting block weight through block forms

Just retitling to hopefully cut down on confusion.

pwolanin’s picture

@alexpott - this patch should be sufficient to enable putting a new block always at the top (or bottom). that bit is implemented in the follow-up patch.

This alone might not be sufficient to place a new block arbitrarily within the middle of existing blocks, since they might need to be shifted as you say.

tkoleary’s picture

@pwolanin

Re: #2739079: Reduce visual clutter of Place Block module

the change I'm proposing has no impact on the UI of the modals, only passes data along in the query string. Check out the patch.

The fact that this patch has no visible UI change does not ipso facto imply "we don't need to look at a design". The attitude that we can write the code and 'paint it with some UX' after the fact is a recipe for wasted effort and technical debt.

Different designs imply different data models. Imagine, for example that we had a design that included a button to 'maintain relative position' when moving a block from one region to another eg. based on the blocks visible to the current user, if in region A, block 1 is third from the top, when I move it to region B, it should still be third from the top. That's not a feature I'm currently designing, but if it were I'm pretty certain that this patch would need major refactor to handle it.

pwolanin’s picture

@tkoleary - please look at the patch. Your comments don't make sense. There is no change to the data model. This is only applied to new blocks.

YesCT’s picture

See #2793053: Optimize repeated method call in BlockLibraryController for the destination optimization that was descoped in #13 (see interdiff)

(rerolls should be "easy" on either issue, context lines kind of thing.)

tkoleary’s picture

@pwolanin

Spoke to Emily in UX meeting and she's confident in the direction, so I'll take her word for it.

  • xjm committed ea28d66 on 8.3.x
    Issue #2787641 by pwolanin, YesCT: Add non-UI mechanism for setting...

  • xjm committed 629b6f2 on 8.2.x
    Issue #2787641 by pwolanin, YesCT: Add non-UI mechanism for setting...
xjm’s picture

Status: Reviewed & tested by the community » Fixed

Thanks everyone!

@tkoleary, this patch has no impact on the UI whatsoever (nor the data model, which also has nothing to do with the UI anyway. Data model ≠ data modeling tools.) There's nothing to "paint with UX" because it's just internal API support for future feature additions to the form workflow for placing blocks. Any followups that actually add/change the UI will of course need some usability review according to their module stability (minimal validation in the case of Place Block).

I think @alexpott's question is addressed by the comments above; I agree with @pwolanin (and the retitle) that this functionality is sufficient for now. If we need more later, we can add it then.

This is a BC addition to internal form functionality, so beta-safe. I checked with @tim.plunkett as a subsystem maintainer for both Block and Form API and he signed off on the change. My one question was whether we should document this request option, but according to @tim.plunkett we don't do that elsewhere either.

Committed ea28d66 and pushed to 8.3.x and 8.2.x. Thanks!

pwolanin’s picture

Thanks xjm! will wrap up the follow-up issue

Status: Fixed » Closed (fixed)

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