You are here

function feed_import_generate_xpath_item in Feed Import 7.2

Same name and namespace in other branches
  1. 7 feed_import.module \feed_import_generate_xpath_item()

Generate field

Parameters

int $pos: Fieldset number

array $values: Array containing default values

bool $collapsed: Inicates if fieldset is collapsed

Return value

array Fieldset containing xpath inputs

1 call to feed_import_generate_xpath_item()
feed_import_edit_feed_form in ./feed_import.module
Edit feed form

File

./feed_import.module, line 1438
User interface, cron functions for feed_import module

Code

function feed_import_generate_xpath_item($pos = 0, $values = NULL, $collapsed = FALSE) {
  $container = 'container_' . $pos;
  $item[$container] = array(
    '#type' => 'fieldset',
    '#collapsible' => TRUE,
    '#collapsed' => $collapsed,
    '#title' => isset($values['#field']) ? $values['#field'] : t('Unspecified field'),
    '#attributes' => array(
      'id' => 'item_container_' . $pos,
    ),
  );
  $container =& $item[$container];
  $values['#xpath'] = isset($values['#xpath']) ? $values['#xpath'] : '';
  if (is_array($values['#xpath'])) {
    $values['#xpath'] = implode(PHP_EOL, $values['#xpath']);
  }
  $container['xpath_' . $pos] = array(
    '#type' => 'textarea',
    '#default_value' => $values['#xpath'],
    '#title' => t('XPATH'),
    '#description' => t('Enter XPATH to item. You can enter multiple XPATHs (one per line) until one passes pre-filter.'),
  );
  $container['default_action_' . $pos] = array(
    '#type' => 'select',
    '#options' => FeedImport::getDefaultActions(),
    '#default_value' => isset($values['#default_action']) ? $values['#default_action'] : 'default_value',
    '#title' => t('Action when filtered result is empty'),
    '#description' => t('If the filter is empty you can choose what action to take next.'),
  );
  $container['default_' . $pos] = array(
    '#type' => 'textfield',
    '#default_value' => isset($values['#default_value']) ? $values['#default_value'] : '',
    '#title' => t('Default value'),
    '#description' => t('If no XPATH passes pre-filter then use a default value.'),
    '#prefix' => '<div style="display: none;" rel="default_action_' . $pos . '">',
    '#suffix' => '</div>',
  );
  $container['remove_container_' . $pos] = array(
    '#type' => 'button',
    '#value' => t('Remove field @field', array(
      '@field' => drupal_strtoupper($container['#title']),
    )),
    '#ajax' => array(
      'event' => 'click',
      'wrapper' => 'item_container_' . $pos,
      'method' => 'replace',
      'callback' => 'feed_import_ajax_remove_item',
    ),
  );
  return $item;
}