class EntityShareMediasScaldExport in Entity Share 7
Class for scald atoms export.
Hierarchy
- class \EntityShareMediasAbstract
- class \EntityShareMediasProviderAbstract implements EntityShareMediasProviderInterface
- class \EntityShareMediasScaldAbstract
- class \EntityShareMediasScaldExport implements EntityShareMediasExportInterface
- class \EntityShareMediasScaldAbstract
- class \EntityShareMediasProviderAbstract implements EntityShareMediasProviderInterface
Expanded class hierarchy of EntityShareMediasScaldExport
1 string reference to 'EntityShareMediasScaldExport'
- entity_share_medias_scald_es_medias_media_types_config_alter in modules/
entity_share_medias/ modules/ entity_share_medias_scald/ entity_share_medias_scald.module - Implements hook_entity_share_medias_scald_es_medias_types_config_alter().
File
- modules/
entity_share_medias/ modules/ entity_share_medias_scald/ includes/ entity_share_medias_scald.export.inc, line 11 - Class for handling scald Medias Export.
View source
class EntityShareMediasScaldExport extends EntityShareMediasScaldAbstract implements EntityShareMediasExportInterface {
/**
* Load Scald Atom.
*
* @param int $sid
* ScaldID.
*
* @return object
* Scald atom.
*/
protected function loadScaldAtom($sid) {
$scald_atom = scald_atom_load($sid);
// Add entity_share property to the entity.
$this->entity->entity_share->scald_atoms[$sid] = $scald_atom;
return $scald_atom;
}
/**
* Export the medias of the provider.
*/
public function exportMedias() {
// Alter the field_data.
if ($this
->isRteField()) {
$this
->rteManagement();
}
else {
$this
->fieldManagement();
}
}
/**
* Alter RTE datas.
*/
protected function rteManagement() {
$this
->rteEmbeddedMedia($this->fieldData, $this
->getExportRteFieldCallback(), '/\\[scald=([0-9]+):([^\\s]+)?(.*?)]/');
}
/**
* Manage field media reference content.
*/
protected function fieldManagement() {
if (is_object($this->fieldData)) {
$this->fieldData = (array) $this->fieldData;
}
$sid = $this->fieldData['sid'];
if (!empty($sid)) {
$scald_atom = $this
->loadScaldAtom($sid);
if (!empty($scald_atom->base_entity)) {
// Add the file url in a property of the scald object.
$scald_atom->file_url = file_create_url($scald_atom->base_entity->uri);
}
$this->fieldData = $scald_atom;
}
}
/**
* Generate the callback to treat the scald content from the field data.
*
* @return callable
* The callback to treat RTE.
*/
protected function getExportRteFieldCallback() {
$instance = $this;
return function ($matches, &$field_value) use ($instance) {
foreach ($matches as $match) {
$full_pattern_match = $match[0];
$sid = $match[1];
$context = $match[2];
$infos = $match[3];
// Replace sid per file uuid (alter the original field_value,
// be careful with all references).
$field_value = str_replace($full_pattern_match, $instance
->generateExportRteMediaString($sid, $context, $infos), $field_value);
}
};
}
/**
* Generate the export string for the scald atom.
*
* @param int $sid
* Scald atom id.
* @param string $context
* Scald context.
* @param string $infos
* Scald additional information.
*
* @return string
* The export string.
*/
protected function generateExportRteMediaString($sid, $context, $infos) {
// Load scald atom.
$scald_atom = $this
->loadScaldAtom($sid);
// Uuid.
$uuid = $this
->getUniqueIdFromAtom($scald_atom);
// Add the file url in a dimension of the object.
$file_url = '';
if (!empty($scald_atom->base_entity)) {
$file_url = file_create_url($scald_atom->base_entity->uri);
}
return <<<EXPORT
[scald={<span class="php-variable">$uuid</span>}:{<span class="php-variable">$context</span>} url={<span class="php-variable">$file_url</span>} orisid={<span class="php-variable">$sid</span>} entity_share=1 {<span class="php-variable">$infos</span>}]
EXPORT;
}
}