You are here

class EntityShareMediasScaldExport in Entity Share 7

Class for scald atoms export.

Hierarchy

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;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
EntityShareMediasAbstract::$entity protected property Entity object.
EntityShareMediasAbstract::$fieldData protected property Field data.
EntityShareMediasAbstract::$fieldInfo protected property Metadatas of the field.
EntityShareMediasAbstract::$fieldName protected property Name of the field.
EntityShareMediasAbstract::$fieldType protected property Type of the field.
EntityShareMediasAbstract::__construct public function Constructor. Initialize properties.
EntityShareMediasProviderAbstract::$rteKeys protected property Values to treat for embedded RTE.
EntityShareMediasProviderAbstract::createFile protected function Create the file.
EntityShareMediasProviderAbstract::getRelativePathFromUrl protected function Get the relative drupal stream path from a full drupal URL.
EntityShareMediasProviderAbstract::isManagedFieldType public function Check if the field type is managed. Overrides EntityShareMediasProviderInterface::isManagedFieldType
EntityShareMediasProviderAbstract::isRteField protected function Check if RTE Field.
EntityShareMediasProviderAbstract::rteEmbeddedMedia protected function Treatment on the RTE field to match fid, etc.
EntityShareMediasProviderAbstract::WATCHDOG_TYPE constant 2
EntityShareMediasScaldAbstract::$managedFieldTypes protected property Types of field handled by the current class. Overrides EntityShareMediasProviderAbstract::$managedFieldTypes
EntityShareMediasScaldAbstract::CUSTOM_UUID_PREFIX constant
EntityShareMediasScaldAbstract::getScaldAtomFromProvider protected function Get the scald atom from provider and base id.
EntityShareMediasScaldAbstract::getScaldIdFromBaseEntityUuid public function Get the scald atom id from base entity uuid.
EntityShareMediasScaldAbstract::getScaldIdFromUuid public function Get a scald Id from a UUID.
EntityShareMediasScaldAbstract::getUniqueIdFromAtom public function Generate manually a uuid from a scald atom.
EntityShareMediasScaldAbstract::isCustomUuid public function Is custom UUID.
EntityShareMediasScaldExport::exportMedias public function Export the medias of the provider. Overrides EntityShareMediasExportInterface::exportMedias
EntityShareMediasScaldExport::fieldManagement protected function Manage field media reference content. Overrides EntityShareMediasProviderAbstract::fieldManagement
EntityShareMediasScaldExport::generateExportRteMediaString protected function Generate the export string for the scald atom.
EntityShareMediasScaldExport::getExportRteFieldCallback protected function Generate the callback to treat the scald content from the field data.
EntityShareMediasScaldExport::loadScaldAtom protected function Load Scald Atom.
EntityShareMediasScaldExport::rteManagement protected function Alter RTE datas. Overrides EntityShareMediasProviderAbstract::rteManagement