You are here

class EntityShareMedias in Entity Share 7

Class EntityShareMedias.

Hierarchy

Expanded class hierarchy of EntityShareMedias

File

modules/entity_share_medias/includes/entity_share_medias.inc, line 288
Class for handling Medias.

View source
class EntityShareMedias extends EntityShareMediasAbstract {
  const WATCHDOG_TYPE = 'entity_share_medias';
  const HOOK_PREFIX = 'es_medias_';

  /**
   * Configuration of the medias to manage.
   *
   * @var array
   *   Class configuration of the medias to handle.
   */
  protected $mediaTypesConfig = array();

  /**
   * Get the Media Types Configuration.
   *
   * @return array
   *   Class configuration of the medias to handle.
   */
  public function getMediaTypesConfig() {

    // Alter the media types configurations.
    drupal_alter(self::HOOK_PREFIX . 'media_types_config', $this->mediaTypesConfig);
    return $this->mediaTypesConfig;
  }

  /**
   * Export the medias of the providers.
   */
  public function exportMedias() {
    foreach ($this
      ->getMediaTypesConfig() as $type => $config) {
      $class = $config['export'];
      $provider = new $class($this->fieldData, $this->fieldName, $this->fieldType, $this->entity, $this->fieldInfo);
      if (!$provider instanceof EntityShareMediasExportInterface) {
        watchdog(self::WATCHDOG_TYPE, 'The media type %type class must implement EntityShareMediasProviderInterface interface !', array(
          '%type' => $type,
        ), WATCHDOG_WARNING);
        continue;
      }
      if ($provider
        ->isManagedFieldType()) {
        $provider
          ->exportMedias();
      }
    }
  }

  /**
   * Import the medias of the providers.
   */
  public function importMedias() {
    foreach ($this
      ->getMediaTypesConfig() as $type => $config) {
      $class = $config['import'];
      $provider = new $class($this->fieldData, $this->fieldName, $this->fieldType, $this->entity, $this->fieldInfo);
      if (!$provider instanceof EntityShareMediasImportInterface) {
        watchdog(self::WATCHDOG_TYPE, 'The media type %type class must implement EntityShareMediasProviderInterface interface !', array(
          '%type' => $type,
        ), WATCHDOG_WARNING);
        continue;
      }
      if ($provider
        ->isManagedFieldType()) {
        $provider
          ->importMedias();
      }
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
EntityShareMedias::$mediaTypesConfig protected property Configuration of the medias to manage.
EntityShareMedias::exportMedias public function Export the medias of the providers.
EntityShareMedias::getMediaTypesConfig public function Get the Media Types Configuration.
EntityShareMedias::HOOK_PREFIX constant
EntityShareMedias::importMedias public function Import the medias of the providers.
EntityShareMedias::WATCHDOG_TYPE constant
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.