You are here

public function ParserBase::_buildConfigurationForm in Feeds extensible parsers 8

Builds configuration form for the parser settings.

@todo The code below is still D7 code and does not work in D8 yet. Also, it's likely that most of the code below is no longer needed as the parser UI is planned to be implemented in a completely different way.

See also

https://www.drupal.org/node/2917924

File

src/Feeds/Parser/ParserBase.php, line 596

Class

ParserBase
The Feeds extensible parser.

Namespace

Drupal\feeds_ex\Feeds\Parser

Code

public function _buildConfigurationForm(array $form, FormStateInterface $form_state) {
  $form = [
    '#tree' => TRUE,
    '#theme' => 'feeds_ex_configuration_table',
    '#prefix' => '<div id="feeds-ex-configuration-wrapper">',
    '#suffix' => '</div>',
  ];
  $form['sources'] = [
    '#id' => 'feeds-ex-source-table',
    '#attributes' => [
      'class' => [
        'feeds-ex-source-table',
      ],
    ],
  ];
  $max_weight = 0;
  foreach ($this->configuration['sources'] as $machine_name => $source) {
    $form['sources'][$machine_name]['name'] = [
      '#type' => 'textfield',
      '#title' => $this
        ->t('Name'),
      '#title_display' => 'invisible',
      '#default_value' => $source['name'],
      '#size' => 20,
    ];
    $form['sources'][$machine_name]['machine_name'] = [
      '#title' => $this
        ->t('Machine name'),
      '#title_display' => 'invisible',
      '#markup' => $machine_name,
    ];
    $form['sources'][$machine_name]['value'] = [
      '#type' => 'textfield',
      '#title' => $this
        ->t('Value'),
      '#title_display' => 'invisible',
      '#default_value' => $source['value'],
      '#size' => 50,
      '#maxlength' => 1024,
    ];
    foreach ($this
      ->configFormTableHeader() as $column => $name) {
      $form['sources'][$machine_name][$column] = $this
        ->configFormTableColumn($form_state, $source, $column, $machine_name);
    }
    $form['sources'][$machine_name]['debug'] = [
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Debug'),
      '#title_display' => 'invisible',
      '#default_value' => $source['debug'],
    ];
    $form['sources'][$machine_name]['remove'] = [
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Remove'),
      '#title_display' => 'invisible',
    ];
    $form['sources'][$machine_name]['weight'] = [
      '#type' => 'textfield',
      '#default_value' => $source['weight'],
      '#size' => 3,
      '#attributes' => [
        'class' => [
          'feeds-ex-source-weight',
        ],
      ],
    ];
    $max_weight = $source['weight'];
  }
  $form['add']['name'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Add new source'),
    '#id' => 'edit-sources-add-name',
    '#description' => $this
      ->t('Name'),
    '#size' => 20,
  ];
  $form['add']['machine_name'] = [
    '#title' => $this
      ->t('Machine name'),
    '#title_display' => 'invisible',
    '#type' => 'machine_name',
    '#machine_name' => [
      'exists' => 'feeds_ex_source_exists',
      'source' => [
        'add',
        'name',
      ],
      'standalone' => TRUE,
      'label' => '',
    ],
    '#field_prefix' => '<span dir="ltr">',
    '#field_suffix' => '</span>&lrm;',
    '#feeds_importer' => $this->id,
    '#required' => FALSE,
    '#maxlength' => 32,
    '#size' => 15,
    '#description' => $this
      ->t('A unique machine-readable name containing letters, numbers, and underscores.'),
  ];
  $form['add']['value'] = [
    '#type' => 'textfield',
    '#description' => $this
      ->t('Value'),
    '#title' => '&nbsp;',
    '#size' => 50,
    '#maxlength' => 1024,
  ];
  foreach ($this
    ->configFormTableHeader() as $column => $name) {
    $form['add'][$column] = $this
      ->configFormTableColumn($form_state, [], $column, '');
  }
  $form['add']['debug'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Debug'),
    '#title_display' => 'invisible',
  ];
  $form['add']['weight'] = [
    '#type' => 'textfield',
    '#default_value' => ++$max_weight,
    '#size' => 3,
    '#attributes' => [
      'class' => [
        'feeds-ex-source-weight',
      ],
    ],
  ];
  $form['display_errors'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Display errors'),
    '#description' => $this
      ->t('Display all error messages after parsing. Fatal errors will always be displayed.'),
    '#default_value' => $this->configuration['display_errors'],
  ];
  $form['debug_mode'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Enable debug mode'),
    '#description' => $this
      ->t('Displays the configuration form on the feed source page to ease figuring out the expressions. Any values entered on that page will be saved here.'),
    '#default_value' => $this->configuration['debug_mode'],
  ];
  $form = $this
    ->getEncoder()
    ->buildConfigurationForm($form, $form_state);
  $form['#attached']['drupal_add_tabledrag'][] = [
    'feeds-ex-source-table',
    'order',
    'sibling',
    'feeds-ex-source-weight',
  ];
  $form['#attached']['css'][] = drupal_get_path('module', 'feeds_ex') . '/feeds_ex.css';
  $form['#header'] = $this
    ->getFormHeader();
  return $form;
}