AbstractFragmentController.php (contao-4.9.11) | : | AbstractFragmentController.php (contao-4.9.12) | ||
---|---|---|---|---|
skipping to change at line 16 | skipping to change at line 16 | |||
* This file is part of Contao. | * This file is part of Contao. | |||
* | * | |||
* (c) Leo Feyer | * (c) Leo Feyer | |||
* | * | |||
* @license LGPL-3.0-or-later | * @license LGPL-3.0-or-later | |||
*/ | */ | |||
namespace Contao\CoreBundle\Controller; | namespace Contao\CoreBundle\Controller; | |||
use Contao\CoreBundle\Fragment\FragmentOptionsAwareInterface; | use Contao\CoreBundle\Fragment\FragmentOptionsAwareInterface; | |||
use Contao\CoreBundle\Routing\ScopeMatcher; | ||||
use Contao\FrontendTemplate; | use Contao\FrontendTemplate; | |||
use Contao\Model; | use Contao\Model; | |||
use Contao\PageModel; | use Contao\PageModel; | |||
use Contao\StringUtil; | use Contao\StringUtil; | |||
use Contao\Template; | use Contao\Template; | |||
use Symfony\Component\DependencyInjection\Container; | use Symfony\Component\DependencyInjection\Container; | |||
use Symfony\Component\HttpFoundation\RequestStack; | use Symfony\Component\HttpFoundation\RequestStack; | |||
abstract class AbstractFragmentController extends AbstractController implements FragmentOptionsAwareInterface | abstract class AbstractFragmentController extends AbstractController implements FragmentOptionsAwareInterface | |||
{ | { | |||
/** | /** | |||
* @var array | * @var array | |||
*/ | */ | |||
protected $options = []; | protected $options = []; | |||
public function setFragmentOptions(array $options): void | public function setFragmentOptions(array $options): void | |||
{ | { | |||
$this->options = $options; | $this->options = $options; | |||
} | } | |||
public static function getSubscribedServices(): array | /** | |||
* @return array<string> | ||||
*/ | ||||
public static function getSubscribedServices() | ||||
{ | { | |||
$services = parent::getSubscribedServices(); | $services = parent::getSubscribedServices(); | |||
$services['request_stack'] = RequestStack::class; | $services['request_stack'] = RequestStack::class; | |||
$services['contao.routing.scope_matcher'] = ScopeMatcher::class; | ||||
return $services; | return $services; | |||
} | } | |||
protected function getPageModel(): ?PageModel | protected function getPageModel(): ?PageModel | |||
{ | { | |||
$request = $this->get('request_stack')->getCurrentRequest(); | $request = $this->get('request_stack')->getCurrentRequest(); | |||
if (null === $request || !$request->attributes->has('pageModel')) { | if (null === $request || !$request->attributes->has('pageModel')) { | |||
return null; | return null; | |||
skipping to change at line 85 | skipping to change at line 90 | |||
/** | /** | |||
* Creates a template by name or from the "customTpl" field of the model. | * Creates a template by name or from the "customTpl" field of the model. | |||
*/ | */ | |||
protected function createTemplate(Model $model, string $templateName): Templ ate | protected function createTemplate(Model $model, string $templateName): Templ ate | |||
{ | { | |||
if (isset($this->options['template'])) { | if (isset($this->options['template'])) { | |||
$templateName = $this->options['template']; | $templateName = $this->options['template']; | |||
} | } | |||
if ($model->customTpl) { | if ($model->customTpl) { | |||
$templateName = $model->customTpl; | $request = $this->get('request_stack')->getCurrentRequest(); | |||
// Use the custom template unless it is a back end request | ||||
if (null === $request || !$this->get('contao.routing.scope_matcher') | ||||
->isBackendRequest($request)) { | ||||
$templateName = $model->customTpl; | ||||
} | ||||
} | } | |||
$template = $this->get('contao.framework')->createInstance(FrontendTempl ate::class, [$templateName]); | $template = $this->get('contao.framework')->createInstance(FrontendTempl ate::class, [$templateName]); | |||
$template->setData($model->row()); | $template->setData($model->row()); | |||
return $template; | return $template; | |||
} | } | |||
/** | /** | |||
* @param string|array $headline | * @param string|array $headline | |||
End of changes. 4 change blocks. | ||||
2 lines changed or deleted | 13 lines changed or added |