diff --git a/phpBB/phpbb/textformatter/s9e/factory.php b/phpBB/phpbb/textformatter/s9e/factory.php index b053fd6468..01209d352a 100644 --- a/phpBB/phpbb/textformatter/s9e/factory.php +++ b/phpBB/phpbb/textformatter/s9e/factory.php @@ -471,11 +471,21 @@ class factory implements \phpbb\textformatter\cache_interface /** * Merge the templates from any number of styles into one BBCode template * + * When multiple templates are available for the same BBCode (because of multiple styles) we + * merge them into a single template that uses an xsl:choose construct that determines which + * style to use at rendering time. + * * @param array $style_templates Associative array matching style_ids to their template * @return string */ protected function merge_templates(array $style_templates) { + // Return the template as-is if there's only one style or all styles share the same template + if (count(array_unique($style_templates)) === 1) + { + return end($style_templates); + } + // Group identical templates together $grouped_templates = array(); foreach ($style_templates as $style_id => $style_template) @@ -483,11 +493,6 @@ class factory implements \phpbb\textformatter\cache_interface $grouped_templates[$style_template][] = '$STYLE_ID=' . $style_id; } - if (count($grouped_templates) === 1) - { - return $style_template; - } - // Sort templates by frequency descending $templates_cnt = array_map('sizeof', $grouped_templates); array_multisort($grouped_templates, $templates_cnt);