You are here

protected function EntityExportFormBuilder::initExportForm in Content Synchronizer 8

Same name and namespace in other branches
  1. 8.2 src/Service/EntityExportFormBuilder.php \Drupal\content_synchronizer\Service\EntityExportFormBuilder::initExportForm()
  2. 3.x src/Service/EntityExportFormBuilder.php \Drupal\content_synchronizer\Service\EntityExportFormBuilder::initExportForm()

Init the export form.

1 call to EntityExportFormBuilder::initExportForm()
EntityExportFormBuilder::addExportFieldsToEntityForm in src/Service/EntityExportFormBuilder.php
Add exports fields to the entity form.

File

src/Service/EntityExportFormBuilder.php, line 86

Class

EntityExportFormBuilder
The entity export form builder.

Namespace

Drupal\content_synchronizer\Service

Code

protected function initExportForm(EntityInterface $entity, array &$form, FormStateInterface $formState, $isBundle = FALSE) {

  /** @var ExportManager $exportManager */
  $exportManager = \Drupal::service(ExportManager::SERVICE_NAME);
  $form['content_synchronizer'] = [
    '#type' => 'details',
    '#title' => $isBundle ? t('Export all entities of @bundle bundle', [
      '@bundle' => $entity
        ->label(),
    ]) : t('Export'),
    '#group' => 'advanced',
    '#weight' => '100',
  ];

  // Init labels.
  $quickExportButton = $isBundle ? t('Export entities') : t('Export entity');
  $addToExportButton = $isBundle ? t('Or add the entities to an existing export') : t('Or add the entity to an existing export');
  $form['content_synchronizer']['quick_export'] = [
    '#markup' => '<a href="' . $this
      ->getQuickExportUrl($entity) . '" class="button button--primary">' . $quickExportButton . '</a>',
  ];
  $exportsListOptions = $exportManager
    ->getExportsListOptions();
  if (!empty($exportsListOptions)) {
    $form['content_synchronizer']['exports_list'] = [
      '#type' => 'checkboxes',
      '#title' => $addToExportButton,
      '#options' => $exportsListOptions,
      '#default_value' => array_keys($exportManager
        ->getEntitiesExport($entity)),
    ];
    $form['content_synchronizer']['add_to_export'] = [
      '#type' => 'submit',
      '#value' => t('Add to the choosen export'),
      '#submit' => [
        get_called_class() . '::onAddToExport',
      ],
    ];
  }
}