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?

Comments

brianV’s picture

Version: 6.x-3.0-beta2 » 6.x-3.x-dev

I 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.

rhymeswithcamera’s picture

Thank 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:

  • Disable "Add a block" - and subsequently, "Restore defaults"
  • Disable "closable" on all blocks - so that users can't "delete" a block they can't get back
  • Collapse less-important blocks in the default display to reduce the page clutter

With the Autosave feature, users will be able to move things around and expand/collapse blocks to their liking pretty easily.

lucky_lowell’s picture

Rhymes
How did you do this?
Lowell

rhymeswithcamera’s picture

lucky_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?

lucky_lowell’s picture

Who's better than you!

pribeh’s picture

subscribing.

rocnhorse’s picture

Status: Active » Needs review
StatusFileSize
new5.18 KB

The 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,
),
...

stevenmhouse’s picture

Here'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.

attiks’s picture

StatusFileSize
new7.14 KB

Patch from #7 updated for latest dev version, the hiding/showing is now done using to count/max count.

michielkenis’s picture

Version: 6.x-3.x-dev » 7.x-2.0-beta6

How about version 7 of Homeboxes. How can I prevent users of Homeboxes 7.x-2.0-beta6 to add duplicate homeboxes?

broncomania’s picture

#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.

osopolar’s picture

StatusFileSize
new10.02 KB

On 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 condition if (!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.

camprandall’s picture

Status: Needs review » Reviewed & tested by the community

We're now using this (homebox-hide-addlinks-1066304-12.patch) and are having no problems with it. Nice work!

bturoque’s picture

I am using version 6.x-3.0-beta5 and desire this functionality. Will the patch in #7 or #12 work for this version?

osopolar’s picture

@bturoque: You will find out when you try the patch. Pleas leave a commend if it works or don't work.

cgmonroe’s picture

Status: Reviewed & tested by the community » Needs work

The 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:

 while (isset($user_blocks[$block_key])) {
    if (empty($user_blocks[$block_key]['open'])) {
      // A closed user block gots opened again. Add it with same color and to
      // the same region where it was before but on the bottom, because weight
      // likely changed within all blocks so we can't be sure where it
      // was before.

Correct code using 'status' instead of 'open' on the if(empty... line:

while (isset($user_blocks[$block_key])) {
    if (empty($user_blocks[$block_key]['status'])) {
      // A closed user block gots opened again. Add it with same color and to
      // the same region where it was before but on the bottom, because weight
      // likely changed within all blocks so we can't be sure where it
      // was before.
bturoque’s picture

@osopolar Patches in #7 and #12 are for the 7.x version.

Anonymous’s picture

Issue summary: View changes

Another very easy fix is to change the homebox css file here:

#homebox-add a.used{
display:none;
}

mayank_kanungo’s picture

Thanks Osopolar,

Commend #12 patch is work like charm for me. :)

unqunq’s picture

The 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.

scuba_fly’s picture

#12 does not apply to the current version.

scuba_fly’s picture

Version: 7.x-2.0-beta6 » 7.x-2.0-rc3
Status: Needs work » Needs review
StatusFileSize
new14.04 KB
new22.03 KB

I created a new patch for the current version.
See included patch and interdiff.

scuba_fly’s picture

Assigned: Unassigned » scuba_fly
Status: Needs review » Needs work
scuba_fly’s picture

StatusFileSize
new11.71 KB
new20.16 KB

New patch, without drush packaging information. Ignore #22
This is a reworked version of #12

scuba_fly’s picture

Assigned: scuba_fly » Unassigned
Status: Needs work » Needs review
osopolar’s picture

Status: Needs review » Needs work

From #2135291: [Policy, no patch] PHP 5.4 short array syntax coding standards for Drupal 8:

Please note, short array syntax is unsupported in versions of PHP prior to 5.4. This means that Drupal 7 core and Drupal 7 contributed projects without an explicit PHP 5.4+ requirement must use long array syntax.

+++ b/homebox.module
@@ -33,8 +33,8 @@ function homebox_menu() {
     foreach ($pages as $page) {
       $items[$page->settings['path']] = array(
-        'title' => $page->settings['title'],
         'title callback' => 'homebox_build_title',
+        'title arguments' => [$page->settings['title']],
         'page callback' => 'homebox_build',
         'page arguments' => array($page),
         'access callback' => '_homebox_user_access_view_homebox',
@@ -58,7 +58,7 @@ function homebox_menu() {

@@ -58,7 +58,7 @@ function homebox_menu() {
     if ($page) {
       $items['user/%user/' . $page->settings['path']] = array(
         'title callback' => 'homebox_build_title',
-        'title arguments' => array($page->settings['title']),
+        'title arguments' => [$page->settings['title']],
         'page callback' => 'homebox_build',
+++ b/homebox.admin.inc
@@ -64,7 +64,7 @@ function homebox_admin_page($form, &$form_state, $page = FALSE) {
+    '#description' => t('Can be positioned in <a href="!url">Menus admin</a>.', ['!url' => url('admin/structure/menu')]),
scuba_fly’s picture

Thanks for the review, I guess a new patch is needed then.

scuba_fly’s picture

Assigned: Unassigned » scuba_fly
scuba_fly’s picture

Assigned: scuba_fly » Unassigned
Status: Needs work » Needs review
StatusFileSize
new10.73 KB
new1.42 KB

Here's the new patch.

scuba_fly’s picture

Assigned: Unassigned » scuba_fly
Status: Needs review » Needs work
scuba_fly’s picture

Assigned: scuba_fly » Unassigned
Status: Needs work » Needs review

Looked at it again. This should be the right patch.
The interdiff should only be named 24-29.

anybody’s picture

Status: Needs review » Closed (outdated)

We'll implement something like that in 3.0.x. Closing this for Drupal 7.