You are here

class MediaFeedsLibraryProvider in Media Feeds 7

Same name and namespace in other branches
  1. 7.2 includes/MediaFeedsLibraryProvider.inc \MediaFeedsLibraryProvider

Class for mapping values using existing files from the media library.

Hierarchy

Expanded class hierarchy of MediaFeedsLibraryProvider

File

includes/MediaFeedsLibraryProvider.inc, line 11
Map existing files from the library.

View source
class MediaFeedsLibraryProvider extends MediaFeedsProvider {
  protected $file;
  public function __construct($value, $config = array()) {

    // Query existing files.
    $query = new EntityFieldQuery();
    $query
      ->entityCondition('entity_type', 'file');

    // By exact match or without file extension.
    if (empty($config['no_file_extensions'])) {
      $query
        ->propertyCondition('filename', $value);
    }
    else {
      $query
        ->propertyCondition('filename', $value . '.', 'STARTS_WITH');
    }

    // Get the result.
    $result = $query
      ->execute();
    if (!empty($result)) {
      $this->file = reset(file_load_multiple(array_keys($result['file'])));
    }
  }
  public function getFileObject() {
    return $this->file;
  }
  public function save() {
    return $this->file;
  }
  public static function summaryCallback($mapping, $target, $form, $form_state) {
    if (empty($mapping['no_file_extensions'])) {
      return t('Source is <strong>exactly</strong> the filename');
    }
    else {
      return t('Source <strong>doesn\'t have file extensions</strong>');
    }
  }
  public static function formCallback($mapping, $target, $form, $form_state) {
    return array(
      'no_file_extensions' => array(
        '#type' => 'checkbox',
        '#title' => t('Source has no file extensions'),
        '#default_value' => !empty($mapping['no_file_extensions']),
      ),
    );
  }

}

Members

Namesort descending Modifiers Type Description Overrides
MediaFeedsLibraryProvider::$file protected property
MediaFeedsLibraryProvider::formCallback public static function
MediaFeedsLibraryProvider::getFileObject public function Create a file object from the source value. Overrides MediaFeedsProvider::getFileObject
MediaFeedsLibraryProvider::save public function Save the file in the database. Overrides MediaFeedsProvider::save
MediaFeedsLibraryProvider::summaryCallback public static function
MediaFeedsLibraryProvider::__construct public function Constructor of MediaFeedsProvider. Overrides MediaFeedsProvider::__construct
MediaFeedsProvider::$config protected property An associative array of configuration options.
MediaFeedsProvider::$entity protected property The target entity.
MediaFeedsProvider::$source protected property The FeedsSource.
MediaFeedsProvider::$target protected property The target name.
MediaFeedsProvider::$value protected property The values to save.
MediaFeedsProvider::validate public function Validate the source value. 1