In the 6.x-2.1 version, a user could only add one occurrence of the same block/widget to a homebox. In the latest 3.x release, the user is able to add as many occurrences of the same block as they want. (You can see this behavior with your dashboard on drupal.org.) I'm not sure what the use case is for this feature.
For the site I'm developing, the 2.1 behavior is necessary for theming. The site ties colors to core functions - e.g. gold is used for community-related objects. We're using Homebox for the user's dashboard, offering up a variety of color-coordinated blocks. We "colored" the blocks with the Homebox block ID in the CSS.
In this newer version of Homebox, which allows for multiple occurrences of the same block, it looks like Homebox is dynamically generating the block IDs by appending "-#" to the base block ID. For example, the first occurrence of a block ID in Homebox may be #homebox-block-user_2. Now let's say I close that block, and then add it back in through "Add a block." The block is then redisplayed, but it now has a block ID of #homebox-block-user_2-1. The problem is that I have color-coded #homebox-block-user_2, not #homebox-block-user_2-1.
So the request is to give the administrator the option to (dis)allow multiple occurrences of the same block in a homebox. Alternatively, is there a better approach to theming/color-coding the blocks?
| Comment | File | Size | Author |
|---|---|---|---|
| #29 | interdiff-1066304-45-29.txt | 1.42 KB | scuba_fly |
| #29 | ability_to_add_only_one-1066304-29.patch | 10.73 KB | scuba_fly |
| #24 | ability_to_add_only_one-1066304-24.patch | 11.71 KB | scuba_fly |
| #12 | homebox-hide-addlinks-1066304-12.patch | 10.02 KB | osopolar |
| #9 | i1066304.patch | 7.14 KB | attiks |
Comments
Comment #1
brianV commentedI open to doing something like this as I don't see much use case for adding a single block multiple times. However, since this is used for the d.org dashboard, I want to be careful that we don't do something that might break it.
Come Monday, I'll check with drumm to see if / how this use case would break drupal.org.
Comment #2
rhymeswithcamera commentedThank you for the consideration. In the meantime, we've come up with a workaround so that users cannot add multiple instances of the same block:
With the Autosave feature, users will be able to move things around and expand/collapse blocks to their liking pretty easily.
Comment #3
lucky_lowell commentedRhymes
How did you do this?
Lowell
Comment #4
rhymeswithcamera commentedlucky_lowell, sorry for the delay.
To disable "Add a block", I just used CSS (for now): #homebox-buttons { display: none; }
Then click on the Layout link for the homebox you want to change. For each block, if you uncheck "Closable," this will remove the Close icon from the block. If you uncheck "Open," this will collapse the block in the default display. The user can then open and Autosave will automatically save the block in the opened state.
Does that help?
Comment #5
lucky_lowell commentedWho's better than you!
Comment #6
pribeh commentedsubscribing.
Comment #7
rocnhorse commentedThe attached patch allows you to set the maximum number of times each block can be added. If 0 or undefined you can add an unlimited number. (current behavior)
The use case I have for adding more then one block is the block can be filtered in the settings so you can have multiple blocks with different filters.
I'm not fully happy with the term "max to show". If you come up with a better term use it. I'm not going to worry about something the site users won't see.
I added the Max to Show field to the block settings in the homebox layout form.
You can also define the maxToShow in the hook_homebox()
$pages['userdashboard'] = array(
...
'blocks' => array(
'myDashboard_block' => array(
'module' => 'myDashboard',
'delta' => 'block',
'region' => 1,
'movable' => 1,
'status' => 1,
'open' => 1,
'closable' => 1,
'title' => '',
'weight' => -7,
'maxToShow' => 3,
),
...
Comment #8
stevenmhouse commentedHere's something to consider. I'm using a 6.3 version and the blocks that are currently used have the class 'used'. You can set your CSS for display:none. As a quick way to test you could open your console of Chrome/Firebug and try this jquery: $(".used").hide() and the 'used' blocks will disappear. I do like the direction of the patch above though, because, as @rocnhorse noted there are use cases (only filters from what I can think of now) that will want more than one block to be there.
Comment #9
attiks commentedPatch from #7 updated for latest dev version, the hiding/showing is now done using to count/max count.
Comment #10
michielkenis commentedHow about version 7 of Homeboxes. How can I prevent users of Homeboxes 7.x-2.0-beta6 to add duplicate homeboxes?
Comment #11
broncomania commented#9 works perfect!
I just add the standart occurence of 1 to the maxtoshow var. I think this is a good point to start for the most users.
Comment #12
osopolarOn my research I overlooked this issue. Now I have a similar fix. The difference is to not a amount "max to show" but a simple checkbox to allow multiple.
Another problem was, that if a widget does not have content, it is not marked as used and so the add link won't be hidden and may be add multiple times ... but won't show because blocks with no content won't show in homebox.
I moved
$allowed_blocks[$block->module][$block->delta]['used'] = TRUE;to another place outside of the conditionif (!is_null($block)).Last problem related to this issue I fixed: If a user clicked multiple times on the add block link, nothing prevented that the block will be add multiple times.
Comment #13
camprandall commentedWe're now using this (homebox-hide-addlinks-1066304-12.patch) and are having no problems with it. Nice work!
Comment #14
bturoque commentedI am using version 6.x-3.0-beta5 and desire this functionality. Will the patch in #7 or #12 work for this version?
Comment #15
osopolar@bturoque: You will find out when you try the patch. Pleas leave a commend if it works or don't work.
Comment #16
cgmonroe commentedThe patch in #12 prevents new blocks that have been added with the "visible" option unchecked from being added to a user's dashboard.
This is because the code uses the 'open' property and not the 'status' property.
Here's the code in the patch (function homebox_add_block() approx line 1312:
Correct code using 'status' instead of 'open' on the if(empty... line:
Comment #17
bturoque commented@osopolar Patches in #7 and #12 are for the 7.x version.
Comment #18
Anonymous (not verified) commentedAnother very easy fix is to change the homebox css file here:
#homebox-add a.used{
display:none;
}
Comment #19
mayank_kanungo commentedThanks Osopolar,
Commend #12 patch is work like charm for me. :)
Comment #20
unqunqThe patch allows for the removal of an already used block from the Add a block link however when I remove a block (by clicking on x) it does not come back up in the list of available blocks. User needs to reload the page in order to get access to that block.
Comment #21
scuba_fly#12 does not apply to the current version.
Comment #22
scuba_flyI created a new patch for the current version.
See included patch and interdiff.
Comment #23
scuba_flyComment #24
scuba_flyNew patch, without drush packaging information. Ignore #22
This is a reworked version of #12
Comment #25
scuba_flyComment #26
osopolarFrom #2135291: [Policy, no patch] PHP 5.4 short array syntax coding standards for Drupal 8:
Comment #27
scuba_flyThanks for the review, I guess a new patch is needed then.
Comment #28
scuba_flyComment #29
scuba_flyHere's the new patch.
Comment #30
scuba_flyComment #31
scuba_flyLooked at it again. This should be the right patch.
The interdiff should only be named 24-29.
Comment #32
anybodyWe'll implement something like that in 3.0.x. Closing this for Drupal 7.