You are here

protected function EntityExportFormBuilder::initExportForm in Content Synchronizer 3.x

Same name and namespace in other branches
  1. 8.2 src/Service/EntityExportFormBuilder.php \Drupal\content_synchronizer\Service\EntityExportFormBuilder::initExportForm()
  2. 8 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 136

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 ? $this
      ->t('Export all entities of @bundle bundle', [
      '@bundle' => $entity
        ->label(),
    ]) : $this
      ->t('Export'),
    '#group' => 'advanced',
    '#weight' => '100',
  ];

  // Init labels.
  $quickExportButton = $isBundle ? $this
    ->t('Export entities') : $this
    ->t('Export entity');
  $addToExportButton = $isBundle ? $this
    ->t('Or add the entities to an existing export') : $this
    ->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' => $this
        ->t('Add to the export'),
      '#submit' => [
        get_called_class() . '::onAddToExport',
      ],
    ];
  }
}