I have a custom module which provides a form, where I am using a popup date selector. When the form is rendered, I get the following errors from required_by_role:

Notice: Undefined index: #field in required_by_role_date_popup_process_alter() (line 58 of /Users/myself/Projects/required_by_role/required_by_role.date.inc).

Notice: Undefined index: #instance in required_by_role_date_popup_process_alter() (line 57 of /Users/myself/Projects/required_by_role/required_by_role.date.inc).

Attaching a patch to wrap these in an if statement; if the date widget is not being used in a field form input, then required_by_role settings don't apply.

Comments

micromegas’s picture

micromegas’s picture

Status: Active » Needs review
lord_of_freaks’s picture

Hi @micromegas

Thanks for the feedback and the patch.

Could you add an example of the form you are building (at the the part with the date field) in order to be able to create a test for this behavior?

Regards

micromegas’s picture

This should be a good simplified example:

/**
 * Implements hook_form().
 */
function mymodule_date_select_form($form, &$form_state) {
  $form = array(
    '#date' => new DateTime(),
  );
  
  $form['date'] = array(
    '#type' => 'date_popup',
    '#date_format' => 'm/d/Y',
    '#default_value' => $form['#date']->format('Y-m-d'),
  );

  return $form;
}
lord_of_freaks’s picture

Status: Needs review » Closed (fixed)

Hi Micromegas

Thanks for the feedback, the bug was already fixed and commited in:

http://cgit.drupalcode.org/required_by_role/commit/?id=0ddb2a665df5b11dd8a7f7cff19805803117d534 and
http://cgit.drupalcode.org/required_by_role/commit/?id=0eeb53a96f14916f2074f1ccb3764c485a94e8e3

It will be available in the next release (hopefully today)