mirror of
https://github.com/phpbb/phpbb.git
synced 2025-07-30 21:40:43 +02:00
[feature/twig] Working on fixing tests
PHPBB3-11598
This commit is contained in:
@@ -130,4 +130,11 @@ interface phpbb_template
|
||||
* @return bool false on error, true on success
|
||||
*/
|
||||
public function alter_block_array($blockname, array $vararray, $key = false, $mode = 'insert');
|
||||
|
||||
/**
|
||||
* Clear the cache
|
||||
*
|
||||
* @return phpbb_template
|
||||
*/
|
||||
public function clear_cache();
|
||||
}
|
||||
|
@@ -32,20 +32,36 @@ class phpbb_template_twig_node_begin extends Twig_Node
|
||||
;
|
||||
|
||||
$compiler
|
||||
->write("foreach (\$parent['" . $this->getAttribute('beginName') . "'] as \$" . $this->getAttribute('beginName') . ") {\n")
|
||||
->indent()
|
||||
// Set up $context correctly so that Twig can get the correct data with $this->getAttribute
|
||||
->write("\$this->getEnvironment()->context_recursive_loop_builder(\$" . $this->getAttribute('beginName') . ", \$phpbb_blocks, \$context);\n")
|
||||
->write("if (!empty(\$parent['" . $this->getAttribute('beginName') . "'])) {\n")
|
||||
->indent()
|
||||
->write("foreach (\$parent['" . $this->getAttribute('beginName') . "'] as \$" . $this->getAttribute('beginName') . ") {\n")
|
||||
->indent()
|
||||
// Set up $context correctly so that Twig can get the correct data with $this->getAttribute
|
||||
->write("\$this->getEnvironment()->context_recursive_loop_builder(\$" . $this->getAttribute('beginName') . ", \$phpbb_blocks, \$context);\n")
|
||||
|
||||
// We store the parent so that we can do this recursively
|
||||
->write("\$parent = \$" . $this->getAttribute('beginName') . ";\n")
|
||||
// We store the parent so that we can do this recursively
|
||||
->write("\$parent = \$" . $this->getAttribute('beginName') . ";\n")
|
||||
;
|
||||
|
||||
$compiler->subcompile($this->getNode('body'));
|
||||
|
||||
$compiler
|
||||
->outdent()
|
||||
->write("}\n")
|
||||
$compiler
|
||||
->outdent()
|
||||
->write("}\n")
|
||||
;
|
||||
|
||||
if (null !== $this->getNode('else')) {
|
||||
$compiler
|
||||
->write("} else {\n")
|
||||
->indent()
|
||||
->subcompile($this->getNode('else'))
|
||||
->outdent()
|
||||
;
|
||||
}
|
||||
|
||||
$compiler
|
||||
->outdent()
|
||||
->write("}\n")
|
||||
|
||||
// Remove the last item from the blocks storage as we've completed iterating over them all
|
||||
->write("array_pop(\$phpbb_blocks);\n")
|
||||
|
@@ -114,10 +114,6 @@ class phpbb_template_twig implements phpbb_template
|
||||
// Initiate the loader, __main__ namespace paths will be setup later in set_style_names()
|
||||
$loader = new Twig_Loader_Filesystem('');
|
||||
|
||||
// Add admin namespace
|
||||
// @todo use phpbb_admin path
|
||||
$loader->addPath($this->phpbb_root_path . 'adm/style/', 'admin');
|
||||
|
||||
$this->twig = new phpbb_template_twig_environment($loader, array(
|
||||
'cache' => $this->cachepath,
|
||||
'debug' => true, // @todo
|
||||
@@ -133,10 +129,7 @@ class phpbb_template_twig implements phpbb_template
|
||||
|
||||
// Clear previous cache files (while WIP)
|
||||
// @todo remove
|
||||
if (is_dir($this->cachepath))
|
||||
{
|
||||
$this->twig->clearCacheFiles();
|
||||
}
|
||||
$this->clear_cache();
|
||||
|
||||
$this->twig->addExtension(new phpbb_template_twig_extension);
|
||||
|
||||
@@ -145,6 +138,21 @@ class phpbb_template_twig implements phpbb_template
|
||||
$this->twig->setLexer($lexer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the cache
|
||||
*
|
||||
* @return phpbb_template
|
||||
*/
|
||||
public function clear_cache()
|
||||
{
|
||||
if (is_dir($this->cachepath))
|
||||
{
|
||||
$this->twig->clearCacheFiles();
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the template filenames for handles.
|
||||
*
|
||||
@@ -177,6 +185,10 @@ class phpbb_template_twig implements phpbb_template
|
||||
{
|
||||
$this->twig->getLoader()->setPaths($style_paths, 'core');
|
||||
|
||||
// Add admin namespace
|
||||
// @todo use phpbb_admin path
|
||||
$loader->addPath($this->phpbb_root_path . 'adm/style/', 'admin');
|
||||
|
||||
// Add all namespaces for all extensions
|
||||
if ($this->extension_manager instanceof phpbb_extension_manager)
|
||||
{
|
||||
@@ -415,25 +427,28 @@ class phpbb_template_twig implements phpbb_template
|
||||
$vars = array();
|
||||
|
||||
// Work-around for now
|
||||
foreach ($this->user->lang as $key => $value)
|
||||
if (!empty($this->user->lang))
|
||||
{
|
||||
if (!is_string($value))
|
||||
foreach ($this->user->lang as $key => $value)
|
||||
{
|
||||
continue;
|
||||
if (!is_string($value))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$vars['L_' . strtoupper($key)] = $value;
|
||||
$vars['LA_' . strtoupper($key)] = addslashes($value);
|
||||
}
|
||||
|
||||
$vars['L_' . strtoupper($key)] = $value;
|
||||
$vars['LA_' . strtoupper($key)] = addslashes($value);
|
||||
$vars = array_merge(
|
||||
$vars,
|
||||
$this->context->get_rootref(),
|
||||
array(
|
||||
'_phpbb_blocks' => $this->context->get_tpldata(),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$vars = array_merge(
|
||||
$vars,
|
||||
$this->context->get_rootref(),
|
||||
array(
|
||||
'_phpbb_blocks' => $this->context->get_tpldata(),
|
||||
)
|
||||
);
|
||||
|
||||
// Must do this so that <!-- IF .blah --> works correctly
|
||||
// (only for the base loops, the rest are properly handled by the begin node)
|
||||
foreach ($this->context->get_tpldata() as $block_name => $block_values)
|
||||
|
Reference in New Issue
Block a user