You are here

protected function FieldsForm::generatePathItem in Feed Import 8

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 FieldsForm::generatePathItem()
FieldsForm::buildForm in src/Form/FieldsForm.php
Form constructor.

File

src/Form/FieldsForm.php, line 234
Contains \Drupal\feed_import\Form\FieldsForm

Class

FieldsForm

Namespace

Drupal\feed_import\Form

Code

protected function generatePathItem($pos, array $values, $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];
  $container['field'] = array(
    '#type' => 'value',
    '#value' => $values['field'],
  );
  $container['paths'] = array(
    '#type' => 'textarea',
    '#default_value' => is_array($values['paths']) ? implode(PHP_EOL, $values['paths']) : $values['paths'],
    '#title' => t('Paths'),
    '#description' => t('Enter path to item. You can enter multiple paths (one per line) until one passes pre-filter.'),
  );
  $container['default_action'] = array(
    '#type' => 'select',
    '#options' => array(
      FeedImportProcessor::ACTION_DEFAULT_VALUE => t('Provide a default value'),
      FeedImportProcessor::ACTION_DEFAULT_FILTERED_VALUE => t('Provide a filtered default value'),
      FeedImportProcessor::ACTION_IGNORE_FIELD => t('Ignore this field'),
      FeedImportProcessor::ACTION_SKIP_ITEM => t('Skip importing this entity'),
    ),
    '#default_value' => $values['default_action'],
    '#title' => t('Action when filtered result is empty'),
    '#description' => t('If the filtered result is empty you can choose what action to take next.'),
    '#id' => 'default_action_' . $pos,
  );
  $container['default_value'] = array(
    '#type' => 'textarea',
    '#rows' => 2,
    '#default_value' => $values['default_value'],
    '#title' => t('Default value'),
    '#description' => t('If no path passes pre-filter then use a default value.'),
    '#prefix' => '<div style="display: none;" rel="default_action_' . $pos . '">',
    '#suffix' => '</div>',
  );
  $options = \Drupal::moduleHandler()
    ->invokeAll('feed_import_field_merge_classes');
  foreach ($options as &$option) {
    $option = $option['title'];
  }
  $container['update_mode'] = array(
    '#type' => 'select',
    '#options' => $options,
    '#default_value' => $values['update_mode'],
    '#title' => t('Field update mode'),
    '#description' => t('How to update existing entities.'),
  );
  $container['remove_container_' . $pos] = array(
    '#type' => 'button',
    '#name' => 'remove_container_' . $pos,
    '#value' => t('Remove field'),
    '#ajax' => array(
      'event' => 'click',
      'wrapper' => 'item_container_' . $pos,
      'method' => 'replace',
      'callback' => array(
        $this,
        'ajaxRemoveItem',
      ),
    ),
  );
  return $item;
}