$hooks) { if ($module == $module_to_display) { foreach ($hooks as $hook => $description) { $form_id = 'trigger_' . $hook . '_assign_form'; $build[$form_id] = drupal_get_form($form_id, $module, $hook, $description['label']); } } } return $build; } /** * Confirm removal of an assigned action. * * @param $module * The tab of triggers the user will be directed to after successful * removal of the action, or if the confirmation form is cancelled. * @param $hook * @param $aid * The action ID. * @ingroup forms * @see trigger_unassign_submit() */ function trigger_unassign($form, $form_state, $module, $hook = NULL, $aid = NULL) { if (!($hook && $aid)) { drupal_goto('admin/structure/trigger'); } $form['hook'] = array( '#type' => 'value', '#value' => $hook, ); $form['module'] = array( '#type' => 'value', '#value' => $module, ); $form['aid'] = array( '#type' => 'value', '#value' => $aid, ); $action = actions_function_lookup($aid); $actions = actions_get_all_actions(); $destination = 'admin/structure/trigger/' . $module; return confirm_form($form, t('Are you sure you want to unassign the action %title?', array('%title' => $actions[$action]['label'])), $destination, t('You can assign it again later if you wish.'), t('Unassign'), t('Cancel') ); } /** * Submit callback for trigger_unassign() form. */ function trigger_unassign_submit($form, &$form_state) { $form_values = $form_state['values']; if ($form_values['confirm'] == 1) { $aid = actions_function_lookup($form_values['aid']); db_delete('trigger_assignments') ->condition('hook', $form_values['hook']) ->condition('aid', $aid) ->execute(); $actions = actions_get_all_actions(); watchdog('actions', 'Action %action has been unassigned.', array('%action' => check_plain($actions[$aid]['label']))); drupal_set_message(t('Action %action has been unassigned.', array('%action' => $actions[$aid]['label']))); $form_state['redirect'] = 'admin/structure/trigger/' . $form_values['module']; } else { drupal_goto('admin/structure/trigger'); } } /** * Returns the form for assigning an action to a trigger. * * @param $module * The name of the trigger group, e.g., 'node'. * @param $hook * The name of the trigger hook, e.g., 'node_insert'. * @param $label * A plain English description of what this trigger does. * * @ingoup forms * @see trigger_assign_form_validate() * @see trigger_assign_form_submit() */ 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', '#title' => t('Trigger: ') . $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' => "