You are here

function node_export_settings in Node export 7.3

Same name and namespace in other branches
  1. 6.3 node_export.pages.inc \node_export_settings()
  2. 6.2 node_export.module \node_export_settings()

Menu callback to configure module settings.

1 string reference to 'node_export_settings'
node_export_menu in ./node_export.module
Implements hook_menu().

File

./node_export.pages.inc, line 37
The Node export pages file.

Code

function node_export_settings($form, &$form_state) {
  $types = node_type_get_names();
  menu_rebuild();
  $form['basic'] = array(
    '#type' => 'fieldset',
    '#title' => t('General settings'),
  );
  $format_handlers = node_export_format_handlers();
  $format_options = array();
  foreach ($format_handlers as $format_handler => $format) {
    $display = $format['#title'];
    if (!empty($format['#description'])) {
      $display .= '<div><small>';
      $display .= $format['#description'];
      $display .= '</small></div>';
    }
    $format_options[$format_handler] = $display;
    $format_settings = array();
    if (!empty($format['#settings_callback'])) {
      if (!empty($format['#file']) && is_file($format['#file'])) {
        require_once $format['#file'];
      }
      $format_form = call_user_func($format['#settings_callback'], $form, $form_state);
      $format_settings = $format_settings + $format_form;
    }
  }
  $selected_formats = variable_get('node_export_format', array(
    'drupal',
  ));
  if (!count(array_filter($selected_formats))) {
    $selected_formats = array(
      'drupal',
    );
  }
  if (count($format_options) > 1) {
    $form['basic']['node_export_format'] = array(
      '#type' => 'checkboxes',
      '#title' => t('Format to use when exporting a node'),
      '#default_value' => $selected_formats,
      '#options' => $format_options,
      '#description' => t("If you select multiple formats, they will all be available to the user.  If you select none, or the format handler is not found, it will use the default 'Drupal var export'.  This does not affect imports, the required import format will be used automatically."),
    );
  }
  else {
    $format = key($format_options);
    $form['basic']['node_export_format'] = array(
      '#type' => 'value',
      '#value' => array(
        $format => $format,
      ),
    );
  }
  $form['basic'][] = $format_settings;
  $form['basic']['node_export_code'] = array(
    '#type' => 'radios',
    '#title' => t('Node export code delivery'),
    '#options' => array(
      'all' => t('All of the below options on a page'),
      'copy' => t('Textarea filled with export code'),
      'file' => t('Text file download'),
    ),
    '#default_value' => variable_get('node_export_code', 'all'),
  );
  $form['basic']['filename'] = array(
    '#type' => 'fieldset',
    '#title' => t('Filename settings'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $form['basic']['filename']['node_export_filename'] = array(
    '#type' => 'textarea',
    '#title' => t('Filename pattern'),
    '#default_value' => variable_get('node_export_filename', 'node-export[node_export_filename:nid-list]([node_export_filename:node-count]-nodes).[node_export_filename:timestamp].[node_export_filename:format]'),
    '#rows' => 1,
    '#wysiwyg' => FALSE,
  );
  node_export_settings_token_bits($form['basic']['filename'], 'node_export_filename');
  $form['basic']['filename']['node_export_file_list'] = array(
    '#type' => 'textfield',
    '#title' => t('Node ID list max'),
    '#default_value' => variable_get('node_export_file_list', 10),
    '#size' => 6,
    '#maxlength' => 30,
    '#description' => t('If there are more than this many nodes, the [node_export_filename:nid-list] token for the filename will not be built.  This is to prevent very long filenames.'),
  );
  $form['basic']['node_export_existing'] = array(
    '#type' => 'radios',
    '#title' => t('When importing a node that already exists'),
    '#options' => array(
      'new' => t('Create a new node'),
      'revision' => t('Create a new revision of the existing node'),
      'skip' => t('Skip the node'),
    ),
    '#description' => t('UUIDs are used to uniquely identify nodes.'),
    '#default_value' => variable_get('node_export_existing', 'new'),
  );
  $form['publishing'] = array(
    '#type' => 'fieldset',
    '#title' => t('Reset values on import'),
  );
  foreach ($types as $type => $name) {
    $form['publishing'][$type] = array(
      '#type' => 'fieldset',
      '#title' => $name,
      '#description' => t('Reset these values when importing nodes of type @s.', array(
        '@s' => $name,
      )),
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
    );
    $form['publishing'][$type]['node_export_reset_status_' . $type] = array(
      '#type' => 'checkbox',
      '#title' => t('Published'),
      '#default_value' => variable_get('node_export_reset_status_' . $type, FALSE),
      '#description' => t('Set to unpublished'),
    );
    $form['publishing'][$type]['node_export_reset_promote_' . $type] = array(
      '#type' => 'checkbox',
      '#title' => t('Promoted to front page'),
      '#default_value' => variable_get('node_export_reset_promote_' . $type, FALSE),
      '#description' => t('Set to not promoted'),
    );
    $form['publishing'][$type]['node_export_reset_sticky_' . $type] = array(
      '#type' => 'checkbox',
      '#title' => t('Sticky at top of lists'),
      '#default_value' => variable_get('node_export_reset_sticky_' . $type, FALSE),
      '#description' => t('Set to not sticky'),
    );
    $form['publishing'][$type]['node_export_reset_author_' . $type] = array(
      '#type' => 'checkbox',
      '#title' => t('Author (will set to user performing the import)'),
      '#default_value' => variable_get('node_export_reset_author_' . $type, TRUE),
      '#description' => t('Recommended since User IDs could be different on import site and the wrong user may gain permission to edit the node.'),
    );
    $form['publishing'][$type]['node_export_reset_created_' . $type] = array(
      '#type' => 'checkbox',
      '#title' => t('Created time (<em>Authored on</em> date/time)'),
      '#default_value' => variable_get('node_export_reset_created_' . $type, TRUE),
    );
    $form['publishing'][$type]['node_export_reset_changed_' . $type] = array(
      '#type' => 'checkbox',
      '#title' => t('Changed time (<em>Last updated</em> date/time)'),
      '#default_value' => variable_get('node_export_reset_changed_' . $type, TRUE),
    );
    $form['publishing'][$type]['node_export_reset_revision_timestamp_' . $type] = array(
      '#type' => 'checkbox',
      '#title' => t('Revision changed time'),
      '#default_value' => variable_get('node_export_reset_revision_timestamp_' . $type, TRUE),
    );
    $form['publishing'][$type]['node_export_reset_last_comment_timestamp_' . $type] = array(
      '#type' => 'checkbox',
      '#title' => t('Last comment time (date/time the last comment was made)'),
      '#default_value' => variable_get('node_export_reset_last_comment_timestamp_' . $type, TRUE),
    );
    $form['publishing'][$type]['node_export_reset_menu_' . $type] = array(
      '#type' => 'checkbox',
      '#title' => t('Menu link'),
      '#default_value' => variable_get('node_export_reset_menu_' . $type, TRUE),
    );
    $form['publishing'][$type]['node_export_reset_path_' . $type] = array(
      '#type' => 'checkbox',
      '#title' => t('URL path'),
      '#default_value' => variable_get('node_export_reset_path_' . $type, TRUE),
    );
    $form['publishing'][$type]['node_export_reset_book_mlid_' . $type] = array(
      '#type' => 'checkbox',
      '#title' => t('Book menu link'),
      '#default_value' => variable_get('node_export_reset_book_mlid_' . $type, TRUE),
      '#description' => t('Prevents Book node imports causing errors.'),
    );
  }
  $form['file'] = array(
    '#type' => 'fieldset',
    '#title' => t('File fields'),
  );
  $types = node_type_get_names();
  $form['file']['node_export_file_types'] = array(
    '#type' => 'checkboxes',
    '#title' => t('Files exported for content types'),
    '#default_value' => variable_get('node_export_file_types', array()),
    '#options' => $types,
    '#description' => t('Which content types should export file fields?'),
  );
  $textarea_delivery = $form['basic']['node_export_code']['#default_value'];
  $mode_message_display = $textarea_delivery != 'file';
  $form['file']['node_export_file_mode'] = array(
    '#type' => 'radios',
    '#title' => t('File export mode'),
    '#default_value' => variable_get('node_export_file_mode', 'inline'),
    '#options' => array(
      'inline' => t('Inline Base64'),
      'local' => t('Local file export'),
      'remote' => t('Remote file export, URL'),
    ),
    '#description' => t('Should file exports be inline inside the export code, a local path to the file, or a URL?  Inline Base64 is the easiest option to use but can sometimes exceed PHP post limits, local and remote modes are more useful for power users.  <em>NOTE: Remote mode only works with a public files directory.</em>'),
  );
  $form['file']['node_export_file_assets_path'] = array(
    '#type' => 'textfield',
    '#title' => t('Local file field assets path'),
    '#size' => 60,
    '#maxlength' => 255,
    '#default_value' => variable_get('node_export_file_assets_path', ''),
    '#description' => t('Optionally, copy files to this path when the node is exported.
      The primary advantage of this is to divert exported files into a
      safe location so they can be committed to source control (eg: SVN,
      CVS, Git).  <em>Tip: For install profile developers, setting this
      path to <code>profiles/my_profile/node_export_assets</code> may be
      useful.</em>'),
    '#required' => FALSE,
    '#states' => array(
      'visible' => array(
        ':input[name=node_export_file_mode]' => array(
          'value' => 'local',
        ),
      ),
    ),
  );
  $form['file']['node_export_file_supported_fields'] = array(
    '#type' => 'textfield',
    '#title' => t('Supported file field types'),
    '#default_value' => variable_get('node_export_file_supported_fields', 'file, image'),
    '#maxlength' => 512,
    '#description' => t('Comma separated list of file field types to detect for export/import.'),
  );
  return system_settings_form($form);
}