You are here

function rules_admin_form_export in Rules 6

Exports one or more configurations

1 string reference to 'rules_admin_form_export'
rules_admin_menu in rules_admin/rules_admin.module
Implementation of hook_menu().

File

rules_admin/rules_admin.export.inc, line 121

Code

function rules_admin_form_export($form_state) {
  $form = array();
  if (!isset($form_state['export'])) {
    $form['export'] = array(
      '#tree' => TRUE,
    );
    foreach (rules_get_items() as $name => $info) {
      $items = rules_get_configured_items($name);
      if ($name === 'rules') {

        // Filter out rules within rule sets, we only want event-triggered,
        // standalone rules.
        $items = array_filter($items, 'rules_admin_is_event_rule');
        $info['label'] = t('Triggered rules');
      }
      $items = rules_admin_get_grouped_labels($items);
      if (count($items)) {
        $form['export'][$name] = array(
          '#type' => 'select',
          '#title' => t('Select the %label to export', array(
            '%label' => $info['label'],
          )),
          '#options' => array(
            0 => '-',
          ) + $items,
          '#multiple' => TRUE,
          '#default_value' => 0,
        );
      }
      else {
        $msg = t('There are no %label to be exported.', array(
          '%label' => $info['label'],
        ));
        $form['export'][$name] = array(
          '#value' => '<p>' . $msg . '</p>',
        );
      }
    }

    // Add the possibility to export by category
    if ($tags = rules_admin_get_categories('rules') + rules_admin_get_categories('rule_sets')) {
      $form['export_by_tag'] = array(
        '#type' => 'select',
        '#title' => t('Export by category'),
        '#options' => array(
          0 => '-',
        ) + $tags,
        '#multiple' => TRUE,
        '#default_value' => 0,
      );
    }
    $form['button'] = array(
      '#type' => 'submit',
      '#weight' => 10,
      '#value' => t('Export'),
    );
  }
  else {

    //show a textarea containg the exported configs
    $form['result'] = array(
      '#type' => 'textarea',
      '#title' => t('Exported rule configurations'),
      '#description' => t('Copy these data and paste them into the import page, to import.'),
      '#rows' => 30,
      '#default_value' => var_export($form_state['export'], TRUE),
    );
  }
  return $form;
}