Пример #1
0
 /**
  * {@inheritdoc}
  */
 public function preload(array $entryIds)
 {
     $assets = $this->model->entryId($entryIds)->orderBy('sort_order')->get();
     foreach ($assets as $asset) {
         if (!$asset->filedir_id || !($uploadPref = $this->uploadPrefRepository->find($asset->filedir_id))) {
             if (!is_null($asset->source_id) && $asset->source_settings) {
                 $uploadPref = null;
             } else {
                 continue;
             }
         }
         $asset->setUploadPref($uploadPref);
         if ($asset->content_type === 'matrix' || $asset->content_type === 'grid') {
             if (!isset($this->selections[$asset->content_type][$asset->row_id][$asset->col_id])) {
                 $this->selections[$asset->content_type][$asset->row_id][$asset->col_id] = new AssetCollection();
             }
             $this->selections[$asset->content_type][$asset->row_id][$asset->col_id]->push($asset);
         } else {
             if (!isset($this->selections['entry'][$asset->entry_id][$asset->field_id])) {
                 $this->selections['entry'][$asset->entry_id][$asset->field_id] = new AssetCollection();
             }
             $this->selections['entry'][$asset->entry_id][$asset->field_id]->push($asset);
         }
     }
 }
Пример #2
0
 /**
  * {@inheritdoc}
  */
 public function preload(array $entryIds)
 {
     $query = $this->model->fromEntryCollection($this->collection);
     if (isset($this->hydrators['matrix'])) {
         $query->fromMatrix($this->hydrators['matrix']->getCols(), $this->hydrators['matrix']->getRows());
     }
     if (isset($this->hydrators['grid'])) {
         $query->fromGrid($this->hydrators['grid']->getCols(), $this->hydrators['grid']->getRows());
     }
     $files = $query->get();
     foreach ($files as $file) {
         if (!$file->upload_location_id || !($uploadPref = $this->uploadPrefRepository->find($file->upload_location_id))) {
             continue;
         }
         $file->setUploadPref($uploadPref);
         $this->files['{filedir_' . $file->upload_location_id . '}' . $file->file_name] = $file;
     }
 }
Пример #3
0
 /**
  * Parse a string for these values:
  *
  * {filedir_X}, {assets_X:file_name}, {page_X}
  *
  * @param  string $value WYSIWYG content
  * @return string
  */
 public function parse($value)
 {
     if ($value === null || $value === false || $value === '') {
         return '';
     }
     preg_match_all('#{page_(\\d+)}#', $value, $pageMatches);
     foreach ($pageMatches[1] as $i => $entryId) {
         if ($pageUri = $this->siteRepository->getPageUri($entryId)) {
             $value = str_replace($pageMatches[0][$i], $pageUri, $value);
         }
     }
     preg_match_all('#{filedir_(\\d+)}#', $value, $filedirMatches);
     foreach ($filedirMatches[1] as $i => $id) {
         if ($uploadPref = $this->uploadPrefRepository->find($id)) {
             $value = str_replace($filedirMatches[0][$i], $uploadPref->url, $value);
         }
     }
     // this is all we need to do for now, since we are only supporting Assets locally, not S3 etc.
     preg_match_all('#{assets_\\d+:(.*?)}#', $value, $assetsMatches);
     foreach ($assetsMatches[1] as $i => $url) {
         $value = str_replace($assetsMatches[0][$i], $url, $value);
     }
     return $value;
 }