Problem/Motivation
When creating a new block via block layout region is not stored.
Steps to reproduce
1) Go to /admin/structure/blocks
2) Use the 'Place Block' function next to a region, for example the 'Sidebar Second'.
3) Choose 'add custom block'
4) On the 'Configure Block'-page the region you've selected on step #2 is not selected.
Proposed resolution
Use a URL parameter to remember/set the region like we do for theme
Remaining tasks
User interface changes
When creating a new block the region will be remembered.
API changes
NA
Data model changes
NA
Release notes snippet
NA
Comment | File | Size | Author |
---|---|---|---|
#75 | 2833116-nr-bot.txt | 90 bytes | needs-review-queue-bot |
#73 | 2833116-nr-bot.txt | 2.67 KB | needs-review-queue-bot |
#66 | 2833116-nr-bot.txt | 90 bytes | needs-review-queue-bot |
#64 | Screenshot 2023-12-01 135315.png | 46.49 KB | Nitin shrivastava |
Issue fork drupal-2833116
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
Peter van den Heuvel CreditAttribution: Peter van den Heuvel commentedComment #3
cilefen CreditAttribution: cilefen commentedComment #8
quietone CreditAttribution: quietone at PreviousNext commentedI tested this on Drupal 10.0.x and the problem still exists.
Comment #9
_shYI made a small investigation about that.
Seems like the region set in the
core/modules/block/src/BlockForm.php
and it's taken from the request.But, when we redirect to this form, regions don't pass through request.
So, first I add the route parameter for the action link ("Add custom block"). And later, when we create our custom block, add this parameter to the form state redirect method in
core/modules/block_content/src/BlockContentForm.php
Comment #10
_shYComment #12
_shYReworked patch. Now all tests must pass.
Comment #13
_shYComment #14
Rinku Jacob 13 CreditAttribution: Rinku Jacob 13 at Srijan | A Material+ Company for Drupal India Association commentedI have applied the Patch #12 Successfully for drupal 9.3.x-dev. Before applying the patch the region we have selected in the place block function is not displayed in the Region select box. But after the patch the region will displayed as default.
Comment #15
_shYRinku Jacob 13, thank you for testing.
Do you mean, that after applying the patch, a region that was selected before will be displayed in the settings form?
Comment #17
Rinku Jacob 13 CreditAttribution: Rinku Jacob 13 at Srijan | A Material+ Company for Drupal India Association commented@ Kostia Bohach I have meant like that . But mistakely i wrote that. After applying the patch, a region that was selected before will be displayed in the settings form. In screenshots we can see the difference.Sorry for the mistake.
Comment #18
smustgrave CreditAttribution: smustgrave at Mobomo commentedThis seems like a perfect use case for a test.
Comment #19
Munavijayalakshmi CreditAttribution: Munavijayalakshmi at Valuebound commentedComment #20
Munavijayalakshmi CreditAttribution: Munavijayalakshmi at Valuebound commentedComment #21
mohit_aghera CreditAttribution: mohit_aghera at PreviousNext commentedComment #23
smustgrave CreditAttribution: smustgrave at Mobomo commentedWow quick turn around on those tests! Good job!
Tested patch #21
Going to block layout
Place block
Create new custom block
Saving that block
Verified the region I originally clicked to place the block was remembered.
Comment #24
alexpottThis seems like a nice improvement to usability.
This can be written as:
$add_action_url = $build['local_actions']['block_content_add_action']['#link']['url'] ?? NULL;
I think we shouldn't do the
&& region
here. I think adding the param if it is NULL should be okay - it'll just be ignored and then we don't have to think about regions called'0'
.I think this could be:
For the same reason as above.
Comment #25
Ratan Priya CreditAttribution: Ratan Priya at OpenSense Labs commented@alexpott,
Made changes as per comment #24 for points 1,2,3.
Needs review.
Comment #26
Ratan Priya CreditAttribution: Ratan Priya at OpenSense Labs commentedFixed custom commands failing issue.
Comment #27
smustgrave CreditAttribution: smustgrave at Mobomo commentedTested #26
Went to block layout
Clicked Add block into header region
Create custom block
Next page the header region was auto selected
Tested again with a region in the middle
Same correct behavior.
Comment #28
alexpottWe've lost the test coverage that was present in #21 and the missing test coverage noted by #24.4 still does not exist.
Comment #29
smustgrave CreditAttribution: smustgrave at Mobomo commentedGood catch. @Ratan Priya was there a reason for removing the tests?
Going back to #19 and starting from there to be safe.
Comment #30
smustgrave CreditAttribution: smustgrave at Mobomo commentedFyi this needs more work for the solution. If you go to /admin/structure/block/library/stark?region=content the region parameter isn't set.
Comment #31
smustgrave CreditAttribution: smustgrave at Mobomo commentedUpdated solution to cover additional scenario
Updated tests also.
Comment #33
mohit_aghera CreditAttribution: mohit_aghera at PreviousNext commentedLooks like test case failures are random. Test results seems to be green.
Comment #34
Manibharathi E R CreditAttribution: Manibharathi E R at Srijan | A Material+ Company for Srijan | A Material+ Company commentedPatch #31 Applied successfully in Drupal 9.4.x and Drupal 9.5.x.
Steps:
1. Go to Structure->Block Layout
2. Click Place block any regions
3. Than Click Add custom block
4. Check the regions are not auto selected.
5. Apply the Patch
6. Regions are auto selected in the block configuration.
Comment #35
gaurav-mathur CreditAttribution: gaurav-mathur at Dotsquares Ltd. commentedApplied patch #31 successfully in Drupal 9.5.x. and working fine.Adding screenshots to refer after and before patch.
Comment #36
ameymudras CreditAttribution: ameymudras at Salsa Digital commentedTested on Drupal 9.5
- Issue summary is clear and steps to reproduce have been provided
- The patch applies cleanly
- Was able to reproduce the issue following the steps in #34 and the patch fixes the issue
- A couple of suggestions with respect to the code
The comment wordings could have been better
Can we make use of dependency injection here
Comment #37
_pratik_ CreditAttribution: _pratik_ as a volunteer and at Specbee for Drupal India Association commentedComment #38
_pratik_ CreditAttribution: _pratik_ as a volunteer and at Specbee for Drupal India Association commentedComment #39
_pratik_ CreditAttribution: _pratik_ as a volunteer and at Specbee for Drupal India Association commentedFixed above CCF.
Comment #42
smustgrave CreditAttribution: smustgrave at Mobomo commentedStarted back at #31
Updated the comment slightly
Added the current route to the LocalActionDefault
Comment #43
smustgrave CreditAttribution: smustgrave at Mobomo commentedComment #44
smustgrave CreditAttribution: smustgrave at Mobomo commentedMore convinced we will need a trigger_error :(
Comment #46
mohit_aghera CreditAttribution: mohit_aghera at PreviousNext commentedI think a few permissions were missing in the test case.
Failing test case is passing on local now.
Comment #47
mohit_aghera CreditAttribution: mohit_aghera at PreviousNext commentedOops, probably something like this also be a good change.
Updated the patch.
Cancelled the previous test case run and hiding the patch.
Comment #48
mohit_aghera CreditAttribution: mohit_aghera at PreviousNext commentedLooks like my local 10.1.x head was not updated.
Re-rolled the patch.
Comment #50
mohit_aghera CreditAttribution: mohit_aghera at PreviousNext commentedFixing the label change happened in latest head.
Hiding failed patches.
Comment #52
mohit_aghera CreditAttribution: mohit_aghera at PreviousNext commentedComment #53
smustgrave CreditAttribution: smustgrave at Mobomo commentedTested patch #50 following steps in issue summary and it resolves the issue.
Still think we will need a trigger_error but maybe the committer will surprise me.
Comment #54
quietone CreditAttribution: quietone at PreviousNext commentedDoing RTBC triage.
The first thing I notice is that the issue summary is incomplete and the steps to reproduce are out of date. And since this is making a change to the user interface there should be before and after screenshots. However, maybe manual testing here is fine.
I read the comments. I agree with #24 that this is a nice usability improvement. The changes asked for in #24 appear to have been done. In #42 there should be an explanation for why the current route is added to LocalActionDefault and that should be in the proposed resolution as well. And a reminder that anyone who works on a patch should ask for reviews and someone else to set the issue to RTBC.
I then looked at the patch.
Needs to be wrapped to 80 columns.
This isn't a complete sentence.
This can be simpler. "Tests the region value when a new block is saved."
See policy for adding constructor arguments. Although my later testing questions whether these changes are needed.
Since this is testing placement and not the value can we skip generating a random value and just use, say, 'foo'.
I then tested on a fresh install of Drupal 10.1x, standard install. First, I confirmed the problem using the steps in the IS. The I applied the patch and confirmed the fix. I then removed the changes to the menu system (core/modules/menu_ui/src/Plugin/Menu/LocalAction/MenuLinkAdd.php and core/modules/menu_ui/src/Plugin/Menu/LocalAction/MenuLinkAdd.php), cleared cached and retested. The fix was still working but the new test was failing. That needs to be looked into. I didn't look further myself.
So, back to NW for comment changes and then a question about the changes to the menu system.
Comment #55
nitin_lamaComment #56
nitin_lamaAddressed #54 changes but not sure of the cause of the failed tests. For pointer 4, we can remove the unused class object but are unsure of its original purpose. Updated patch. Please review.
Comment #57
smustgrave CreditAttribution: smustgrave at Mobomo commentedIssue summary needs to be updated
and #54.4 hasn't been done.
Comment #59
smustgrave CreditAttribution: smustgrave at Mobomo commentedHiding patches and converted to MR.
Comment #61
smustgrave CreditAttribution: smustgrave at Mobomo commented@quietone the request is used to get the query parameter which can't get from route_match. To get around that we would probably have to update the url to include region also. That seemed like the least desirable approach
Comment #62
quietone CreditAttribution: quietone at PreviousNext commented@smustgrave, thanks. I don't know enough about this so I will leave this for others to RTBC.
The conversion to MR lost a change, I have commented in the MR.
Comment #63
smustgrave CreditAttribution: smustgrave at Mobomo commentedComment #64
Nitin shrivastava CreditAttribution: Nitin shrivastava at OpenSense Labs commented@smustgrave
The issue has been resolved following the patch in MR #5562. When creating a custom block within the region, it displays correctly in the drop-down menu, automatically selecting the respective region
Thanks !
Before Implementation
After Implementation
Comment #65
cilefen CreditAttribution: cilefen commentedNitpick: Is it normal for `url` to be lower-case in comments? It’s an acronym.
Neither my comment nor the screenshot review above should be credited.
Comment #66
needs-review-queue-bot CreditAttribution: needs-review-queue-bot as a volunteer commentedThe Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".
This does not mean that the patch needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #67
larowlanLeft a review
Comment #68
mohit_aghera CreditAttribution: mohit_aghera at PreviousNext commented@larowlan Addressed all 3 issues.
Tests are green now.
Comment #69
smustgrave CreditAttribution: smustgrave at Mobomo commentedResolved all the threads fixed by @mohit_aghera.
Rebased the MR as there was a merge conflict.
Retested by going through block layout > place block into content region > custom block > verified region is saved.
Comment #70
larowlanUpdating issue credits
Comment #71
larowlanLeft some comments on the MR to simplify this
Comment #72
smustgrave CreditAttribution: smustgrave at Mobomo commentedAddressed feedback.
Comment #73
needs-review-queue-bot CreditAttribution: needs-review-queue-bot as a volunteer commentedThe Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #74
smustgrave CreditAttribution: smustgrave at Mobomo commentedFixed
Comment #75
needs-review-queue-bot CreditAttribution: needs-review-queue-bot as a volunteer commentedThe Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #76
smustgrave CreditAttribution: smustgrave at Mobomo commentedRebased
Comment #78
acbramley CreditAttribution: acbramley at PreviousNext commentedTest only failed as expected. Looks good to go!
Comment #79
smustgrave CreditAttribution: smustgrave at Mobomo commentedThanks @acbramley!
Comment #80
alexpottCommitted and pushed 1f94e17f9f to 11.x and a0138ae5ef to 10.3.x. Thanks!