trigger_assign_form
- Versions
- 6
trigger_assign_form($form_state, $hook,$op,$description)- 7
trigger_assign_form($form, $form_state, $module, $hook, $label)
Returns the form for assigning an action to a trigger.
@ingoup forms
See also
trigger_assign_form_validate()
@see trigger_assign_form_submit()
Parameters
$module The name of the trigger group, e.g., 'node'.
$hook The name of the trigger hook, e.g., 'node_insert'.
$label A plain English description of what this trigger does.
Code
modules/trigger/trigger.admin.inc, line 115
<?php
function trigger_assign_form($form, $form_state, $module, $hook, $label) {
$form['module'] = array(
'#type' => 'hidden',
'#value' => $module,
);
$form['hook'] = array(
'#type' => 'hidden',
'#value' => $hook,
);
// All of these forms use the same validate and submit functions.
$form['#validate'][] = 'trigger_assign_form_validate';
$form['#submit'][] = 'trigger_assign_form_submit';
$options = array();
$functions = array();
// Restrict the options list to actions that declare support for this hook.
foreach (actions_list() as $func => $metadata) {
if (in_array('any', $metadata['triggers']) || in_array($hook, $metadata['triggers'])) {
$functions[] = $func;
}
}
foreach (actions_actions_map(actions_get_all_actions()) as $aid => $action) {
if (in_array($action['callback'], $functions)) {
$options[$action['type']][$aid] = $action['label'];
}
}
$form[$hook] = array(
'#type' => 'fieldset',
// !description is correct, since these labels are passed through t() in
// hook_trigger_info().
'#title' => t('Trigger: !description', array('!description' => $label)),
'#theme' => 'trigger_display',
);
// Retrieve actions that are already assigned to this hook combination.
$actions = trigger_get_assigned_actions($hook);
$form[$hook]['assigned']['#type'] = 'value';
$form[$hook]['assigned']['#value'] = array();
foreach ($actions as $aid => $info) {
$form[$hook]['assigned']['#value'][$aid] = array(
'label' => $info['label'],
'link' => l(t('unassign'), "admin/structure/trigger/unassign/$module/$hook/" . md5($aid)),
);
}
$form[$hook]['parent'] = array(
'#prefix' => "<div class='container-inline'>",
'#suffix' => '</div>',
);
// List possible actions that may be assigned.
if (count($options) != 0) {
array_unshift($options, t('Choose an action'));
$form[$hook]['parent']['aid'] = array(
'#type' => 'select',
'#options' => $options,
);
$form[$hook]['parent']['submit'] = array(
'#type' => 'submit',
'#value' => t('Assign')
);
}
else {
$form[$hook]['none'] = array(
'#markup' => t('No actions available for this trigger. <a href="@link">Add action</a>.', array('@link' => url('admin/config/system/actions/manage')))
);
}
return $form;
}
?>Login or register to post comments 