mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Restore legacy $ThemeDir support
This commit is contained in:
parent
07a0f75426
commit
6e7fb4747e
@ -3,9 +3,12 @@
|
||||
namespace SilverStripe\View;
|
||||
|
||||
use Exception;
|
||||
use SilverStripe\Core\Config\Config;
|
||||
use SilverStripe\Core\Config\Configurable;
|
||||
use SilverStripe\Core\Extensible;
|
||||
use SilverStripe\Core\Injector\Injectable;
|
||||
use SilverStripe\Core\Manifest\ModuleResourceLoader;
|
||||
use SilverStripe\Dev\Deprecation;
|
||||
use SilverStripe\ORM\ArrayLib;
|
||||
use SilverStripe\ORM\FieldType\DBField;
|
||||
use SilverStripe\ORM\FieldType\DBHTMLText;
|
||||
@ -586,6 +589,35 @@ class ViewableData implements IteratorAggregate
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the directory if the current active theme (relative to the site root).
|
||||
*
|
||||
* This method is useful for things such as accessing theme images from your template without hardcoding the theme
|
||||
* page - e.g. <img src="$ThemeDir/images/something.gif">.
|
||||
*
|
||||
* This method should only be used when a theme is currently active. However, it will fall over to the current
|
||||
* project directory.
|
||||
*
|
||||
* @return string URL to the current theme
|
||||
* @deprecated 4.0.0..5.0.0 Use $resourcePath or $resourceURL template helpers instead
|
||||
*/
|
||||
public function ThemeDir()
|
||||
{
|
||||
Deprecation::notice('5.0', 'Use $resourcePath or $resourceURL template helpers instead');
|
||||
$themes = SSViewer::get_themes();
|
||||
foreach ($themes as $theme) {
|
||||
// Skip theme sets
|
||||
if (strpos($theme, '$') === 0) {
|
||||
continue;
|
||||
}
|
||||
// Map theme path to url
|
||||
$themePath = ThemeResourceLoader::inst()->getPath($theme);
|
||||
return ModuleResourceLoader::resourceURL($themePath);
|
||||
}
|
||||
|
||||
return project();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get part of the current classes ancestry to be used as a CSS class.
|
||||
*
|
||||
|
@ -5,6 +5,7 @@ namespace SilverStripe\View\Tests;
|
||||
use SilverStripe\ORM\FieldType\DBField;
|
||||
use SilverStripe\Dev\SapphireTest;
|
||||
use SilverStripe\View\ArrayData;
|
||||
use SilverStripe\View\SSViewer;
|
||||
use SilverStripe\View\ViewableData;
|
||||
|
||||
/**
|
||||
@ -204,4 +205,19 @@ class ViewableDataTest extends SapphireTest
|
||||
$this->assertSame($failover, $container->getFailover(), 'getFailover() returned a different object');
|
||||
$this->assertFalse($container->hasMethod('testMethod'), 'testMethod() incorrectly reported as existing');
|
||||
}
|
||||
|
||||
public function testThemeDir()
|
||||
{
|
||||
$themes = [
|
||||
"silverstripe/framework:/tests/php/View/ViewableDataTest/testtheme",
|
||||
SSViewer::DEFAULT_THEME
|
||||
];
|
||||
SSViewer::set_themes($themes);
|
||||
|
||||
$data = new ViewableData();
|
||||
$this->assertContains(
|
||||
'tests/php/View/ViewableDataTest/testtheme',
|
||||
$data->ThemeDir()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
0
tests/php/View/ViewableDataTest/testtheme/empty.txt
Normal file
0
tests/php/View/ViewableDataTest/testtheme/empty.txt
Normal file
Loading…
Reference in New Issue
Block a user