cache = $tagAwareInterface; $this->environment = $environment; $this->entityManager = $entityManager; // $this->debug = false; } public function invalidate(AGridContent $content){ try { $this->cache->invalidateTags(['agrid_content_' . $content->getId()]); } catch (InvalidArgumentException $e) { } } public function getContent(AGridContent $content, string $lang, string $mode){ // if($this->debug) $this->cache->delete('content_'.$content->getId().'_'.$lang.'_'.$mode); $data = $this->cache->get('content_'.$content->getId().'_'.$lang.'_'.$mode, function (ItemInterface $item) use($content, $lang, $mode){ //region Agrid content $item->tag(['content','agrid_content_'.$content->getId()]); return $this->environment->render('@AGrid/renderer_front/content.front.html.twig',[ 'content'=>$content, 'lang'=>$lang, 'mode'=>$mode ]); //endregion }); return $data; } public function getRow(AGridRow $row, string $lang, string $mode){ // if($this->debug) $this->cache->delete('row_'.$row->getId().'_'.$lang.'_'.$mode); $data = $this->cache->get('row_'.$row->getId().'_'.$lang.'_'.$mode, function (ItemInterface $item) use($row, $lang, $mode){ //region régénère le menu général $item->tag(['row','row_'.$row->getId(), 'agrid_content_'.$row->getParentContainer()->getId()]); return $this->environment->render('@AGrid/renderer_front/row.front.html.twig',[ 'row'=>$row, 'lang'=>$lang, 'mode'=>$mode ]); //endregion }); return $data; } public function getCol(AGridCol $col, string $lang, string $mode){ // if($this->debug) $this->cache->delete('col_'.$col->getId().'_'.$lang.'_'.$mode); $data = $this->cache->get('col_'.$col->getId().'_'.$lang.'_'.$mode, function (ItemInterface $item) use($col, $lang, $mode){ //region régénère le menu général $item->tag(['col','col_'.$col->getId(),'row_'.$col->getParentRow()->getId(), 'agrid_content_'.$col->getParentRow()->getParentContainer()->getId()]); return $this->environment->render('@AGrid/renderer_front/col.front.html.twig',[ 'col'=>$col, 'lang'=>$lang, 'mode'=>$mode ]); //endregion }); return $data; } public function getModules(AGridCol $col, string $lang, string $mode){ $data = ''; $row = $col->getParentRow(); $container = $row->getParentContainer(); $ColModules = $this->entityManager->getRepository(AGridContentColModule::class)->findBy(['aGridContent'=>$container,'aGridCol'=>$col]); foreach ($ColModules as $ColModule){ $module = $ColModule->getAGridModule(); if(null != $module && $module->getParameter('twig') ?? ''){ $data .= $this->cache->get('module_'.$module->getId().'_col_'.$col->getId().'_'.$lang.'_'.$mode, function (ItemInterface $item) use($module,$col, $lang, $mode, $container){ //region régénère le menu général $item->tag(['module','module_'.$module->getId(),'col_'.$col->getId(),'row_'.$col->getParentRow()->getId(), 'agrid_content_'.$container->getId()]); return $this->environment->render($module->getParameter('twig'), [ 'lang'=>$lang, 'mode'=>$mode, 'module' => $module ]); //endregion }); } } return $data; } }