function trigger_assign_form_submit

cis7 trigger.admin.inc trigger_assign_form_submit($form, &$form_state)
cle7 trigger.admin.inc trigger_assign_form_submit($form, &$form_state)
elmsmedia7 trigger.admin.inc trigger_assign_form_submit($form, &$form_state)
icor7 trigger.admin.inc trigger_assign_form_submit($form, &$form_state)
meedjum_blog7 trigger.admin.inc trigger_assign_form_submit($form, &$form_state)
mooc7 trigger.admin.inc trigger_assign_form_submit($form, &$form_state)

Form submission handler for trigger_assign_form().

See also

trigger_assign_form_validate()

1 string reference to 'trigger_assign_form_submit'
trigger_assign_form in modules/trigger/trigger.admin.inc
Returns the form for assigning an action to a trigger.

File

modules/trigger/trigger.admin.inc, line 231
Admin page callbacks for the trigger module.

Code

function trigger_assign_form_submit($form, &$form_state) {
  if (!empty($form_state['values']['aid'])) {
    $aid = actions_function_lookup($form_state['values']['aid']);
    $weight = db_query("SELECT MAX(weight) FROM {trigger_assignments} WHERE hook = :hook", array(':hook' => $form_state['values']['hook']))->fetchField();

    // Insert the new action.
    db_insert('trigger_assignments')->fields(array(
      'hook' => $form_state['values']['hook'],
      'aid' => $aid,
      'weight' => $weight + 1,
    ))->execute();

    // If we are not configuring an action for a "presave" hook and this action
    // changes an object property, then we need to save the object, so the
    // property change will persist.
    $actions = actions_list();
    if (strpos($form_state['values']['hook'], 'presave') === FALSE && isset($actions[$aid]['behavior']) && in_array('changes_property', $actions[$aid]['behavior'])) {
      // Determine the corresponding save action name for this action.
      $save_action = strtok($aid, '_') . '_save_action';
      // If no corresponding save action exists, we need to bail out.
      if (!isset($actions[$save_action])) {
        throw new Exception(t('Missing/undefined save action (%save_aid) for %aid action.', array('%save_aid' => $aid, '%aid' => $aid)));
      }
      // Delete previous save action if it exists, and re-add it using a higher
      // weight.
      $save_action_assigned = db_query("SELECT aid FROM {trigger_assignments} WHERE hook = :hook AND aid = :aid", array(':hook' => $form_state['values']['hook'], ':aid' => $save_action))->fetchField();

      if ($save_action_assigned) {
        db_delete('trigger_assignments')->condition('hook', $form_state['values']['hook'])->condition('aid', $save_action)->execute();
      }
      db_insert('trigger_assignments')->fields(array(
        'hook' => $form_state['values']['hook'],
        'aid' => $save_action,
        'weight' => $weight + 2,
      ))->execute();

      // If no save action existed before, inform the user about it.
      if (!$save_action_assigned) {
        drupal_set_message(t('The %label action has been appended, which is required to save the property change.', array('%label' => $actions[$save_action]['label'])));
      }
      // Otherwise, just inform about the new weight.
      else {
        drupal_set_message(t('The %label action was moved to save the property change.', array('%label' => $actions[$save_action]['label'])));
      }
    }
  }
  drupal_static_reset('trigger_get_assigned_actions');
}
Error | ELMSLN API

Error

×

Error message

  • Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/elmsln_community/api.elmsln.org/includes/common.inc:2791) in drupal_send_headers() (line 1499 of /var/www/html/elmsln_community/api.elmsln.org/includes/bootstrap.inc).
  • Error: Call to undefined function apc_delete() in DrupalAPCCache->clear() (line 289 of /var/www/html/elmsln_community/api.elmsln.org/sites/all/modules/apc/drupal_apc_cache.inc).
The website encountered an unexpected error. Please try again later.