. */ /* */ /*************************************************************************************/ namespace View\Loop; use Symfony\Component\Finder\Finder; use Symfony\Component\Finder\SplFileInfo; use Thelia\Core\Template\Element\ArraySearchLoopInterface; use Thelia\Core\Template\Element\BaseLoop; use Thelia\Core\Template\Element\LoopResult; use Thelia\Core\Template\Element\LoopResultRow; use Thelia\Core\Template\Loop\Argument\Argument; use Thelia\Core\Template\Loop\Argument\ArgumentCollection; use Thelia\Core\Template\TheliaTemplateHelper; use Thelia\Type; /** * Class Commentaire * @package Commentaire\Loop * @author manuel raynaud */ class Frontfiles extends BaseLoop implements ArraySearchLoopInterface { /** * @return ArgumentCollection */ protected function getArgDefinitions() { return new ArgumentCollection( Argument::createAnyTypeArgument('templates-active') ); } public function buildArray() { try { /** @var TheliaTemplateHelper $templateHelper */ $templateHelper = $this->container->get('thelia.template_helper'); } catch (\Exception $ex) { $templateHelper = TemplateHelper::getInstance(); } $frontTemplatePath = $templateHelper->getActiveFrontTemplate()->getAbsolutePath(); $list = []; $finder = Finder::create() ->files() ->in($frontTemplatePath) // Do not enter in bower and node directories ->exclude(['bower_components', 'node_modules']) // Ignore VCS related directories ->ignoreVCS(true) ->ignoreDotFiles(true) ->sortByName() ->name("*.html"); foreach ($finder as $file) { $list[] = $file; } return $list; } public function parseResults(LoopResult $loopResult) { /** @var SplFileInfo $template */ foreach ($loopResult->getResultDataCollection() as $template) { $loopResultRow = new LoopResultRow($template); $loopResultRow ->set("NAME", str_replace('.html', '', $template->getFilename())) ->set("FILE", $template->getFilename()) ->set("RELATIVE_PATH", $template->getRelativePath()) ->set("ABSOLUTE_PATH", $template->getPath()) ; $loopResult->addRow($loopResultRow); } return $loopResult; } }