Roger broke my stuff in #574196: $type parameter not used in ctools_ajax_associate_url_to_element()! :p

if I define a form element like:

<?php
$form
['job_type'] = array(
   
'#name' => 'datasync_scheduler_job_type',
   
'#title' => t('Job type'),
   
'#type' => 'select',
   
'#options' => $options,
   
'#description' => t('Type of job you want to add'),
   
'#default_value' => $defaults['job_type'],
   
'#attributes' => array('class' => 'ctools-use-ajax-onchange'),
  );
 
ctools_ajax_associate_url_to_element($form, $form['job_type'], $url);
?>

My ctools-use-ajax-onchange class gets overwritten. The attached patch fixes this behavior.

Files: 
CommentFileSizeAuthor
#3 652236.patch811 bytesandrewlevine
leaveMyClassPlease.patch860 bytesandrewlevine

Comments

q0rban’s picture

Why not:

<?php
  $form_element
['#attributes']['class'] = $form_element['#attributes']['class'] ? $form_element['#attributes']['class'] ." $type" : $type;
?>

or:

<?php
   
if ($form_element['#attributes']['class']) {
     
$form_element['#attributes']['class'] = $type;
    }
    else {
     
$form_element['#attributes']['class'] .= " $type";
    }
?>
andrewlevine’s picture

I believe both of your examples will generate "Notice: Undefined index" if $form_element['#attributes']['class'] isn't set. Although I also think you can use !empty() safely instead of isset() && !empty() so I was being verbose

andrewlevine’s picture

StatusFileSize
new811 bytes

removing the unnecessary isset() check

merlinofchaos’s picture

Status:Needs review» Fixed

Committed.

Status:Fixed» Closed (fixed)

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