You are here

public function ExportForm::buildForm in Default Content Deploy 8

Form constructor.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array The form structure.

Overrides FormInterface::buildForm

File

src/Form/ExportForm.php, line 87

Class

ExportForm
Config Form for run DCD deploy in Admin UI.

Namespace

Drupal\default_content_deploy\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $form['mode'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Mode'),
    '#description' => $this
      ->t('Mode of the export (export all content, with reference etc). Read more in the documentation.'),
    '#required' => TRUE,
    '#options' => [
      'default' => $this
        ->t('Content of the entity type'),
      'reference' => $this
        ->t('Content of the entity type with reference'),
      'all' => $this
        ->t('All content'),
    ],
    '#default_value' => 'default',
    '#ajax' => [
      'callback' => [
        $this,
        'processingMode',
      ],
      'wrapper' => 'edit-settings-wrapper',
    ],
  ];
  $form['settings'] = [
    '#type' => 'container',
    '#attributes' => [
      'style' => 'display:block',
    ],
    '#prefix' => '<div id="edit-settings-wrapper">',
    '#suffix' => '</div>',
  ];
  $form['settings']['entity_type'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Entity type'),
    '#description' => $this
      ->t('Select entity type id for exporting.'),
    '#empty_value' => '',
    '#options' => $this->deployManager
      ->getContentEntityTypes(),
    '#ajax' => [
      'callback' => [
        $this,
        'processingEntityType',
      ],
      'wrapper' => 'edit-entity-bundle-wrapper',
    ],
  ];
  $form['settings']['bundle'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Bundle'),
    '#description' => $this
      ->t('Select entity type id for exporting. By default all bundles will be exported.'),
    '#empty_value' => '',
    '#options' => [],
    '#prefix' => '<div id="edit-entity-bundle-wrapper">',
    '#suffix' => '</div>',
    '#validated' => TRUE,
    '#default_value' => '',
  ];
  $form['settings']['entity_ids'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Entity IDs'),
    '#placeholder' => $this
      ->t('2,10,11'),
    '#description' => $this
      ->t('Exports an entity with the specified IDs.'),
  ];
  $form['settings']['skip_entities'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Skip entity IDs'),
    '#placeholder' => $this
      ->t('3,5,20'),
    '#description' => $this
      ->t('IDs of entity to skip.'),
  ];
  $form['folder'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Folder'),
    '#description' => $this
      ->t('All existing content will be exported to this folder.'),
    '#default_value' => $this->deployManager
      ->getContentFolder(),
    '#states' => [
      'visible' => [
        ':input[name="download"]' => [
          'checked' => FALSE,
        ],
      ],
    ],
  ];
  $form['force_update'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Force update'),
    '#description' => $this
      ->t('All existing content will be overridden (locally updated default content will be reverted to the state defined on the site).'),
    '#default_value' => FALSE,
    '#states' => [
      'visible' => [
        ':input[name="download"]' => [
          'checked' => FALSE,
        ],
      ],
    ],
  ];
  $form['download'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Export to a tar archive'),
    '#description' => $this
      ->t('Download an archive with the content of current settings.'),
    '#default_value' => FALSE,
  ];
  $form['export'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Export content'),
  ];
  return $form;
}