You are here

protected function ParserBase::baseForm in Feeds XPath Parser 8

2 calls to ParserBase::baseForm()
ParserBase::buildForm in lib/Drupal/feeds_xpathparser/ParserBase.php
Form constructor.
ParserBase::feedForm in lib/Drupal/feeds_xpathparser/ParserBase.php

File

lib/Drupal/feeds_xpathparser/ParserBase.php, line 199
Contains \Drupal\feeds_xpathparser\ParserBase.

Class

ParserBase
Base class for the HTML and XML parsers.

Namespace

Drupal\feeds_xpathparser

Code

protected function baseForm(array $form, array $form_state, array $config) {
  $mappings = $this->importer->processor
    ->getMappings();
  $targets = $this->importer->processor
    ->getMappingTargets();
  if (empty($mappings)) {

    // Detect if Feeds menu structure has changed. This will take a while to
    // be released, but since I run dev it needs to work.
    $feeds_base = 'admin/structure/feeds/manage/';
    $form['xpath']['error_message']['#markup'] = '<div class="help">' . t('No XPath mappings are defined. Define mappings !link.', array(
      '!link' => l(t('here'), $feeds_base . $this->id . '/mapping'),
    )) . '</div><br />';
    return $form;
  }
  $form['context'] = array(
    '#type' => 'textfield',
    '#title' => t('Context'),
    '#required' => TRUE,
    '#description' => t('This is the base query, all other queries will run in this context.'),
    '#default_value' => $config['context'],
    '#maxlength' => 1024,
    '#size' => 80,
    '#required' => TRUE,
  );
  $uniques = $this
    ->getUniques();
  if (!empty($uniques)) {
    $items = array(
      format_plural(count($uniques), t('Field <strong>!column</strong> is mandatory and considered unique: only one item per !column value will be created.', array(
        '!column' => implode(', ', $uniques),
      )), t('Fields <strong>!columns</strong> are mandatory and values in these columns are considered unique: only one entry per value in one of these columns will be created.', array(
        '!columns' => implode(', ', $uniques),
      ))),
    );
    $form['help']['#markup'] = '<div class="help">' . theme('item_list', array(
      'items' => $items,
    )) . '</div>';
  }
  $form['sources'] = array(
    '#type' => 'fieldset',
    '#tree' => TRUE,
  );
  $variables = array();
  foreach ($this
    ->getOwnMappings() as $source => $target) {
    $form['sources'][$source] = array(
      '#type' => 'textfield',
      '#title' => check_plain($targets[$target]['name']),
      '#description' => t('The XPath query to run.'),
      '#default_value' => isset($config['sources'][$source]) ? $config['sources'][$source] : '',
      '#maxlength' => 1024,
      '#size' => 80,
    );
    if (!empty($variables)) {
      $variable_text = format_plural(count($variables), t('The variable %variable is available for replacement.', array(
        '%variable' => implode(', ', $variables),
      )), t('The variables %variable are available for replacement.', array(
        '%variable' => implode(', ', $variables),
      )));
      $form['sources'][$source]['#description'] .= '<br />' . $variable_text;
    }
    $variables[] = '$' . $target;
  }
  $form['settings'] = array(
    '#type' => 'vertical_tabs',
    '#weight' => 99,
  );
  $form['raw_xml_settings'] = array(
    '#type' => 'details',
    '#group' => 'settings',
    '#title' => t('Raw XML'),
    '#collapsed' => TRUE,
    '#tree' => FALSE,
  );
  $form['raw_xml_settings']['raw_xml'] = array(
    '#type' => 'checkboxes',
    '#title' => t('Select the queries you would like to return raw XML or HTML'),
    '#options' => $this
      ->getOwnMappings(TRUE),
    '#default_value' => $config['raw_xml'],
  );
  $form['debug'] = array(
    '#type' => 'details',
    '#group' => 'settings',
    '#title' => t('Debug'),
    '#collapsed' => TRUE,
    '#tree' => FALSE,
  );
  $form['debug']['errors'] = array(
    '#type' => 'checkbox',
    '#title' => t('Show error messages.'),
    '#default_value' => $config['errors'],
  );
  $form['debug']['debug'] = array(
    '#type' => 'checkboxes',
    '#title' => t('Debug query'),
    '#options' => array_merge(array(
      'context' => t('Context'),
    ), $this
      ->getOwnMappings(TRUE)),
    '#default_value' => $config['debug'],
  );
  if (extension_loaded('tidy')) {
    $form['debug']['tidy'] = array(
      '#type' => 'checkbox',
      '#title' => t('Use Tidy'),
      '#description' => t('The Tidy PHP extension has been detected.
                              Select this to clean the markup before parsing.'),
      '#default_value' => $config['tidy'],
    );
    $form['debug']['tidy_encoding'] = array(
      '#type' => 'textfield',
      '#title' => t('Tidy encoding'),
      '#description' => t('Set the encoding for tidy. See the !phpdocs for possible values.', array(
        '!phpdocs' => l(t('PHP docs'), 'http://www.php.net/manual/en/tidy.parsestring.php/'),
      )),
      '#default_value' => $config['tidy_encoding'],
      '#states' => array(
        'visible' => array(
          ':input[name="tidy"],:input[name="parser[tidy]"]' => array(
            'checked' => TRUE,
          ),
        ),
      ),
    );
  }
  return $form;
}