function rules_action_taxonomy_load_term_form in Rules 6
Action: Load a term configuration form.
Multistep form.
Related topics
File
- rules/
modules/ taxonomy.rules_forms.inc, line 16 - Rules configuration forms for the taxonomy module.
Code
function rules_action_taxonomy_load_term_form($settings, &$form, $form_state) {
$settings += array(
'vocabulary' => 0,
);
if (empty($settings['vocabulary'])) {
// Get existing taxonomy vocabularies.
$vocab = $options = array();
$options = _rules_action_taxonomy_get_vocab();
$form['settings']['vocabulary'] = array(
'#type' => 'select',
'#title' => t('Vocabulary'),
'#options' => $options,
'#description' => !empty($options) ? t('Select the vocabulary.') : t('There are no existing vocabularies, you should <a href="@add-url">add</a> one.', array(
'@add-url' => url('/admin/content/taxonomy/add/vocabulary'),
)),
'#required' => TRUE,
'#disabled' => empty($options),
);
// Hide some form elements in the first step.
$form['new']['#access'] = FALSE;
$form['input_help']['#access'] = FALSE;
$form['weight']['#access'] = FALSE;
// Replace the usual submit handlers with our own handler.
$form['submit']['#submit'] = array(
'rules_action_taxonomy_load_term_form_step_submit',
);
$form['submit']['#value'] = t('Continue');
}
else {
$options = array();
$vocabulary = taxonomy_vocabulary_load($settings['vocabulary']);
$terms = taxonomy_get_tree($vocabulary->vid);
foreach ($terms as $term) {
$options[$term->tid] = check_plain($term->name);
}
$form['settings']['term'] = array(
'#type' => 'fieldset',
'#title' => t("Select a term"),
'#description' => empty($options) ? t('There are no terms in the vocabulary, you should <a href="@add-url">add</a> one.', array(
'@add-url' => url('admin/content/taxonomy/' . $vocabulary->vid . '/add/term'),
)) : t('Select an existing term from vocabulary !vocab or manually enter the name of the term that should be added or removed from the content.', array(
'!vocab' => $vocabulary->name,
)),
);
$form['settings']['term']['term_select'] = rules_taxonomy_form($vocabulary->vid, !empty($settings['term']['term_select']) ? $settings['term']['term_select'] : 0);
$form['settings']['term']['term_text'] = array(
'#type' => 'textarea',
'#title' => t('Select by term id'),
'#default_value' => !empty($settings['term']['term_text']) ? $settings['term']['term_text'] : '',
'#disabled' => empty($options),
'#description' => t('Optional: enter the term id (<em>not the term name</em>) that should be loaded . If this field is used "Select a term" field will be ignored.'),
);
}
}