class FileProcessor in Content Synchronizer 3.x
Same name and namespace in other branches
- 8.2 src/Plugin/content_synchronizer/entity_processor/FileProcessor.php \Drupal\content_synchronizer\Plugin\content_synchronizer\entity_processor\FileProcessor
- 8 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
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\content_synchronizer\Processors\Entity\EntityProcessorBase implements EntityProcessorInterface
- class \Drupal\content_synchronizer\Plugin\content_synchronizer\entity_processor\FileProcessor implements EntityProcessorInterface uses JsonWriterTrait
- class \Drupal\content_synchronizer\Processors\Entity\EntityProcessorBase implements EntityProcessorInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of FileProcessor
File
- src/
Plugin/ content_synchronizer/ entity_processor/ FileProcessor.php, line 21
Namespace
Drupal\content_synchronizer\Plugin\content_synchronizer\entity_processorView source
class FileProcessor extends EntityProcessorBase implements EntityProcessorInterface {
use JsonWriterTrait;
const DIR_ASSETS = "assets";
/**
* Export assets directory path.
*
* @var string
*/
protected $exportAssetsDirPath;
/**
* Import assets directory path.
*
* @var string
*/
protected $importAssetsDirPath;
/**
* Return the data to export.
*/
public function getDataToExport(EntityInterface $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\EntityInterface|null $entityToImport
* The entity to import.
*
* @return \Drupal\Core\Entity\EntityInterface|null
* The entity to import.
*/
public function getEntityToImport(array $data, EntityInterface $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(),
'/',
];
}
$this
->createDirTreeForFileDest($destination, $root);
$result = copy($assetsFile, $file
->getFileUri());
if ($result) {
return $file;
}
}
}
return NULL;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
public | function | 2 | |
DependencySerializationTrait:: |
public | function | 2 | |
EntityProcessorBase:: |
protected | property | The entity processor manager service. | |
EntityProcessorBase:: |
protected | property | The entity publisher service. | |
EntityProcessorBase:: |
protected | property | The current entity type. | |
EntityProcessorBase:: |
protected | property | The global reference manager service. | |
EntityProcessorBase:: |
protected | property | Ids not to export. | |
EntityProcessorBase:: |
protected | property | The type processor manager service. | |
EntityProcessorBase:: |
public | function | Return if the entity can be exported. | |
EntityProcessorBase:: |
private | function | Check if entity's bundle exist, create-it. | |
EntityProcessorBase:: |
private | function | Create missing Bundle. | |
EntityProcessorBase:: |
protected | function | Return a translation. | |
EntityProcessorBase:: |
final public | function | Export the entity and return the gid if exists, else false. | |
EntityProcessorBase:: |
constant | |||
EntityProcessorBase:: |
public | function | Return the data of the default language of the passed data. | |
EntityProcessorBase:: |
protected | function | Get the global reference entity. | |
EntityProcessorBase:: |
protected | function | Get the EntityProcessor plugin manager. | |
EntityProcessorBase:: |
public | function | Return the entity saver service. | |
EntityProcessorBase:: |
protected | function | Return the entity translations. | |
EntityProcessorBase:: |
public | function | Return the current entity type. | |
EntityProcessorBase:: |
final protected | function | Get the contentSyncManager. | |
EntityProcessorBase:: |
public | function |
Get the array of the property of the entity not to export. Overrides EntityProcessorInterface:: |
|
EntityProcessorBase:: |
protected | function | Get the TypeProcessor plugin manager. | |
EntityProcessorBase:: |
final public | function | Create or update entity with data :. | |
EntityProcessorBase:: |
constant | |||
EntityProcessorBase:: |
constant | |||
EntityProcessorBase:: |
protected | function | Callback when the entity has been imported. | |
EntityProcessorBase:: |
protected | function | Update the changed time form the data array. | |
EntityProcessorBase:: |
public | function | Set the current entity type. | |
FileProcessor:: |
protected | property | Export assets directory path. | |
FileProcessor:: |
protected | property | Import assets directory path. | |
FileProcessor:: |
protected | function | Add file to assets dir. | |
FileProcessor:: |
constant | |||
FileProcessor:: |
public | function |
Return the data to export. Overrides EntityProcessorBase:: |
|
FileProcessor:: |
public | function |
Return the entity to import. Overrides EntityProcessorBase:: |
|
FileProcessor:: |
protected | function | Return the export assets path. | |
FileProcessor:: |
protected | function | Return the import assets path. | |
JsonWriterTrait:: |
protected | property | File System. | |
JsonWriterTrait:: |
protected | function | Create a directory if not exists. | |
JsonWriterTrait:: |
protected | function | Create a directory tree. | |
JsonWriterTrait:: |
public | function | Return file system. | |
JsonWriterTrait:: |
protected | function | Get json decode data from a file. | |
JsonWriterTrait:: |
protected | function | Save json in the destination file. | |
MessengerTrait:: |
protected | property | The messenger. | 27 |
MessengerTrait:: |
public | function | Gets the messenger. | 27 |
MessengerTrait:: |
public | function | Sets the messenger. | |
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
2 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
PluginBase:: |
public | function | Constructs a \Drupal\Component\Plugin\PluginBase object. | 98 |
StringTranslationTrait:: |
protected | property | The string translation service. | 4 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |