У меня возникла трудная для отладки проблема. Я пытаюсь отключить доктрину SQLFilter в \Twig_Extension, но фильтр по-прежнему применяется к следующему запросу. ?
Я сделал такой же код в контроллере, и фильтр хорошо отключился.
Вот соответствующие части функции Twig:
/**
* @return array|\Twig_Function[]
*/
public function getFunctions()
{
return [
new TwigFunction('hreflang', [$this, 'hreflang'], ['is_safe_callback' => true, 'is_safe' => ['html']]),
];
}
/**
* Builds and returns the hreflang of a page.
*
* @param string $locale
* @param TreeNodeInterface|null $contentObject
*
* @return string
*/
public function hreflang(string $locale, TreeNodeInterface $contentObject = null)
{
// Deactivate the doctrine filter
if ($this->em->getFilters()->isEnabled('locale_filter')) {
$this->em->getFilters()->disable('locale_filter');
}
// Query the ORM for fetching the translated url.
// This is the part where the SQLFilter should be deactivated but is not.
$url = $this->getTranslatedUrl($locale, $contentObject);
// Reactivate the doctrine filter.
$this->em->getFilters()->enable('locale_filter');
// ... Builds and returns the hreflang, no relevant code.
}
Этот фрагмент кода используется, чтобы работать как шарм в приложении 3.4, сейчас я работаю над 4.1.4.
Большое спасибо.
Я знаю, да. Вверху моего базового шаблона (в шапке).






Вы действительно вызываете функцию
hreflangвнутри шаблона?