/**
  * Append models as database assets to the event collection.
  *
  * @param CollectAssetsEvent $event      The collect event.
  * @param \Model\Collection  $collection The model collection.
  * @param string             $type       The file type.
  *
  * @return void
  */
 protected function appendDatabaseAssets(CollectAssetsEvent $event, \Model\Collection $collection, $type)
 {
     foreach ($collection as $model) {
         $asset = new DatabaseAsset($model->row(), $type, $event->getRenderMode(), $this->asseticFactory, $this->filterRulesFactory);
         $event->append($asset, 100);
     }
 }
 public function collectPageJavaScripts(CollectAssetsEvent $event, $eventName)
 {
     $page = $event->getPage();
     $javaScriptIds = [];
     // add noinherit javascripts from current page
     if ($page->theme_plus_include_javascripts_noinherit) {
         $javaScriptIds = deserialize($page->theme_plus_javascripts_noinherit, true);
     }
     // add inherited javascripts from page trail
     while ($page) {
         if ($page->theme_plus_include_javascripts) {
             $javaScriptIds = array_merge($javaScriptIds, deserialize($page->theme_plus_javascripts, true));
         }
         $page = \PageModel::findByPk($page->pid);
     }
     if (empty($javaScriptIds)) {
         return;
     }
     $columns = ['(' . implode(' OR ', array_fill(0, count($javaScriptIds), 'id=?')) . ')'];
     $values = $javaScriptIds;
     if ($eventName == ThemePlusEvents::COLLECT_BODY_JAVASCRIPT_ASSETS) {
         if ($event->getLayout()->theme_plus_default_javascript_position == 'body') {
             $columns[] = 'position!=?';
             $values[] = 'head';
         } else {
             $columns[] = 'position=?';
             $values[] = 'body';
         }
     } else {
         if ($event->getLayout()->theme_plus_default_javascript_position == 'head') {
             $columns[] = 'position!=?';
             $values[] = 'body';
         } else {
             $columns[] = 'position=?';
             $values[] = 'head';
         }
     }
     $collection = JavaScriptModel::findBy($columns, $values, ['order' => 'sorting']);
     if ($collection) {
         $this->appendDatabaseAssets($event, $collection, 'js');
     }
 }
 public function collectUserStylesheets(CollectAssetsEvent $event, $eventName, EventDispatcherInterface $eventDispatcher)
 {
     if (is_array($GLOBALS['TL_USER_CSS']) && !empty($GLOBALS['TL_USER_CSS'])) {
         foreach ($GLOBALS['TL_USER_CSS'] as $stylesheet) {
             if ($stylesheet instanceof AssetInterface) {
                 $event->append($stylesheet);
             } else {
                 list($source, $media, $mode, $version) = explode('|', $stylesheet);
                 $stripStaticDomainEvent = new StripStaticDomainEvent($event->getRenderMode(), $event->getPage(), $event->getLayout(), $source);
                 $eventDispatcher->dispatch(ThemePlusEvents::STRIP_STATIC_DOMAIN, $stripStaticDomainEvent);
                 $source = $stripStaticDomainEvent->getUrl();
                 $asset = new ExtendedFileAsset(TL_ROOT . '/' . $source, [new CssRewriteFilter()], TL_ROOT, $stylesheet);
                 $asset->setMediaQuery($media);
                 $asset->setStandalone($mode != 'static');
                 $generateAssetPathEvent = new GenerateAssetPathEvent($event->getRenderMode(), $event->getPage(), $event->getLayout(), $asset, $event->getDefaultFilters(), 'css');
                 $eventDispatcher->dispatch(ThemePlusEvents::GENERATE_ASSET_PATH, $generateAssetPathEvent);
                 $asset->setTargetPath($generateAssetPathEvent->getPath());
                 $event->append($asset, 150);
             }
         }
         $GLOBALS['TL_USER_CSS'] = [];
     }
 }