- ๐ฏ๐ตJapan ptmkenny
I re-rolled patch #46 and opened an MR to allow this to apply to the latest version.
- ๐ฎ๐ณIndia gaurav.kapoor
#53 would require some changes as it isn't removing these 2 lines and the radio buttons disappear as their type gets changed to 'value'.
- $form['user_role']['negate']['#type'] = 'value'; - $form['user_role']['negate']['#value'] = $form['user_role']['negate']['#default_value'];
Also, the saved value of user role negation isn't reflected in the UI after saving the block. Should we make this change as well:
- $form['user_role']['negate']['#default_value'] = (int) $form['request_path']['negate']['#default_value']; + $form['user_role']['negate']['#default_value'] = (int) $form['user_role']['negate']['#default_value'];
Thoughts?
- ๐ซ๐ทFrance liliplanet Cannes
How I wish this negate role functionality could be committed, it is awesome! Been having to hack the block module since D8 ๐
- ๐ธ๐ชSweden edward.peters
Me too, this would be such a great development to have this in core.
- ๐ซ๐ทFrance liliplanet Cannes
Thank you! But the patch in #53 does not save when you select 'hide for the selected roles'.
- ๐ซ๐ทFrance liliplanet Cannes
Oh dear, I have tried patch #43, #46, #54, still 'hide for selected roles' is not saving.
Any progress most appreciated.
- ๐ซ๐ทFrance liliplanet Cannes
Thank you #@mohit! #46 is definitely the one.
- ๐ฎ๐ณIndia shabana.navas
Updating patch in #46 to fix default value problem mentioned in #54.
- ๐ฏ๐ตJapan ptmkenny
@gaurav.kapoor I renamed request_path to user_role; that was a mistake on my part. Thank you for pointing it out.
As for the first two lines, in Drupal 11 it seems those lines are already gone.
- ๐ฌ๐งUnited Kingdom iancawthorne
Is there a patch for 10.2.x which works on this thread?
I've tried #53, which will apply, but as mentioned in #58, saving the block does not update the negate value. The patches at #43, #46 and #60 will not apply to 10.2.6.
- ๐ฑ๐ฐSri Lanka SajithAthukorala
Patch for Issue #2986958: Invert visibility of chosen roles for blocks
Here is the patch to invert the visibility of chosen roles for blocks as per Issue #2986958.
This patch introduces a custom block permissions handler that allows inverting the visibility settings for blocks based on roles.
@iancawthorne #62
Please review and test the changes.
This patch tested with Drupal 10.2.xhttps://www.drupal.org/files/issues/2024-06-03/2986958-invert-block-visibility-by-role.patch โ
- ๐ฌ๐งUnited Kingdom iancawthorne
The patch at #63 works great on 10.2.x.
- Merge request !8269Issue #2986958: Invert visibility of chosen roles for blocks โ (Open) created by SajithAthukorala
- ๐ฏ๐ตJapan ptmkenny
Warning: Patch #63 is a different modification than the MR
2986958-add-support-for
and the rest of the patches in this thread. Patch #63 inverts the visibility of the roles in all cases, whereas the rest of the patches and the MR2986958-add-support-for
add a setting that allows the roles to be negated. Patch #63 is not a solution to this issue and it doesn't have any tests. - ๐ฌ๐งUnited Kingdom iancawthorne
@ptmkenny Can you clarify on the [quote]inverts the visibility of the roles in all cases[/quote] part?
From my testing, I update a blocks visibility and did a config export. Only the user role visibility changed in that config export, as expected. No config changed for negating visibility was negated for any of the other conditions, such as by content type, by page or by vocabulary etc.
Are you talking about a different scenario which I'm missing?
- ๐ฏ๐ตJapan ptmkenny
@iancawthorne I meant all cases for user roles, not for the other conditions. Anyway, you can clearly see this by reading the code for the patch; patch #63 is a one-liner whereas the other patches in this thread are many more lines.
- ๐ฎ๐ณIndia prashant.c Dharamshala
Prashant.c โ made their first commit to this issueโs fork.
- ๐ฎ๐ณIndia prashant.c Dharamshala
I noticed a few things, and I would like to request your inputs on the following considerations:
- By default none of the radio boxes should be selected, currently by default
"Show for the selected roles"
is selected and it gives the impression that we have to select some role before proceeding - There should be some description under roles checkboxes like
"If nothing is selected the block will be visible to all the listed roles"
- The "Roles" label should be just above the roles checkboxes and not above the radioboxes.
Please see the attached screenshot.
- By default none of the radio boxes should be selected, currently by default
- ๐ฌ๐งUnited Kingdom iancawthorne
@ptmkenny I can see the patch at #63 is a lot less lines of code than others. However, up until needing to upgrade from Drupal 10.1.x to 10.2.x, I've been using the patch at #21. If you take out the test lines for that patch, you are left with a two liner, which as far as I can tell does the same as patch #63 but in a very slightly different way.
I'm still not sure what you mean by
all cases for user roles
though? - ๐ฏ๐ตJapan ptmkenny
@Prashant.c First, please note that this change has already undergone a usability review โจ Add support for negating user role condition for block visibility Needs work .
As for your points:
By default none of the radio boxes should be selected, currently by default "Show for the selected roles"is selected and it gives the impression that we have to select some role before proceeding
In Drupal, radios generally have something selected by default. For example, in "Submission form settings", "Preview before submitting" also has a default value selected. If no default value was selected, when creating a new entity, users would always have to fill out that part of the form. Anyway, this is the way other
There should be some description under roles checkboxes like "If nothing is selected the block will be visible to all the listed roles"
The "Roles" label should be just above the roles checkboxes and not above the radioboxes.This could be a helpful suggestion but I think it is out of scope for this issue, as the change has already undergone usability review. Please consider opening a new issue with this request.
- ๐ฏ๐ตJapan ptmkenny
For anyone coming to this issue and "just looking for a patch," please consider using the User Not Role module โ instead, which does what this issue will eventually accomplish in core.
- ๐ฎ๐ณIndia prashant.c Dharamshala
@ptmkenny
Thanks for your responses; I understand your points. Apologies for missing #41 โจ Add support for negating user role condition for block visibility Needs work