You are here

function rules_link_form_submit in Rules Link 7

Same name and namespace in other branches
  1. 7.2 rules_link.admin.inc \rules_link_form_submit()

Form API submit callback for the type form.

File

./rules_link.admin.inc, line 395
Generate a admin UI.

Code

function rules_link_form_submit(&$form, &$form_state) {
  $rules_link = entity_ui_form_submit_build_entity($form, $form_state);
  $form_state['redirect'] = 'admin/config/workflow/rules_links';
  if (empty($rules_link->path)) {
    $rules_link->path = $rules_link->name;
  }
  if ($form_state['op'] == 'add') {
    $form_state['redirect'] = 'admin/config/workflow/rules_links/manage/' . $rules_link->name;
    $rule_set = rules_link_load_rules_set($rules_link);
    $condition_set = rules_link_load_condition_set($rules_link);
    $rules_set_vars =& $rule_set
      ->componentVariables();
    $condition_vars =& $condition_set
      ->componentVariables();

    // Remove the first element, since it is decoration only and it might be
    // wrong in case Javascript is disabled.
    array_shift($form_state['values']['settings']['vars']['items']);
    foreach ($form_state['values']['settings']['vars']['items'] as $var) {
      if ($var['type'] !== '0') {
        $val = array(
          'label' => $var['label'],
          'type' => $var['type'],
        );
        $rules_set_vars[$var['name']] = $val;
        $condition_vars[$var['name']] = $val;
      }
    }
    $condition_set->label = 'Rules link: ' . $rules_link->label . ' condition';
    $condition_set
      ->save(rules_link_get_condition_set_name($rules_link), 'rules_link');
    $rule_set->label = 'Rules link: ' . $rules_link->label . ' rules set';
    $rule_set
      ->save(rules_link_get_rules_set_name($rules_link), 'rules_link');
    drupal_set_message(t('Your Rules Link has been created along with the required components. Please remember to set <a href="!url">%link</a> for your link and to add actions to your reactions rule.', array(
      '%link' => t('the permissions'),
      '!url' => url('admin/people/permissions', array(
        'fragment' => 'module-rules_link',
      )),
    )));
  }
  else {
    drupal_set_message(t('Your Rules Link has been saved.'));
  }

  // Save and go back.
  $rules_link
    ->save();
}