NEW: Add ViewableData::getViewerTemplates()

Forms part of the fix for silverstripe/silverstripe-cms#2039
This commit is contained in:
Loz Calver 2017-12-01 15:03:39 +00:00
parent d57dea0318
commit 259ae3f78b
2 changed files with 39 additions and 21 deletions

View File

@ -2,35 +2,36 @@
namespace SilverStripe\ORM; namespace SilverStripe\ORM;
use BadMethodCallException;
use Exception;
use InvalidArgumentException;
use LogicException;
use SilverStripe\Control\HTTP;
use SilverStripe\Core\ClassInfo; use SilverStripe\Core\ClassInfo;
use SilverStripe\Core\Config\Config; use SilverStripe\Core\Config\Config;
use SilverStripe\Core\Injector\Injector; use SilverStripe\Core\Injector\Injector;
use SilverStripe\Core\Resettable; use SilverStripe\Core\Resettable;
use SilverStripe\Dev\Deprecation;
use SilverStripe\Dev\Debug; use SilverStripe\Dev\Debug;
use SilverStripe\Control\HTTP; use SilverStripe\Dev\Deprecation;
use SilverStripe\Forms\FieldList; use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\FormField; use SilverStripe\Forms\FormField;
use SilverStripe\Forms\FormScaffolder; use SilverStripe\Forms\FormScaffolder;
use SilverStripe\i18n\i18n; use SilverStripe\i18n\i18n;
use SilverStripe\i18n\i18nEntityProvider; use SilverStripe\i18n\i18nEntityProvider;
use SilverStripe\ORM\Connect\MySQLSchemaManager; 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\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\Member;
use SilverStripe\Security\Permission; use SilverStripe\Security\Permission;
use SilverStripe\Security\Security; use SilverStripe\Security\Security;
use SilverStripe\View\SSViewer;
use SilverStripe\View\ViewableData; use SilverStripe\View\ViewableData;
use LogicException;
use InvalidArgumentException;
use BadMethodCallException;
use Exception;
use stdClass; use stdClass;
/** /**
@ -2146,6 +2147,11 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
return $untabbedFields; return $untabbedFields;
} }
public function getViewerTemplates($suffix = '')
{
return SSViewer::get_templates_by_class(static::class, $suffix, $this->baseClass());
}
/** /**
* Gets the value of a field. * Gets the value of a field.
* Called by {@link __get()} and any getFieldName() methods you might create. * Called by {@link __get()} and any getFieldName() methods you might create.

View File

@ -2,25 +2,26 @@
namespace SilverStripe\View; namespace SilverStripe\View;
use ArrayIterator;
use Exception; use Exception;
use InvalidArgumentException;
use IteratorAggregate;
use LogicException;
use SilverStripe\Core\ClassInfo;
use SilverStripe\Core\Config\Config; use SilverStripe\Core\Config\Config;
use SilverStripe\Core\Config\Configurable; use SilverStripe\Core\Config\Configurable;
use SilverStripe\Core\Convert;
use SilverStripe\Core\Extensible; use SilverStripe\Core\Extensible;
use SilverStripe\Core\Injector\Injectable; use SilverStripe\Core\Injector\Injectable;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Core\Manifest\ModuleResourceLoader; use SilverStripe\Core\Manifest\ModuleResourceLoader;
use SilverStripe\Dev\Debug;
use SilverStripe\Dev\Deprecation; use SilverStripe\Dev\Deprecation;
use SilverStripe\ORM\ArrayLib; use SilverStripe\ORM\ArrayLib;
use SilverStripe\ORM\FieldType\DBField; use SilverStripe\ORM\FieldType\DBField;
use SilverStripe\ORM\FieldType\DBHTMLText; use SilverStripe\ORM\FieldType\DBHTMLText;
use SilverStripe\Core\ClassInfo; use SilverStripe\View\SSViewer;
use SilverStripe\Core\Convert;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Dev\Debug;
use IteratorAggregate;
use LogicException;
use InvalidArgumentException;
use UnexpectedValueException; use UnexpectedValueException;
use ArrayIterator;
/** /**
* A ViewableData object is any object that can be rendered into a template/view. * A ViewableData object is any object that can be rendered into a template/view.
@ -578,6 +579,17 @@ class ViewableData implements IteratorAggregate
// UTILITY METHODS ------------------------------------------------------------------------------------------------- // 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 * When rendering some objects it is necessary to iterate over the object being rendered, to do this, you need
* access to itself. * access to itself.