/**
  * Fetch correct thumbnail according to type (medium or large)
  *
  * @param Record|Story $record Record for which to fetch the thumbnail
  * @param string $type Size of the thumbnail
  * @return null|\PhraseanetSDK\Entity\Subdef
  * @throws \InvalidArgumentException
  */
 public function fetch($record, $type)
 {
     if (!$record instanceof Record && !$record instanceof Story) {
         throw new \InvalidArgumentException();
     }
     if (!$this->thumbnailMap->hasSubDefinition($type) || $record instanceof Story) {
         return $record->getThumbnail();
     }
     $subdefinition = $this->thumbnailMap->getSubDefinition($type);
     if ($record->getSubdefs()->containsKey($subdefinition)) {
         return $record->getSubdefs()->get($subdefinition);
     }
     return $record->getThumbnail();
 }
 public function subdefs(Record $record, array $names, $prefix = null)
 {
     $defsByName = array();
     $subdefs = array();
     foreach ($record->getSubdefs() as $subdef) {
         $defsByName[$subdef->getName()] = $subdef;
     }
     foreach ($names as $name) {
         $fullName = $prefix ? $prefix . '_' . $name : $name;
         if (!isset($this->subdefsMap[$fullName])) {
             throw new \RuntimeException('Subdef "' . $fullName . '" is not configured.');
         }
         $defName = $this->subdefsMap[$fullName];
         if (isset($defsByName[$defName])) {
             $subdefs[$name] = $defsByName[$defName];
         }
     }
     return $subdefs;
 }