You are here

public static function EntityExportFormBuilder::onAddToExport in Content Synchronizer 8

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

Add entity to an existing entity export.

Parameters

array $form: The form build array.

\Drupal\Core\Form\FormStateInterface $formState: The form state.

File

src/Service/EntityExportFormBuilder.php, line 150

Class

EntityExportFormBuilder
The entity export form builder.

Namespace

Drupal\content_synchronizer\Service

Code

public static function onAddToExport(array &$form, FormStateInterface $formState) {
  $exportsList = ExportEntity::loadMultiple($formState
    ->getValue('exports_list'));
  $entity = $formState
    ->getFormObject()
    ->getEntity();
  if ($entity instanceof ConfigEntityBundleBase) {
    if ($entitiesToExport = self::getEntitiesFromBundle($entity)) {

      /** @var \Drupal\content_synchronizer\Entity\ExportEntity $export */
      foreach (ExportEntity::loadMultiple() as $export) {
        foreach ($entitiesToExport as $entityToExport) {
          if (array_key_exists($export
            ->id(), $exportsList)) {
            $export
              ->addEntity($entityToExport);
          }
        }
      }
    }
  }
  else {

    /** @var \Drupal\content_synchronizer\Entity\ExportEntity $export */
    foreach (ExportEntity::loadMultiple() as $export) {
      if (array_key_exists($export
        ->id(), $exportsList)) {
        $export
          ->addEntity($entity);
      }
      else {
        $export
          ->removeEntity($entity);
      }
    }
  }
}