Compare commits

...

2 commits

Author SHA1 Message Date
rxu
ccbdfb49c7
[ticket/15214] Adjust core event name and docblock
PHPBB3-15214
2025-05-21 11:25:35 +07:00
rxu
43cf7b73bd
[ticket/15214] Adjust event node logic
PHPBB3-15214
2025-05-21 10:47:27 +07:00
6 changed files with 35 additions and 21 deletions

View file

@ -52,11 +52,8 @@ class event extends \Twig\Node\Node
foreach ($this->environment->get_phpbb_extensions() as $ext_namespace => $ext_path)
{
$ext_namespace = str_replace('/', '_', $ext_namespace);
if ($this->environment->isDebug() || $this->environment->getLoader()->exists('@' . $ext_namespace . '/' . $location . '.html'))
{
$priority_key = $this->template_event_priority_array[$ext_namespace][$location] ?? 0;
$template_events[$priority_key][] = $ext_namespace;
}
$priority_key = $this->template_event_priority_array[$ext_namespace][$location] ?? 0;
$template_events[$priority_key][] = $ext_namespace;
}
krsort($template_events);
@ -75,13 +72,16 @@ class event extends \Twig\Node\Node
->indent();
}
$compiler
->write("\$previous_look_up_order = \$this->env->getNamespaceLookUpOrder();\n")
if ($this->environment->isDebug() || $this->environment->getLoader()->exists('@' . $ext_namespace . '/' . $location . '.html'))
{
$compiler
->write("\$previous_look_up_order = \$this->env->getNamespaceLookUpOrder();\n")
// We set the namespace lookup order to be this extension first, then the main path
->write("\$this->env->setNamespaceLookUpOrder(array('{$ext_namespace}', '__main__'));\n")
->write("\$this->env->loadTemplate(\$this->env->getTemplateClass('@{$ext_namespace}/{$location}.html'), '@{$ext_namespace}/{$location}.html')->display(\$context);\n")
->write("\$this->env->setNamespaceLookUpOrder(\$previous_look_up_order);\n");
// We set the namespace lookup order to be this extension first, then the main path
->write("\$this->env->setNamespaceLookUpOrder(array('{$ext_namespace}', '__main__'));\n")
->write("\$this->env->loadTemplate(\$this->env->getTemplateClass('@{$ext_namespace}/{$location}.html'), '@{$ext_namespace}/{$location}.html')->display(\$context);\n")
->write("\$this->env->setNamespaceLookUpOrder(\$previous_look_up_order);\n");
}
if ($this->environment->isDebug())
{

View file

@ -42,7 +42,7 @@ class event extends \Twig\TokenParser\AbstractTokenParser
* In case of equal priority values, corresponding template event listeners will be handled in default compilation order.
* If not set, template event listener priority will be assigned to the value of 0.
*
* @event core.twig_tokenparser_constructor
* @event core.twig_event_tokenparser_constructor
* @var array template_event_priority_array Array with template event priority assignments per extension namespace
* Usage:
* '<author>_<extension_name>' => [
@ -50,17 +50,31 @@ class event extends \Twig\TokenParser\AbstractTokenParser
* ],
*
* Example:
* 'phpbb_viglink' => [
* 'event/acp_help_phpbb_stats_after' => 80,
* 'event/overall_footer_after' => 100,
* ],
* class template_event_order implements EventSubscriberInterface
* {
* static public function getSubscribedEvents()
* {
* return [
* 'core.twig_event_tokenparser_constructor' => 'set_template_event_priority',
* ];
* }
*
* public function set_template_event_priority($event)
* {
* $template_event_priority_array = $event['template_event_priority_array'];
* $template_event_priority_array['vendor_name'] = [
* 'event/navbar_header_quick_links_after' => -1,
* ];
* $event['template_event_priority_array'] = $template_event_priority_array;
* }
* }
*
* @since 4.0.0-a1
*/
if ($this->phpbb_dispatcher)
{
$vars = ['template_event_priority_array'];
extract($this->phpbb_dispatcher->trigger_event('core.twig_tokenparser_constructor', compact($vars)));
extract($this->phpbb_dispatcher->trigger_event('core.twig_event_tokenparser_constructor', compact($vars)));
}
$this->template_event_priority_array = $template_event_priority_array;

View file

@ -23,7 +23,7 @@ class template_event_order implements EventSubscriberInterface
static public function getSubscribedEvents()
{
return array(
'core.twig_tokenparser_constructor' => 'set_template_event_priority',
'core.twig_event_tokenparser_constructor' => 'set_template_event_priority',
);
}

View file

@ -23,7 +23,7 @@ class template_event_order implements EventSubscriberInterface
static public function getSubscribedEvents()
{
return array(
'core.twig_tokenparser_constructor' => 'set_template_event_priority',
'core.twig_event_tokenparser_constructor' => 'set_template_event_priority',
);
}

View file

@ -23,7 +23,7 @@ class template_event_order implements EventSubscriberInterface
static public function getSubscribedEvents()
{
return array(
'core.twig_tokenparser_constructor' => 'set_template_event_priority',
'core.twig_event_tokenparser_constructor' => 'set_template_event_priority',
);
}

View file

@ -23,7 +23,7 @@ class template_event_order implements EventSubscriberInterface
static public function getSubscribedEvents()
{
return array(
'core.twig_tokenparser_constructor' => 'set_template_event_priority',
'core.twig_event_tokenparser_constructor' => 'set_template_event_priority',
);
}