You are here

class FileProcessor in Content Synchronizer 8

Same name and namespace in other branches
  1. 8.2 src/Plugin/content_synchronizer/entity_processor/FileProcessor.php \Drupal\content_synchronizer\Plugin\content_synchronizer\entity_processor\FileProcessor
  2. 3.x src/Plugin/content_synchronizer/entity_processor/FileProcessor.php \Drupal\content_synchronizer\Plugin\content_synchronizer\entity_processor\FileProcessor

Plugin implementation of the 'accordion' formatter.

Plugin annotation


@EntityProcessor(
  id = "content_synchronizer_file_processor",
  entityType = "file"
)

Hierarchy

Expanded class hierarchy of FileProcessor

File

src/Plugin/content_synchronizer/entity_processor/FileProcessor.php, line 21

Namespace

Drupal\content_synchronizer\Plugin\content_synchronizer\entity_processor
View source
class FileProcessor extends EntityProcessorBase implements EntityProcessorInterface {
  use JsonWriterTrait;
  const DIR_ASSETS = "assets";
  protected $exportAssetsDirPath;
  protected $importAssetsDirPath;

  /**
   * Return the data to export.
   */
  public function getDataToExport(Entity $entityToExport) {
    $this
      ->addFileToAssets($entityToExport);
    return parent::getDataToExport($entityToExport);
  }

  /**
   * Add file to assets dir.
   */
  protected function addFileToAssets(File $file) {
    $assetsDir = $this
      ->getExportAssetsDir();
    $destination = $this
      ->createDirTreeForFileDest(str_replace('://', '/', $file
      ->getFileUri()), $assetsDir);

    // Copy file in destination directory.
    file_copy($file, $destination);
  }

  /**
   * Return the export assets path.
   */
  protected function getExportAssetsDir() {
    if (!$this->exportAssetsDirPath) {
      $writer = ExportProcessor::getCurrentExportProcessor()
        ->getWriter();
      $this->exportAssetsDirPath = $writer
        ->getDirPath() . '/' . self::DIR_ASSETS;
      $this
        ->createDirectory($this->exportAssetsDirPath);
    }
    return $this->exportAssetsDirPath;
  }

  /**
   * Return the import assets path.
   */
  protected function getImportAssetsDir() {
    if (!$this->importAssetsDirPath) {
      $this->importAssetsDirPath = ImportProcessor::getCurrentImportProcessor()
        ->getImport()
        ->getArchiveFilesPath() . '/' . self::DIR_ASSETS;
    }
    return $this->importAssetsDirPath;
  }

  /**
   * Return the entity to import.
   *
   * @param array $data
   *   The data to import.
   * @param \Drupal\Core\Entity\Entity|null $entityToImport
   *   The entity to import.
   *
   * @return \Drupal\Core\Entity\Entity|\Drupal\Core\Entity\Entity\null|\Drupal\Core\Entity\EntityInterface
   *   The entity to import.
   */
  public function getEntityToImport(array $data, Entity $entityToImport = NULL) {
    if ($file = parent::getEntityToImport($data, $entityToImport)) {
      $assetsFile = $this
        ->getImportAssetsDir() . '/' . str_replace('://', '/', $file
        ->getFileUri());
      if (file_exists($assetsFile)) {
        if (strpos($file
          ->getFileUri(), '://')) {
          list($root, $destination) = explode('://', $file
            ->getFileUri());
          $root .= '://';
        }
        else {
          list($root, $destination) = [
            $file
              ->getFileUri(),
            '/',
          ];
        }
        $destination = $this
          ->createDirTreeForFileDest($destination, $root);
        if ($result = copy($assetsFile, $file
          ->getFileUri())) {
          return $file;
        }
      }
    }
    return NULL;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function 1
DependencySerializationTrait::__wakeup public function 2
EntityProcessorBase::$entityProcessorManager protected property The entity processor manager service.
EntityProcessorBase::$entityPublisher protected property The entity publisher service.
EntityProcessorBase::$entityType protected property The current entity type.
EntityProcessorBase::$globalReferenceManager protected property The global reference manager service.
EntityProcessorBase::$propertyIdsNotToExport protected property
EntityProcessorBase::$typeProcessorManager protected property The type processor manager service.
EntityProcessorBase::checkBundle private function Check if entity's bundle exist, create-it
EntityProcessorBase::createBundle private function Create missing Bundle
EntityProcessorBase::createNewTranslation protected function Return a translation.
EntityProcessorBase::export final public function Export the entity and return the gid if exists, else false.
EntityProcessorBase::EXPORT_HOOK constant
EntityProcessorBase::getDefaultLanguageData public function Return the data of the default language of the passed data.
EntityProcessorBase::getEntityGlobalReference protected function Get the global reference entity.
EntityProcessorBase::getEntityProcessorManager protected function Get the EntityProcessor plugin manager.
EntityProcessorBase::getEntityPublisher public function Return the entity saver service.
EntityProcessorBase::getEntityTranslations protected function Return the entity translations.
EntityProcessorBase::getEntityType public function Return the current entity type.
EntityProcessorBase::getGlobalReferenceManager final protected function Get the contentSyncManager.
EntityProcessorBase::getPropertiesIdsNotToExportList public function Get the array of the property of the entity not to export. Overrides EntityProcessorInterface::getPropertiesIdsNotToExportList
EntityProcessorBase::getTypeProcessorManager protected function Get the TypeProcessor plugin manager.
EntityProcessorBase::import final public function Create or update entity with data :.
EntityProcessorBase::IMPORT_HOOK constant
EntityProcessorBase::KEY_TRANSLATIONS constant
EntityProcessorBase::onEntityImported protected function Callback when the entity has been imported.
EntityProcessorBase::setChangedTime protected function Update the changed time form the data array.
EntityProcessorBase::setEntityType public function Set the current entity type.
FileProcessor::$exportAssetsDirPath protected property
FileProcessor::$importAssetsDirPath protected property
FileProcessor::addFileToAssets protected function Add file to assets dir.
FileProcessor::DIR_ASSETS constant
FileProcessor::getDataToExport public function Return the data to export. Overrides EntityProcessorBase::getDataToExport
FileProcessor::getEntityToImport public function Return the entity to import. Overrides EntityProcessorBase::getEntityToImport
FileProcessor::getExportAssetsDir protected function Return the export assets path.
FileProcessor::getImportAssetsDir protected function Return the import assets path.
JsonWriterTrait::createDirectory protected function Create a directory if not exists.
JsonWriterTrait::createDirTreeForFileDest protected function Create a directory tree.
JsonWriterTrait::getDataFromFile protected function Get json decode data from a file.
JsonWriterTrait::writeJson protected function Save json in the destination file.
MessengerTrait::$messenger protected property The messenger. 29
MessengerTrait::messenger public function Gets the messenger. 29
MessengerTrait::setMessenger public function Sets the messenger.
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin_id.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 3
PluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable public function Determines if the plugin is configurable.
PluginBase::__construct public function Constructs a \Drupal\Component\Plugin\PluginBase object. 92
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.