Comments

mattyoung’s picture

Do you have any information on how to do this?

jtjones23’s picture

This page should get you started - http://drupal.org/node/101742. Wish I could be more helpful but not a coder, yet.

mattyoung’s picture

I don't see anyway to add this multi-column feature to the built-in CCK checkboxes and radios widgets. If anyone know of a way to do it, please let me know.

vkareh’s picture

Version: 6.x-1.1 » 6.x-1.2
Status: Active » Needs review
StatusFileSize
new3.83 KB

Thanks for creating this module!
Here's a patch to provide integration with CCK optionwidgets. Please test it and let me know if it works for you.

jtjones23’s picture

Thanks for the patch. Patch applies successfully and I'm able to display a list as columns. I also get the following error message.

warning: Division by zero in /Applications/MAMP/htdocs/drupal6/sites/all/modules/multicolumncheckboxesradios/multicolumncheckboxesradios.module on line 92.

Running Drupal 6.13, PHP 5.2.5

mattyoung’s picture

vkareh: thanks for the patch. I tested it and it works very well. I've checked it in HEAD.

I made a few changes:

1. I took out '#access' => user_access('administer multicolumncheckboxesradios'),
I think this is not need as only role with CCK admin can access the admin/content form.

2. I changed

if (arg(0) == 'admin' ....

to

if (arg(0) == 'admin' && arg(1) == 'content'

because I want multicolumn to work in admin/settings forms

3. I had to change the beginning of element_process() a little to make it work with normal form element as well as CCK widget. I need this to work for both use cases.

**I wonder if the CCK multicolumn settings can be move from 'CONTENT-TYPE settings' section to 'Global settings" section? It seem to me it make more sense to be there. The same settings should apply to every instance of that widget.

If you can make this change, please apply to HEAD of multicolumncheckboxesradios.module. The version is 1.6.

*
*

jt_jones:

Can you download the dev version and try it? I've just made this dev release so it should show up any minute now on the project page (I hope).

EDIT: the dev tarball can be fetch here: http://ftp.drupal.org/files/projects/multicolumncheckboxesradios-6.x-1.x...

vkareh’s picture

That's awesome, thanks! I will test it all today.

When you say Global Settings, you mean for each individual content type, or for all content types in the site? I still think that the settings should be for each individual instance of the widget, since in some cases you would only have a few options, and in others you might have a lot arranged in a different way. Maybe a good compromise could be a global setting for the whole form, with individual settings to override the global in specific instances? Although I see what you mean: if I have a themed form that can only display up to, say, 6 columns properly, I don't want another [admin] user to make a widget with 9 columns, as it could break the theming.

I put the #access permission there, but really didn't do anything with it (I didn't even implemented hook_perm()), so thanks for removing that.

mattyoung’s picture

>When you say Global Settings, you mean for each individual content type, or for all content types in the site?

I mean for all content types for a particular field.

For example, if I define a field called "Meal choices" of type "Text", widget type "Checkboxes/Radios", its multicolumn settings should be the same for all content types that use the "Meal choices" field.

Go to configure the "Meal choices" field, right now, the multicolumn settings is under "CONTENT-TYPE settings" ("These settings apply only to the Meal Choices field as it appears in the Picnic Content content type.") So multicolumn settings is set for each content type. The multicolumn settings should be in "Global settings" ("These settings apply to the Meal Choices field in every content type in which it appears."), in the same place where the "Required" checkbox is.

vkareh’s picture

Oh! I see what you mean now, thanks!

To do that, I think we need to override content_field_edit_form(), but I don't think there is a hook for that. I'll try a few things and see if it's possible.

On a separate note, the Division by zero error could be solved if you do

 if (denominator == 0) {
  denominator = "some default value that works for you";
} 

right before each division. That's a separate issue, though.

jtjones23’s picture

Installed the July 7 dev on a site I'm building. Module installs and the columns work. But when I tried to create content I got the following error.

Fatal error: Call to undefined function dpm() in /usr/www/users/xxxxx/xxxxx/sites/all/modules/multicolumncheckboxesradios/multicolumncheckboxesradios.module on line 106

Running Drupal 6.13, PHP 5.2.9

vkareh’s picture

Okay, so apparently the way to have custom global settings is by defining a new field through hook_field_info(), hook_field_settings(), and hook_field(). This makes sense, since the global stuff is mostly database-centric (required, multiple, max, min, values) and you need to keep it the same for every instance of the field. The node-type settings, on the other hand, deal mostly with how things are displayed, hence the use of hook_widget_info(), hook_widget_settings(), and hook_widget().

My suggestion is to leave it as a node-type setting, since it's quite painful to modify a field (as opposed to just the widget). Also, there's no easy way of knowing what field type you are dealing with, since widgets (radios, checkboxes) should be able to be applied to any field (number, text, decimal).

vkareh’s picture

StatusFileSize
new615 bytes

dpm() is a function from the Devel module (http://drupal.org/project/devel). I would assume that mattyoung put it there for backtracing while still programming the module.

Download this patch to remove it.

mattyoung’s picture

The dpm() function is from the devel module. Can you install the devel module: http://drupal.org/project/devel, this is very indispensable for development. Since you are hitting the check, which should never happen. I need to see why it's doing that.

Install and enable 'devel' and try again. If you see the message box with two yellow boxes inside, you have hit a error that should never happen. Something is wrong with my code. Save the page source and attach it to a message here.

vkareh’s picture

Good call, mattyoung.

More than the $element['#multicolumn']['width'] being zero, I think it might have to do with the checks that decide whether to continue running multicolumncheckboxesradios_element_process() or return instead. It might be that not all cases for returning are being accounted for?

edit: You could probably be safe to just do a return if $element['#multicolumn']['width'] is zero... although I agree that it shouldn't happen, unless you specifically program it as such.

mattyoung’s picture

jt_jones: Can you download and try the attached version? It will not give you error if you don't have the 'devel' module. But I prefer you install 'devel' to help me track down the bug. I'm not seeing this error on my end so something is different and I'm not testing it here.

vkareh: can you checkout from HEAD now to get the latest? multicolumncheckboxesradios.module version is 1.7

vkareh’s picture

Nicely done. I just updated from the repositories and will proceed to test a few scenarios. I suspect that the zero might be due to the integration with CCK... something might not be coming up properly in $form_state['#field_info'][$element['#parents'][0]]['widget']['width'] in multicolumncheckboxesradios_element_process().

mattyoung’s picture

vk:

>My suggestion is to leave it as a node-type setting, since it's quite painful to modify a field (as opposed to just the widget).

Alright then. The way it is now works great anyway.

I was afraid it would be hard to figure out what the widget type if it's in the Global settings.

>You could probably be safe to just do a return if $element['#multicolumn']['width'] is zero

For now I just do $element['#multicolumn']['width'] <= 1. Although I hate to be sloppy like this because there should never be a zero there. So I hope jt will report back to me why he is getting zero.

vkareh’s picture

Aha! I think I found it!

The multicolumncheckboxesradios_element_process() function is trying to assign the #multicolumn array to fields that are not going to be rendered in that particular page.

For example, in the field-edit form (admin/content/node-type/<node-type>/fields/<field-type>), the multicolumncheckboxesradios_element_process() function is trying to process the actual field for which you are changing the settings, but since the field is not going to be rendered there, it should just return.

The instances where $element['#multicolumn']['width'] == 0 is for either fields that shouldn't be rendered in that page, or that do not have the #multicolumn array set. Checking for $element['#multicolumn']['width'] == 0 is also true when $element['#multicolumn'] == FALSE, so that explains why it's being called.

I think it's safe to return when $element['#multicolumn']['width'] == 0.

jtjones23’s picture

StatusFileSize
new31.51 KB

Tried the latest dev with Devel turned on...getting the attached message at pages that have nothing to do with CCK - like admin pages.

mattyoung’s picture

jt: can you try the attached dev version.

jtjones23’s picture

Looking good. CCK multi-column feature is working with no error messages on local and hosted test site.

vkareh’s picture

Status: Needs review » Fixed

Awesome work mattyoung!

It's working perfectly for me now as well. Thanks for changing the saved variable names too.

mattyoung’s picture

Status: Fixed » Postponed
StatusFileSize
new443.4 KB

Hello all,

I'm postponing this to wait for #417122: Allow drupal_alter() on Field and Widget Settings. D7 already has this patch and it should be released soon for D6 so I'll wait for its release before I release multicolumncheckboxesradios with CCK support.

vk:

I already change multicolumncheckboxesradios code to work against this CCK patch and checked into HEAD (multicolumncheckboxesradios.module v1.9). It works exactly as before but the extension is done using hook_widget_settings_alter() instead of overriding optionwidgets. This leave optionwidgets untouched so anyone else can extend it like we do.

I'm attaching the patched cck so you can check out HEAD and give it a try. The code in HEAD should not show multicolumn settings for any widget except checkboxes/radios.

EDIT: I get the dev release to show on the project page now. That has the latest code which require the CCK patch.

mattyoung’s picture

Version: 6.x-1.2 » 6.x-1.3
Assigned: Unassigned » mattyoung
Status: Postponed » Fixed

This feature is released in version 1.3. Once CCK with #417122: Allow drupal_alter() on Field and Widget Settings is release, the feature will become functional. If you need this working now, you can check out CCK version DRUPAL-6--2 from cvs.

vinoth.3v’s picture

Great Drupal Team :)

Thanks all

Status: Fixed » Closed (fixed)

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