You are here

abstract class EntityShareMediasScaldAbstract in Entity Share 7

Abstract Class to manage scald atoms.

Hierarchy

Expanded class hierarchy of EntityShareMediasScaldAbstract

File

modules/entity_share_medias/modules/entity_share_medias_scald/includes/entity_share_medias_scald.abstract.inc, line 11
Class for handling scald Medias in RTE.

View source
abstract class EntityShareMediasScaldAbstract extends EntityShareMediasProviderAbstract {
  const CUSTOM_UUID_PREFIX = 'entity_share-';

  /**
   * Types of field handled by the current class.
   *
   * @var array
   *   Type of field types managed.
   */
  protected $managedFieldTypes = array(
    'text',
    'text_long',
    'text_with_summary',
    'atom_reference',
  );

  /**
   * Get a scald Id from a UUID.
   *
   * @param string $uuid
   *   UUID of the Scald atom.
   *
   * @return mixed
   *   ScaldId or FALSE.
   */
  public function getScaldIdFromUuid($uuid) {
    if ($this
      ->isCustomUuid($uuid)) {
      list(, $provider, $base_id, ) = explode('-', $uuid);
      $sid = $this
        ->getScaldAtomFromProvider($provider, $base_id);
    }
    else {
      $sid = $this
        ->getScaldIdFromBaseEntityUuid($uuid);
    }
    return $sid;
  }

  /**
   * Is custom UUID.
   *
   * @param string $uuid
   *   UUID of the Scald atom.
   *
   * @return bool
   *   TRUE if custom UUID, FALSE otherwise.
   */
  public function isCustomUuid($uuid) {
    return substr($uuid, 0, strlen(self::CUSTOM_UUID_PREFIX)) == self::CUSTOM_UUID_PREFIX;
  }

  /**
   * Generate manually a uuid from a scald atom.
   *
   * Use uuid if exists in base_entity, generate a custom "uuid" otherwise.
   *
   * @param object $atom
   *   Scald atom.
   *
   * @return string
   *   Scald UUID.
   */
  public function getUniqueIdFromAtom($atom) {
    $uuid = NULL;
    if (empty($atom->base_entity)) {
      $uuid = self::CUSTOM_UUID_PREFIX . $atom->provider . '-' . $atom->base_id . '-' . $atom->language;
    }
    else {
      if (isset($atom->base_entity->uuid)) {
        $uuid = $atom->base_entity->uuid;
      }
      elseif (isset($atom->base_entity['uuid'])) {
        $uuid = $atom->base_entity['uuid'];
      }
    }
    return $uuid;
  }

  /**
   * Get the scald atom from provider and base id.
   *
   * @param string $provider
   *   The scald provider.
   * @param string $base_id
   *   The base id of the scald atom.
   *
   * @return mixed
   *   FALSE if the atom was never imported, the scald identifier of
   *   the atom otherwise.
   */
  protected function getScaldAtomFromProvider($provider, $base_id) {
    $query = array(
      'provider' => $provider,
      'base_id' => $base_id,
    );
    return scald_search($query, FALSE, TRUE);
  }

  /**
   * Get the scald atom id from base entity uuid.
   *
   * @param string $uuid
   *   Entity uuid.
   *
   * @return int
   *   ScaldId.
   */
  public function getScaldIdFromBaseEntityUuid($uuid) {
    $query = db_select('scald_atoms', 's');
    $query
      ->join('file_usage', 'fu', "fu.type='scald_atom' AND fu.id=s.sid");
    $query
      ->join('file_managed', 'fm', 'fm.fid=fu.fid');
    $result = $query
      ->condition('fm.uuid', $uuid)
      ->fields('s', array(
      'sid',
    ))
      ->execute()
      ->fetchAssoc();
    return $result['sid'];
  }

}

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::fieldManagement abstract protected function Manage field media reference content. 4
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::rteManagement abstract protected function Manage RTE content. 4
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.