You are here

function rules_link_component_form_submit in Rules Link 7

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

Form API submit callback for the type form.

File

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

Code

function rules_link_component_form_submit(&$form, &$form_state) {
  $rules_set_vars = $form_state['rules_link_rules_set']
    ->componentVariables();
  $form_state['rules_link_rules_set']
    ->form_submit($form['rule_set'], $form_state);
  $condition_vars =& $form_state['rules_link_condition_set']
    ->componentVariables();
  foreach ($condition_vars as $key => $value) {
    unset($condition_vars[$key]);
  }
  foreach ($rules_set_vars as $key => $value) {
    $condition_vars[$key] = $value;
  }
  $form_state['rules_link_condition_set']
    ->form_submit($form['condition_set'], $form_state);

  // If the rule is renamed, rename also the rules set.
  if ($form_state['rules_link_condition_set']->name != rules_link_get_condition_set_name($form_state['rules_link'])) {
    $form_state['rules_link_condition_set']->label = 'Rules link: ' . $form_state['rules_link']->label . ' condition';
    $form_state['rules_link_condition_set']
      ->save(rules_link_get_condition_set_name($form_state['rules_link']), 'rules_link');
  }

  // If the rule is renamed, rename also the rules set.
  if ($form_state['rules_link_rules_set']->name != rules_link_get_rules_set_name($form_state['rules_link'])) {
    $form_state['rules_link_rules_set']->label = 'Rules link: ' . $form_state['rules_link']->label . ' rules set';
    $form_state['rules_link_rules_set']
      ->save(rules_link_get_rules_set_name($form_state['rules_link']), 'rules_link');
  }

  // Save the permission matrix if access is exposed
  if (isset($form_state['values']['rule_set']['settings']['access']) && !empty($form_state['values']['rule_set']['settings']['access']['access_exposed'])) {

    // Save the permission matrix.
    foreach ($form_state['values']['rule_set']['settings']['access']['permissions']['matrix']['checkboxes'] as $rid => $value) {
      user_role_change_permissions($rid, $value);
    }
  }

  // If an additional variable was added, then disable 'show link in entity'.
  if (count($rules_set_vars) > 1) {
    $form_state['rules_link']->settings['entity_link'] = FALSE;
    $form_state['rules_link']
      ->save();
  }
  drupal_set_message(t('Your Rules Link components has been saved.'));
}