public function Paragraphs::buildConfigurationForm

File

paragraphs/src/Feeds/Target/Paragraphs.php, line 67

Class

Paragraphs
Feeds target plugin for Paragraphs fields.

Namespace

Drupal\paragraphs\Feeds\Target

Code

public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
  $form['paragraphs_type'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Paragraphs type'),
    '#required' => TRUE,
    '#options' => array_map(function (EntityInterface $paragraphs_type) {
      return $paragraphs_type
        ->label();
    }, $this->paragraphsTypeStorage
      ->loadMultiple()),
    '#default_value' => $this->configuration['paragraphs_type'],
  ];

  // Load and filter field configs to create options.

  /** @var \Drupal\field\FieldConfigInterface[] $field_configs */
  $field_configs = $this->fieldConfigStorage
    ->loadByProperties([
    'entity_type' => 'paragraph',
    'bundle' => $this->configuration['paragraphs_type'],
  ]);
  $field_options = [];
  foreach ($field_configs as $field_config) {
    if (in_array($field_config
      ->getType(), [
      'text',
      'text_long',
      'text_with_summary',
    ])) {
      $field_options[$field_config
        ->getName()] = $field_config
        ->label();
    }
  }
  $form['paragraph_field'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Paragraph field'),
    '#description' => $this
      ->t('<strong>Note:</strong> Field options do not appear until a type has been chosen and saved.'),
    '#options' => $field_options,
  ];
  $form = parent::buildConfigurationForm($form, $form_state);
  return $form;
}