<?php
namespace Kobizo\Bundle\CmsBundle\Controller\ViewHelper;
use Kobizo\Bundle\CmsBundle\Controller\ViewHelper\Checker\ViewChecker;
use Kobizo\Component\Configuration\Frontend\TemplateConfig;
abstract class BaseViewHelper
{
private TemplateConfig $templateConfig;
private ViewChecker $viewChecker;
public function __construct(TemplateConfig $templateConfig, ViewChecker $viewChecker)
{
$this->templateConfig = $templateConfig;
$this->viewChecker = $viewChecker;
}
protected function getViewByTemplate(string $view, ?string $template = null): string
{
$viewByApp = str_replace('@KobizoCms/frontend', $this->templateConfig->getValue(null, true), $view);
$viewBySlug = $template ? str_replace('twig', "$template.twig", $viewByApp) : null;
if ($viewBySlug && $this->viewChecker->exists($viewBySlug)) {
return $viewBySlug;
}
if ($this->viewChecker->exists($viewByApp)) {
return $viewByApp;
}
return $view;
}
}