You are here

ExportManager.php in Content Synchronizer 8

Same filename and directory in other branches
  1. 8.2 src/Service/ExportManager.php
  2. 3.x src/Service/ExportManager.php

File

src/Service/ExportManager.php
View source
<?php

namespace Drupal\content_synchronizer\Service;

use Drupal\content_synchronizer\Entity\ExportEntity;
use Drupal\Core\Entity\Entity;

/**
 * The export manager.
 */
class ExportManager {
  const SERVICE_NAME = 'content_synchronizer.export_manager';

  /**
   * Return the list of export checkboxes options.
   *
   * @return array
   *   The export list options.
   */
  public function getExportsListOptions() {
    $exportsOptions = [];

    /** @var \Drupal\content_synchronizer\Entity\ExportEntity $export */
    foreach (ExportEntity::loadMultiple() as $export) {
      $exportsOptions[$export
        ->id()] = $export
        ->label();
    }
    return $exportsOptions;
  }

  /**
   * Return the list of export for an entity.
   *
   * @param \Drupal\Core\Entity\Entity $entity
   *   The entity.
   *
   * @return \Drupal\content_synchronizer\Entity\ExportEntity
   *   THe list of exports.
   */
  public function getEntitiesExport(Entity $entity) {
    if ($result = \Drupal::database()
      ->select(ExportEntity::TABLE_ITEMS)
      ->fields(ExportEntity::TABLE_ITEMS, [
      ExportEntity::FIELD_EXPORT_ID,
    ])
      ->condition(ExportEntity::FIELD_ENTITY_ID, $entity
      ->id())
      ->condition(ExportEntity::FIELD_ENTITY_TYPE, $entity
      ->getEntityTypeId())
      ->execute()) {
      return ExportEntity::loadMultiple($result
        ->fetchCol());
    }
    return [];
  }

  /**
   * Action after delete entity.
   */
  public function onEntityDelete(Entity $entity) {
    foreach ($this
      ->getEntitiesExport($entity) as $export) {
      $export
        ->removeEntity($entity);
    }
  }

}

Classes

Namesort descending Description
ExportManager The export manager.