A few notes on your code:
1. You don't need getAllowedTargets() and getDefaultTemplate() methods in your class as they exist in the original widget class.
2. For easier tracking which classes extend what other classes it makes sense to rename your class from PGPage to CustomerPage (as the original class that you modify from your module).
3. Instead of searching a page with the given name, it will be easier to get the current page and check its name.
4. View classes can use public methods declared in the controller used for the current page. In case of SimpleCMS pages the controller class is \XLite\Module\CDev\SimpleCMS\Controller\Customer\P age that already has getPage() public method. It makes sense to use these methods instead of trying to retrieve the current page by using the Repo class.
5. It makes sense to put the code that checks if it is the gallery page into a separate method.
6. Having one return operator per method is a good practice. You should avoid multiple returns per method when possible.
So, I would change your code as follows:
PHP Code:
<?php
// vim: set ts=4 sw=4 sts=4 et ft=php.html:
namespace XLite\Module\MHG\TemplateMods\View;
/**
* Decorated widget displaying a SimpleCMS page.
*/
class CustomerPage extends \XLite\Module\CDev\SimpleCMS\View\CustomerPage implements \XLite\Base\IDecorator
{
public function getCSSFiles()
{
$files = parent::getCSSFiles();
if ($this->isGallerypage()) {
$files = array_merge(
$files,
array(
array(
'url' => "//cdnjs.cloudflare.com/ajax/libs/nanogallery/5.9.1/css/nanogallery.min.css",
'media' => 'screen',
'no_minify' => true,
),
array(
'url' => "//cdnjs.cloudflare.com/ajax/libs/nanogallery/5.9.1/css/themes/light/nanogallery_light.min.css",
'media' => 'screen',
'no_minify' => true,
)
)
);
}
return $files;
}
public function getJSFiles()
{
$files = parent::getJSFiles();
if ($this->isGallerypage())
{
$files = array_merge(
$files,
array(
array(
'url' => "//cdnjs.cloudflare.com/ajax/libs/nanogallery/5.9.1/jquery.nanogallery.min.js",
'no_minify' => true
),
array(
'file' => 'modules/MHG/TemplateMods/nanogallery_local.js'
)
)
);
}
return $files;
}
protected function isGalleryPage()
{
// Use the getPage() method of the controller class to get the current page object
$currentName = $this->getPage()->getName();
return "Photo Gallery" === $currentName;
}
}
Quote:
Originally Posted by Scott Godin
why css/js aggregation under Look and Feel > Performance, when enabled, fail to load resources added via URL rather than FILE
|
If you add a resource with the "url" key, not "file", X-Cart 5 won't aggregate the file. So, this should work as you expect.