From 259ae3f78bf4fe13985a1277d5b94210935d408f Mon Sep 17 00:00:00 2001 From: Loz Calver Date: Fri, 1 Dec 2017 15:03:39 +0000 Subject: [PATCH] NEW: Add ViewableData::getViewerTemplates() Forms part of the fix for silverstripe/silverstripe-cms#2039 --- src/ORM/DataObject.php | 32 +++++++++++++++++++------------- src/View/ViewableData.php | 28 ++++++++++++++++++++-------- 2 files changed, 39 insertions(+), 21 deletions(-) diff --git a/src/ORM/DataObject.php b/src/ORM/DataObject.php index aeea71e03..c9a61bb87 100644 --- a/src/ORM/DataObject.php +++ b/src/ORM/DataObject.php @@ -2,35 +2,36 @@ namespace SilverStripe\ORM; +use BadMethodCallException; +use Exception; +use InvalidArgumentException; +use LogicException; +use SilverStripe\Control\HTTP; use SilverStripe\Core\ClassInfo; use SilverStripe\Core\Config\Config; use SilverStripe\Core\Injector\Injector; use SilverStripe\Core\Resettable; -use SilverStripe\Dev\Deprecation; use SilverStripe\Dev\Debug; -use SilverStripe\Control\HTTP; +use SilverStripe\Dev\Deprecation; use SilverStripe\Forms\FieldList; use SilverStripe\Forms\FormField; use SilverStripe\Forms\FormScaffolder; use SilverStripe\i18n\i18n; use SilverStripe\i18n\i18nEntityProvider; use SilverStripe\ORM\Connect\MySQLSchemaManager; -use SilverStripe\ORM\Filters\SearchFilter; -use SilverStripe\ORM\Search\SearchContext; -use SilverStripe\ORM\Queries\SQLInsert; -use SilverStripe\ORM\Queries\SQLDelete; -use SilverStripe\ORM\FieldType\DBField; -use SilverStripe\ORM\FieldType\DBDatetime; -use SilverStripe\ORM\FieldType\DBComposite; use SilverStripe\ORM\FieldType\DBClassName; +use SilverStripe\ORM\FieldType\DBComposite; +use SilverStripe\ORM\FieldType\DBDatetime; +use SilverStripe\ORM\FieldType\DBField; +use SilverStripe\ORM\Filters\SearchFilter; +use SilverStripe\ORM\Queries\SQLDelete; +use SilverStripe\ORM\Queries\SQLInsert; +use SilverStripe\ORM\Search\SearchContext; use SilverStripe\Security\Member; use SilverStripe\Security\Permission; use SilverStripe\Security\Security; +use SilverStripe\View\SSViewer; use SilverStripe\View\ViewableData; -use LogicException; -use InvalidArgumentException; -use BadMethodCallException; -use Exception; use stdClass; /** @@ -2146,6 +2147,11 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity return $untabbedFields; } + public function getViewerTemplates($suffix = '') + { + return SSViewer::get_templates_by_class(static::class, $suffix, $this->baseClass()); + } + /** * Gets the value of a field. * Called by {@link __get()} and any getFieldName() methods you might create. diff --git a/src/View/ViewableData.php b/src/View/ViewableData.php index 79d3a239f..317cb51db 100644 --- a/src/View/ViewableData.php +++ b/src/View/ViewableData.php @@ -2,25 +2,26 @@ namespace SilverStripe\View; +use ArrayIterator; use Exception; +use InvalidArgumentException; +use IteratorAggregate; +use LogicException; +use SilverStripe\Core\ClassInfo; use SilverStripe\Core\Config\Config; use SilverStripe\Core\Config\Configurable; +use SilverStripe\Core\Convert; use SilverStripe\Core\Extensible; use SilverStripe\Core\Injector\Injectable; +use SilverStripe\Core\Injector\Injector; use SilverStripe\Core\Manifest\ModuleResourceLoader; +use SilverStripe\Dev\Debug; use SilverStripe\Dev\Deprecation; use SilverStripe\ORM\ArrayLib; use SilverStripe\ORM\FieldType\DBField; use SilverStripe\ORM\FieldType\DBHTMLText; -use SilverStripe\Core\ClassInfo; -use SilverStripe\Core\Convert; -use SilverStripe\Core\Injector\Injector; -use SilverStripe\Dev\Debug; -use IteratorAggregate; -use LogicException; -use InvalidArgumentException; +use SilverStripe\View\SSViewer; use UnexpectedValueException; -use ArrayIterator; /** * A ViewableData object is any object that can be rendered into a template/view. @@ -578,6 +579,17 @@ class ViewableData implements IteratorAggregate // UTILITY METHODS ------------------------------------------------------------------------------------------------- + /** + * Find appropriate templates for SSViewer to use to render this object + * + * @param string $suffix + * @return array + */ + public function getViewerTemplates($suffix = '') + { + return SSViewer::get_templates_by_class(static::class, $suffix, self::class); + } + /** * When rendering some objects it is necessary to iterate over the object being rendered, to do this, you need * access to itself.