Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add trimwhitespace config #4531

Merged
merged 3 commits into from
Oct 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG-3.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- Fixes:
- [CoreBundle] Added clearing of OPCache (if in use) to standard clearcache operation (#4507).
- [ThemeModule] Asset combination now defaults to `false` on installation (#4419).
- [ThemeModule] Corrected missing configurable value for `trimwhitespace` option ().

- Features:
- [config] Added standard Symfony bundle configurations for the following bundles (#4433):
Expand Down
1 change: 1 addition & 0 deletions docs/Configuration/BundleConfig/Defaults/zikula_theme.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# These are the default values
zikula_theme:
script_position: foot
trimwhitespace: false
bootstrap:
css_path: '/bootstrap/css/bootstrap.min.css'
js_path: '/bootstrap/js/bootstrap.bundle.min.js'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public function getConfigTreeBuilder()
->values(['head', 'foot'])
->defaultValue('foot')
->end()
->booleanNode('trimwhitespace')->defaultFalse()->end()
->arrayNode('bootstrap')
->addDefaultsIfNotSet()
->children()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use Zikula\ThemeModule\EventListener\DefaultPageAssetSetterListener;
use Zikula\ThemeModule\EventListener\ExtensionInstallationListener;
use Zikula\ThemeModule\EventListener\HookChangeListener;
use Zikula\ThemeModule\EventListener\ResponseTransformerListener;

class ZikulaThemeExtension extends Extension
{
Expand All @@ -37,6 +38,8 @@ public function load(array $configs, ContainerBuilder $container)

$container->getDefinition(AssetFilter::class)
->setArgument('$scriptPosition', $config['script_position']);
$container->getDefinition(ResponseTransformerListener::class)
->setArgument('$trimWhitespace', $config['trimwhitespace']);

$container->getDefinition(ExtensionInstallationListener::class)
->setArgument('$mergerActive', $config['asset_manager']['combine']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,18 @@
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\ResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents;
use Zikula\ExtensionsModule\Api\ApiInterface\VariableApiInterface;
use Zikula\ThemeModule\Engine\ResponseTransformer;

class ResponseTransformerListener implements EventSubscriberInterface
{
/**
* @var VariableApiInterface
* @var bool
*/
private $variableApi;
private $trimWhitespace;

public function __construct(VariableApiInterface $variableApi)
public function __construct(bool $trimWhitespace = false)
{
$this->variableApi = $variableApi;
$this->trimWhitespace = $trimWhitespace;
}

public static function getSubscribedEvents()
Expand All @@ -47,8 +46,7 @@ public function transformResponse(ResponseEvent $event): void
}

$response = $event->getResponse();
$trimWhitespace = $this->variableApi->get('ZikulaThemeModule', 'trimwhitespace');
if ($trimWhitespace) {
if ($this->trimWhitespace) {
$responseTransformer = new ResponseTransformer();
$responseTransformer->trimWhitespace($response);
}
Expand Down
27 changes: 2 additions & 25 deletions src/system/ThemeModule/ThemeModuleInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,6 @@ class ThemeModuleInstaller extends AbstractExtensionInstaller
{
public function install(): bool
{
// define defaults for module vars
$this->setVar('modulesnocache');
$this->setVar('enablecache', false);
$this->setVar('compile_check', true);
$this->setVar('cache_lifetime', 1800);
$this->setVar('cache_lifetime_mods', 1800);
$this->setVar('force_compile', false);
$this->setVar('trimwhitespace', false);
$this->setVar('maxsizeforlinks', 30);
$this->setVar('itemsperpage', 25);

$this->setVar('cssjscombine', false);
$this->setVar('cssjscompress', false);
$this->setVar('cssjsminify', false);
$this->setVar('cssjscombine_lifetime', 3600);

// View
$this->setVar('render_compile_check', true);
$this->setVar('render_force_compile', false);
$this->setVar('render_cache', false);
$this->setVar('render_expose_template', false);
$this->setVar('render_lifetime', 3600);

// Initialisation successful
return true;
}

Expand All @@ -53,7 +29,8 @@ public function upgrade(string $oldVersion): bool
// version number reset to 3.0.0 at Core 3.0.0
switch ($oldVersion) {
case '2.9.9':
// nothing to do
case '3.0.99':
$this->delVars();
}

return true;
Expand Down