You are here

function entity_rules_bundle_rules_form in Entity Rules 7

Form for setting Rule parmeters for a Bundle

1 string reference to 'entity_rules_bundle_rules_form'
entity_rules_type_op_rules in ./entity_rules.admin.inc
Page call back to list Rules for a bundle.

File

./entity_rules.admin.inc, line 108
Admin functions.

Code

function entity_rules_bundle_rules_form($form, &$form_state, $entity_type, $bundle, $op) {
  $rule_settings = entity_rules_load_settings_for_op($entity_type, $bundle, $op, TRUE);
  $show_tokens = FALSE;
  if (empty($rule_settings)) {
    $form['empty'] = array(
      '#type' => 'markup',
      '#markup' => t('There are currently no active rules'),
    );
    return $form;
  }
  $form['entity_type'] = array(
    '#type' => 'value',
    '#value' => $entity_type,
  );
  $form['bundle'] = array(
    '#type' => 'value',
    '#value' => $bundle,
  );
  $form['op'] = array(
    '#type' => 'value',
    '#value' => $op,
  );
  $current_path = current_path();
  $length = strlen('entity-rules');
  $ends_with_rules = substr($current_path, -$length) === 'entity-rules';
  if ($ends_with_rules) {
    $current_path .= '/create';
  }
  $form['settings']['#tree'] = TRUE;
  $weight = 0;
  foreach ($rule_settings as $id => $rule_setting) {
    $rule = $rule_setting->loaded_rules_config;
    if (isset($rule)) {
      $form_row = array();
      $form_row['name'] = array(
        '#type' => 'markup',
        '#markup' => $rule->label . ' ' . l(t('edit'), "admin/config/workflow/entity_rules/{$op}/manage/{$rule->id}"),
      );
      $form_row['id'] = array(
        '#type' => 'value',
        '#value' => $rule_setting->id,
      );
      $vars = _entity_rules_get_extra_vars($rule, $op);
      if (!empty($vars)) {
        foreach ($vars as $param_name => $param_info) {
          switch ($param_info['type']) {
            case 'text':
              $form_row['args'][$param_name] = array(
                '#type' => 'textarea',
                '#cols' => 15,
                '#rows' => 3,
                '#title' => $param_info['label'],
                '#default_value' => isset($rule_setting->args[$param_name]) ? $rule_setting->args[$param_name] : NULL,
              );
              break;
            default:
              $form_row['args'][$param_name] = array(
                '#type' => $param_info['type'] == 'boolean' ? 'checkbox' : 'textfield',
                '#title' => $param_info['label'],
                '#default_value' => isset($rule_setting->args[$param_name]) ? $rule_setting->args[$param_name] : NULL,
              );
          }
        }
      }
      if (is_subclass_of($rule, 'RulesConditionContainer')) {
        $form_row['false_msg'] = array(
          '#type' => 'text_format',
          '#cols' => 15,
          '#rows' => 3,
          '#title' => t('Rule returns false message'),
          '#default_value' => isset($rule_setting->false_msg['value']) ? $rule_setting->false_msg['value'] : NULL,
          '#format' => isset($rule_setting->false_msg['format']) ? $rule_setting->false_msg['format'] : NULL,
          '#description' => t('This message will be displayed if this Rule evalutes to FALSE.'),
        );
        $show_tokens = TRUE;
      }
      $remove_path = str_replace('/entity-rules', '/entity-rules-remove', $current_path) . "/{$id}";
      $form_row['remove_link'] = array(
        '#markup' => l(t('Remove'), $remove_path),
      );
      $form_row['weight'] = array(
        '#type' => 'weight',
        '#title' => t('Weight'),
        '#default_value' => $weight++,
        '#delta' => 10,
        '#title-display' => 'invisible',
      );
      $form['settings'][$id] = $form_row;
    }
  }
  if ($show_tokens && module_exists('token')) {
    $form['tokens'] = array(
      '#theme' => 'token_tree',
      '#token_types' => array(
        $entity_type,
      ),
      // The token types that have specific context. Can be multiple token types like 'term' and/or 'user'
      '#global_types' => TRUE,
      // A boolean TRUE or FALSE whether to include 'global' context tokens like [current-user:*] or [site:*]. Defaults to TRUE.
      '#click_insert' => TRUE,
      // A boolean whether to include the 'Click this token to insert in into the the focused textfield' JavaScript functionality. Defaults to TRUE.
      '#dialog' => TRUE,
    );
  }
  $form['#theme'] = 'entity_rules_bundle_rules_form';
  $form['actions'] = array(
    '#type' => 'actions',
  );
  $form['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save Changes'),
  );
  return $form;
}