array('ctools_dependent_process'), @endcode * - @code '#dependency' => array('id-of-form-without-the-#' => array(list, of, values, that, make, this, gadget, visible)), @endcode * * A fuller example, that hides the menu title when no menu is selected: * @code *function ctools_dependent_example() { * $form = array(); * $form['menu'] = array( * '#type' => 'fieldset', * '#title' => t('Menu settings'), * '#tree' => TRUE, * ); * $form['menu']['type'] = array( * '#title' => t('Menu type'), * '#type' => 'radios', * '#options' => array( * 'none' => t('No menu entry'), * 'normal' => t('Normal menu entry'), * 'tab' => t('Menu tab'), * 'default tab' => t('Default menu tab'), * ), * '#default_value' => 'none', * ); * * $form['menu']['title'] = array( * '#title' => t('Title'), * '#type' => 'textfield', * '#default_value' => '', * '#description' => t('If set to normal or tab, enter the text to use for the menu item.'), * '#process' => array('ctools_dependent_process'), * '#dependency' => array('radio:menu[type]' => array('normal', 'tab', 'default tab')), * ); * * $form['menu']['title']['#process'] = array('ctools_dependent_process'); * $form['menu']['title']['#dependency'] = array('radio:menu[type]' => array('normal', 'tab', 'default tab')); * * return system_settings_form($form); *} * @endcode */ /** * Process callback to add dependency to form items. */ function ctools_dependent_process($element, $edit, &$form_state, &$form) { if (isset($element['#dependency'])) { if (!isset($element['#dependency_count'])) { $element['#dependency_count'] = 1; } if (!isset($element['#dependency_type'])) { $element['#dependency_type'] = 'hide'; } $js = array( 'values' => $element['#dependency'], 'num' => $element['#dependency_count'], 'type' => $element['#dependency_type'], ); if (!empty($form_state['ajax'])) { $form_state['js settings']['CTools']['dependent'][$element['#id']] = $js; } else { ctools_add_js('dependent'); $options['CTools']['dependent'][$element['#id']] = $js; drupal_add_js($options, 'setting'); } } return $element; }