You are here

class ExportManager in Content Synchronizer 8

Same name and namespace in other branches
  1. 8.2 src/Service/ExportManager.php \Drupal\content_synchronizer\Service\ExportManager
  2. 3.x src/Service/ExportManager.php \Drupal\content_synchronizer\Service\ExportManager

The export manager.

Hierarchy

Expanded class hierarchy of ExportManager

3 files declare their use of ExportManager
content_synchronizer.module in ./content_synchronizer.module
Hooks definitions for content_synchronizer module.
ExportAction.php in src/Plugin/Action/ExportAction.php
ExportConfirmForm.php in src/Form/ExportConfirmForm.php
1 string reference to 'ExportManager'
content_synchronizer.services.yml in ./content_synchronizer.services.yml
content_synchronizer.services.yml
1 service uses ExportManager
content_synchronizer.export_manager in ./content_synchronizer.services.yml
\Drupal\content_synchronizer\Service\ExportManager

File

src/Service/ExportManager.php, line 11

Namespace

Drupal\content_synchronizer\Service
View source
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);
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ExportManager::getEntitiesExport public function Return the list of export for an entity.
ExportManager::getExportsListOptions public function Return the list of export checkboxes options.
ExportManager::onEntityDelete public function Action after delete entity.
ExportManager::SERVICE_NAME constant