CVS edit link for trobey

I wrote a custom module for Drupal 6 that creates a user interface for defining dependencies between attributes used in Ubercart. This allows some attributes to be displayed only when another attribute takes on a particular value(s). It also allows such dependent attributes to be required (when displayed).

Often an attribute will only be needed (and perhaps required) when another attribute takes on a particular value. For instance, perhaps an attribute may be Drupal user with a select box with the values Yes or No. If the user selects Yes, then another attribute, Drupal username, should be displayed and required.

This module defines another tab similar to the Attributes tab that lists in a table the attribute, a select box to choose another attribute on which it depends, the values of the parent attribute (using AHAH) which trigger the dependent attribute to be displayed and whether the attribute should be required when displayed. Often it is desirable to require the attribute but, since it is not displayed under some circumstances, it cannot be required in the same way as for most attributes. The dependencies are stored in a table and jQuery (Javascript) code is used to retrieve the data and display or not display the attributes.

Drupal 7 allows defining dependencies between form elements programatically so it has been recognized that this is an important capability. But Drupal 7 does not provide a user interface to specify the dependencies so a non-programmer can implement them. Drupal Commerce is not using attributes so the module would need to be quite different but may still prove useful for Drupal 7.

This module is currently being used on a Drupal website. It is written in such a way that it could be used on other websites.

Comments

trobey’s picture

Status: Postponed (maintainer needs more info) » Needs review
StatusFileSize
new4.25 KB
avpaderno’s picture

Issue tags: +Module review

Hello, and thanks for applying for a CVS account. I am adding the review tags, and some volunteers will review the code, pointing out what it needs to be changed.

wicketywick’s picture

Seems like an interesting module.

Just tried it on a test site of mine, doesn't seem to work. (the backend seems alright, but nothing happens on the frontend).
Can you post a screen of a configured node/20/edit/dependencies page? Maybe I configured something incorrectly.

I am no developer, just a simple drupal user.

Thanks.

trobey’s picture

There is a screen shot in the post immediately preceding yours. Have you cleared the cache?

trobey’s picture

StatusFileSize
new4.31 KB

This is an updated module that should fix the problem. There was one thing that was specific to the website that the module was developed for that needed to be made more general.

trobey’s picture

There is a demo website for this module.

http://li57-250.members.linode.com/node/1

The student ID attribute only appears if the Continuing Education Credit attribute has the Yes option selected.

avpaderno’s picture

Assigned: Unassigned » avpaderno
Status: Needs review » Needs work
  • The points reported in this review are not in order or importance / relevance.
  • Most of the times I report the code that present an issue. In such cases, the same error can be present in other parts of the code; the fact I don't report the same issue more than once doesn't mean the same issue is not present in different places.
  • Not all the reported points are application blockers; some of the points I report are simple suggestions to who applies for a CVS account. For a list of what is considered a blocker for the application approval, see CVS applications review, what to expect. Keep in mind the list is still under construction, and can be changed to adapt it to what has been found out during code review, or to make the list clearer to who applies for a CVS account.
  1. Menu descriptions and titles, schema descriptions are not passed to t().
  2. Hook implementation comments should be like the following one
    /**
     * Implements hook_menu().
     */
    
  3. function uc_dropdown_attributes_form_alter(&$form, &$form_state, $form_id) {
      if (preg_match('/^uc_product_add_to_cart_form.*/', $form_id)) {
        $nrows=db_result(db_query('SELECT COUNT(*) FROM {uc_dropdown_attributes} WHERE nid="' . $form['nid']['#value'] . '"'));
    
    

    Code that doesn't use db_query()-placeholders is considered not secure.

  4. Code should use Drupal Unicode functions, when the string can be an Unicode string.
  5. See http://drupal.org/coding-standards to understand how a module should be written. In particular, see how the code should be formatted.
  6.         if (strlen($form_state['values']['attributes'][$item->aid])==0) {
              $attribute = uc_attribute_load($item->aid);
              form_set_error('edit-attributes-' . 
                             $item->aid . '-wrapper', $attribute->name . ' field is required');
            }
    
    

    Strings used in the user interface should be translated.

  7.   $form['intro'] = array(
        '#type' => 'markup',
        '#value' => '<p>Since dropdown attributes may not appear, they cannot be always required.  The required checkbox applies only when the dropdown attribute appears.  Any dropdown attribute is also checked under the attributes table to make sure it is not required there as this would cause validation errors.</p><p>If Javascript is not enabled, a Choose button appears at the bottom of the page to allow this page to be reloaded with the updated values.</p>',
      );
    
    

    It should be drop down

avpaderno’s picture

Issue tags: +Ubercart

I am adding the tag we are using for Ubercart related modules.

avpaderno’s picture

Status: Needs work » Closed (won't fix)
trobey’s picture

Component: Miscellaneous » miscellaneous
Status: Closed (won't fix) » Active
StatusFileSize
new4.33 KB

I guess I gave up too early on getting a response to this request.

I have updated the code to address the comments. Note that item 4 is not correct. See https://drupal.org/node/473460:

"Note that if you are using strlen() just to check whether the length of a string is non-zero, it is not necessary to use the Drupal replacement."

strnlen() presumably executes quicker and so is to be preferred in this case.

The original code had been run through the coder module at the default setting. I ran it through at the most strict setting. I also have gone through the coding standards (again) and tried to catch as many problems as I could.

I also have gone through the code once again and found one function that needed to be renamed.

trobey’s picture

Status: Active » Needs review
jthorson’s picture

Trobey,

As Drupal has since moved over from CVS to Git, I'd suggest migrating this to a Git Full Project Access application as per http://drupal.org/node/1075406.

jthorson’s picture

Status: Needs review » Postponed
trobey’s picture

Project: Drupal.org CVS applications » Drupal.org security advisory coverage applications
Component: miscellaneous » module
Assigned: avpaderno » Unassigned
Status: Postponed » Needs review

@jthorson thanks for the information. It was very helpful. I have migrated this project to the Git sandbox at http://drupal.org/sandbox/trobey/1162770. I also have added a new demonstration website at http://dropdown.gaiaes.com/node/3

sreynen’s picture

Title: trobey [trobey] » uc_dropdown_attributes
Issue tags: +PAReview: Ubercart

Updating title and tagging.

rfay’s picture

Status: Needs review » Needs work

You can remove the $Id$ as we don't use those since the git migration.

Probably want to remove the '

' from within the t() in your long text; normally you only want the translatable stuff to be in there, not markup.

A @file header on each file would be nice. A function header for every function would also be nice.

Have you tested if this works with js off? Is that a goal?

It looks to me like this should go through OK.

trobey’s picture

Status: Needs work » Needs review

I removed the $Id, html tags from t(), and added code documentation.

Showing or hiding the attributes uses Javascript so if Javascript is turned off then this functionality is lost. But it is designed to degrade gracefully by just showing all the attributes. For the administrative interface, there is a Change button that appears if Javascript is turned off which still allows the attribute dependencies to be specified. The Change button may not be obvious so some usability is lost but it should still work.

rfay’s picture

Status: Needs review » Reviewed & tested by the community

Works for me. Unless there are objections someone will come by and promote you to have full project permissions within the next several days. Thanks for your contribution and your future contributions! And thanks for your patience. Sorry this was so awful.

sreynen’s picture

Status: Reviewed & tested by the community » Fixed

Hi trobey,

Thanks for your contribution and welcome to the community of project contributors on drupal.org.

I've granted you the git vetted user role which will let you promote this to a full project and also create new projects as either sandbox or "full" projects depending on which you feel is best.

Thanks, also, for your patience with the review process. Anyone is welcome to participate in the review process. Please consider reviewing other projects that are pending review. As someone who has recently completed this process, your input would be especially useful in the code review group as we work to improve this process.

Status: Fixed » Closed (fixed)
Issue tags: -Ubercart, -Module review, -PAReview: Ubercart

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

avpaderno’s picture

Issue summary: View changes
Issue tags: -Ubercart, -Module review, -