SiteTree
class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvider, CMSPreviewable, Resettable, Flushable, MemberCacheFlusher
Basic data-object representing all pages within the site tree. All page types that live within the hierarchy should inherit from this. In addition, it contains a number of static methods for querying the site tree and working with draft and published states.
URLs
A page is identified during request handling via its "URLSegment" database column. As pages can be nested, the full path of a URL might contain multiple segments. Each segment is stored in its filtered representation (through {@link URLSegmentFilter}). The full path is constructed via {@link Link()}, {@link RelativeLink()} and {@link AbsoluteLink()}. You can allow these segments to contain multibyte characters through {@link URLSegmentFilter::$default_allow_multibyte}.
Traits
Constants
CHANGE_NONE |
Represents a field that hasn't changed (before === after, thus before == after) |
CHANGE_STRICT |
Represents a field that has changed type, although not the loosely defined value. (before !== after && before == after) E.g. change 1 to true or "true" to true, but not true to 0. Value changes are by nature also considered strict changes. |
CHANGE_VALUE |
Represents a field that has changed the loosely defined value (before != after, thus, before !== after)) E.g. change false to true, but not false to 0 |
Config options
allowed_children | array | Indicates what kind of children this page type can have. | |
default_child | string | The default child class for this page. | |
default_classname | string | Default value for SiteTree.ClassName enum {see DBClassName::getDefault} | |
default_parent | string | The default parent class for this page. | |
can_be_root | bool | Controls whether a page can be in the root of the site tree. | |
need_permission | array | List of permission codes a user can have to allow a user to create a page of this type. | |
hide_ancestor | string | If you extend a class, and don't want to be able to select the old class in the cms, set this to the old class name. Eg, if you extended Product to make ImprovedProduct, then you would set $hide_ancestor to Product. | |
controller_name | string | You can define the class of the controller that maps to your SiteTree object here if you don't want to rely on the magic of appending Controller to the Classname | |
can_create | boolean | If this is false, the class cannot be created in the CMS by regular content authors, only by ADMINs. | |
icon | string | Icon to use in the CMS page tree. This should be the full filename, relative to the webroot. | |
icon_class | string | Class attached to page icons in the CMS page tree. Also supports font-icon set. | |
nested_urls | |||
create_default_pages | |||
enforce_strict_hierarchy | boolean | ||
meta_generator | string | The value used for the meta generator tag. Leave blank to omit the tag. | |
base_plural_name | string | Plural form for SiteTree / Page classes. Not inherited by subclasses. | |
base_singular_name | string | Plural form for SiteTree / Page classes. Not inherited by subclasses. | |
description | string | Description of the class functionality, typically shown to a user when selecting which page type to create. Translated through {@link provideI18nEntities()}. | |
base_description | string | Description for Page and SiteTree classes, but not inherited by subclasses. |
Properties
bool | $destroyed | from DataObject | |
int | $ID | ID of the DataObject, 0 if the DataObject doesn't exist in database. | from DataObject |
int | $OldID | ID of object, if deleted | from DataObject |
string | $Title | ||
string | $ClassName | Class name of the DataObject | from DataObject |
string | $LastEdited | Date and time of DataObject's last modification. | from DataObject |
string | $Created | Date and time of DataObject creation. | from DataObject |
string | $ObsoleteClassName | If ClassName no longer exists this will be set to the legacy value | from DataObject |
string | $URLSegment | ||
string | $MenuTitle | ||
string | $Content | HTML content of the page. | |
string | $MetaDescription | ||
string | $ExtraMeta | ||
string | $ShowInMenus | ||
string | $ShowInSearch | ||
string | $Sort | Integer value denoting the sort order. | |
string | $ReportClass | ||
bool | $HasBrokenFile | True if this page has a broken file shortcode | |
bool | $HasBrokenLink | True if this page has a broken page shortcode |
Methods
Attempts to locate and call a method dynamically added to a class at runtime if a default cannot be located
Return the names of all the methods available on this object
Add an extension to a specific class.
No description
Get extra config sources for this class
Return TRUE if a class has a specified extension.
Calls a method if available on both this object and all applied {@link Extensions}, and then attempts to merge all results into an array
Run the given function on all of this object's extensions. Note that this method originally returned void, so if you wanted to return results, you're hosed
Get an extension instance attached to this object by name.
Returns TRUE if this object instance has a specific extension applied in {@link $extension_instances}. Extension instances are initialized at constructor time, meaning if you use {@link add_extension()} afterwards, the added extension will just be added to new instances of the extended class. Use the static method {@link has_extension()} to check if a class (not an instance) has a specific extension.
Get all extension instances for this specific object instance.
An implementation of the factory method, allows you to create an instance of a class
Creates a class instance by the "singleton" design pattern.
Get a configuration accessor for this class. Short hand for Config::inst()->get($this->class, .
Gets the uninherited value for the given config option
Construct a new DataObject.
Check if a field exists on this object or its failover.
Get the value of a property/field on this object. This will check if a method called get{$property} exists, then check if a field is available using {@link ViewableData::getField()}, then fall back on a failover object.
Set a property/field on this object. This will check for the existence of a method called set{$property}, then use the {@link ViewableData::setField()} method.
Set a failover object to attempt to get data from if it is not present on this object.
Returns true if the given field exists in a database column on any of
the objects tables and optionally look up a dynamic getter with
get
Set the value of the field Called by {@link __set()} and any setFieldName() methods you might create.
Merge some arbitrary data in with this object. This method returns a {@link ViewableData_Customised} instance with references to both this and the new custom data.
Return the "casting helper" (a piece of PHP code that when evaluated creates a casted value object) for a field on this object. This helper will be a subclass of DBField.
Get the class name a field on this object will be casted to.
Return the string-format type for the given field.
Render this object into the template, and get the result as a string. You can pass one of the following as the $template parameter: - a template name (e.g. Page) - an array of possible template names - the first valid one will be used - an SSViewer instance
Get the value of a field on this object, automatically inserting the value into any available casting objects that have been specified.
A simple wrapper around {@link ViewableData::obj()} that automatically caches the result so it can be used again without re-running the method.
Returns true if the given method/parameter has a value (Uses the DBField::hasValue if the parameter is a database field)
Get the string value of a field on this object that has been suitable escaped to be inserted directly into a template.
Get an array of XML-escaped values by field name
Return a single-item iterator so you can iterate over the fields of a single record.
Find appropriate templates for SSViewer to use to render this object
When rendering some objects it is necessary to iterate over the object being rendered, to do this, you need access to itself.
Get part of the current classes ancestry to be used as a CSS class.
Return debug information about this object that can be rendered into a template
Create a duplicate of this node. Can duplicate many_many relations
Return obsolete class name, if this is no longer a valid class
Set the ClassName attribute. {@link $class} is also updated.
Create a new instance of a different class from this object's record.
Returns TRUE if all values (other than "ID") are considered empty (by weak boolean comparison).
Default singular name for page / sitetree
Get the translated user friendly singular name of this DataObject same as singular_name() but runs it through the translating function
Default plural name for page / sitetree
Get the translated user friendly plural name of this DataObject Same as plural_name but runs it through the translation function Translation string is in the form: $this->class.PLURALNAME Example: Page.PLURALNAME
Standard implementation of a title/label for a specific record. Tries to find properties 'Title' or 'Name', and falls back to the 'ID'. Useful to provide user-friendly identification of a record, e.g. in errormessages or UI-selections.
Returns the associated database record - in this case, the object itself.
Update a number of fields on this object, given a map of the desired changes.
Pass changes as a map, and try to get automatic casting for these fields.
Merges data and relations from another object of same class, without conflict resolution. Allows to specify which dataset takes priority in case its not empty.
Validate the current object.
Find all objects that will be cascade deleted if this object is deleted
Load the default values in from the self::$defaults array.
Writes all changes to this object to the database.
Write the cached components to the database. Cached components could refer to two different instances of the same record.
Delete the record with the given ID.
Return a unary component object from a one to one relationship, as a DataObject.
Returns a one-to-many relation as a HasManyList
Find the foreign class of a relation on this DataObject, regardless of the relation type.
Given a relation name, determine the relation type
Given a relation declared on a remote class, generate a substitute component for the opposite side of the relation.
Returns a many-to-many component, as a ManyManyList.
Return the class of a one-to-one component. If $component is null, return all of the one-to-one components and their classes. If the selected has_one is a polymorphic field then 'DataObject' will be returned for the type.
Returns the class of a remote belongs_to relationship. If no component is specified a map of all components and their class name will be returned.
Gets the class of a one-to-many relationship. If no $component is specified then an array of all the one-to-many relationships and their classes will be returned.
Return the many-to-many extra fields specification.
This returns an array (if it exists) describing the database extensions that are required, or false if none
Generates a SearchContext to be used for building and processing a generic search form for properties on this object.
Determine which properties on the DataObject are searchable, and map them to their default {@link FormField} representations. Used for scaffolding a searchform for {@link ModelAdmin}.
Scaffold a simple edit form for all properties on this dataobject, based on default {@link FormField} mapping in {@link DBField::scaffoldFormField()}.
Returns a FieldList with which to create the main editing form.
Get the actions available in the CMS for this page - eg Save, Publish.
Used for simple frontend forms without relation editing or {@link TabSet} behaviour. Uses {@link scaffoldFormFields()} by default. To customize, either overload this method in your subclass, or extend it by {@link DataExtension->updateFrontEndFields()}.
Return the fields that have changed since the last write.
Uses {@link getChangedFields()} to determine if fields have been changed since loading them from the database.
Set the value of the field, using a casting object.
Returns true if the given field exists as a database column
Process tri-state responses from permission-alterting extensions. The extensions are expected to return one of three values:
Return the DBField object that represents the given field.
Traverses to a DBField referenced by relationships between data objects.
Traverses to a field referenced by relationships between data objects, returning the value The path to the related field is specified with dot separated syntax (eg: Parent.Child.Child.FieldName)
Temporary hack to return an association name, based on class, to get around the mangle of having to deal with reverse lookup of relationships to determine autogenerated foreign keys.
Return all objects matching the filter sub-classes are automatically selected and included
Return the first item matching the given query.
Flush the cached results for all relations (has_one, has_many, many_many) Also clears any cached aggregate data.
Flush the get_one global cache and destroy associated objects.
Clear the permissions cache for SiteTree
Return the given element, searching by ID.
Get list of parameters that should be inherited to relations on this object
Add default records to database.
Get the default searchable fields for this object, as defined in the $searchable_fields list. If searchable fields are not defined on the data object, uses a default selection of summary fields.
No description
Get a human-readable label for a single field, see {@link fieldLabels()} for more details.
Defines a default list of filters for the search context.
Temporarily disable subclass access in data object qeur
Overloaded to also provide entities for 'Page' class which is usually located in custom code, hence textcollector picks it up for the wrong folder.
If selected through a many_many through relation, this is the instance of the joined record
Find objects in the given relationships, merging them into the given list
Helper method to merge owned/owning items into a list.
Fetches the {@link SiteTree} object that maps to a link.
Return a subclass map of SiteTree that shouldn't be hidden through {@link SiteTree::$hide_ancestor}
Replace a "[sitetree_link id=n]" shortcode with a link to the page with the corresponding ID.
Return the link for this {@link SiteTree} object, with the {@link Director::baseURL()} included.
Get the absolute URL for this page, including protocol and host.
Base link used for previewing. Defaults to absolute URL, in order to account for domain changes, e.g. on multi site setups. Does not contain hints about the stage, see {@link SilverStripeNavigator} for details.
To determine preview mechanism (e.g. embedded / iframe)
Return the link for this {@link SiteTree} object relative to the SilverStripe root.
Get the absolute URL for this page on the Live site.
Generates a link to edit this page in the CMS.
Return a CSS identifier generated from this page's link.
Returns true if this is the currently active page being used to handle this request.
Check if this page is in the currently active section (e.g. it is either current or one of its children is currently being viewed).
Check if the parent of this page has been removed (or made otherwise unavailable), and is still referenced by this child. Any such orphaned page may still require access via the CMS, but should not be shown as accessible to external users.
Return "link" or "current" depending on if this is the {@link SiteTree::isCurrent()} current page.
Return "link" or "section" depending on if this is the {@link SiteTree::isSeciton()} current section.
Return "link", "current" or "section" depending on if this page is the current page, or not on the current page but in the current section.
Check if this page is in the given current section.
Duplicates each child of this node recursively and returns the top-level duplicate node.
Duplicate this node and its children as a child of the node with the given ID
Return a breadcrumb trail to this page. Excludes "hidden" pages (with ShowInMenus=0) by default.
Returns a list of breadcrumbs for the current page.
No description
No description
Return a string of the form "parent - page" or "grandparent - parent - page" using page titles
This function should return true if the current user can add children to this page. It can be overloaded to customise the security model for an application.
Stub method to get the site config, unless the current class can provide an alternate.
No description
Collate selected descendants of this page.
Return attributes for various meta tags, plus a title tag, in a keyed array.
Return the title, description, keywords and language metatags.
Returns the object that contains the content that a user would associate with this page.
Trigger synchronisation of link tracking
No description
No description
Flushes the member specific cache for creatable children
Returns true if this object has a URLSegment value that does not conflict with any other objects. This method checks for: - A page with the same URLSegment that has a conflict - Conflicts with actions on the parent page - A conflict caused by a root page having the same URLSegment as a class name
Generate a URL segment based on the title provided.
Gets the URL segment for the latest draft version of this page.
Gets the URL segment for the currently published version of this page.
Get the back-link tracking objects that link to this page
Returns the pages that depend on this page. This includes virtual pages, pages that link to it, etc.
Return all virtual pages that link to this page.
Returns fields related to configuration aspects on this record, e.g. access control. See {@link getCMSFields()} for content-related fields.
No description
Update draft dependant pages
Restore the content in the active copy of this SiteTree page to the stage site.
Check if this page is new - that is, if it has yet to have been written to the database.
Returns an array of the class names of classes that are allowed to be children of this class.
Gets a list of the page types that can be created under this specific page, including font icons
Returns the class name of the default class for children of this page.
Returns the class name of the default class for the parent of this page.
Get the title for use in menus for this page. If the MenuTitle field is set it returns that, else it returns the Title field.
Set the menu title for this page.
A flag provides the user with additional data about the current page status, for example a "removed from draft" status. Each page can have more than one status flag. Returns a map of a unique key to a (localized) title for the flag. The unique key can be reused as a CSS class. Use the 'updateStatusFlags' extension point to customize the flags.
Returns the CSS class used for the page icon in the site tree.
getTreeTitle will return three html DOM elements, an empty with the class 'jstree-pageicon' in front, following by a wrapping around its MenuTitle, then following by a indicating its publication status.
Returns the page in the current page stack of the given level. Level(1) will return the main menu item that we're currently inside, etc.
Gets the depth of this page in the sitetree, where 1 is the root level
Find the controller name by our convention of {$ModelClass}Controller Can be overriden by config variable
Return the CSS classes to apply to this node in the CMS tree.
Stops extendCMSFields() being called on getCMSFields(). This is useful when you need access to fields added by subclasses of SiteTree in a extension. Call before calling parent::getCMSFields(), and reenable afterwards.
Reenables extendCMSFields() being called on getCMSFields() after it has been disabled by disableCMSFieldsExtensions().
Return a map of permission codes to add to the dropdown shown in the Security section of the CMS.
Generate link to this page's icon
Get description for this page type
Get localised description for this page
Returns 'root' if the current page has no parent, or 'subpage' otherwise
Clear the creatableChildren cache on flush
No description
List of groups that can view this object.
List of groups that can edit this object.
No description
Details
in CustomMethods at line 50
mixed
__call(string $method, array $arguments)
Attempts to locate and call a method dynamically added to a class at runtime if a default cannot be located
You can add extra methods to a class using {@link Extensions}, {@link Object::createMethod()} or {@link Object::addWrapperMethod()}
in CustomMethods at line 144
bool
hasMethod(string $method)
Return TRUE if a method exists on this object
This should be used rather than PHP's inbuild method_exists() as it takes into account methods added via extensions
in CustomMethods at line 172
array
allMethodNames(bool $custom = false)
Return the names of all the methods available on this object
in Extensible at line 163
static bool
add_extension(string $classOrExtension, string $extension = null)
Add an extension to a specific class.
The preferred method for adding extensions is through YAML config, since it avoids autoloading the class, and is easier to override in more specific configurations.
As an alternative, extensions can be added to a specific class directly in the {@link Object::$extensions} array. See {@link SiteTree::$extensions} for examples. Keep in mind that the extension will only be applied to new instances, not existing ones (including all instances created through {@link singleton()}).
in Extensible at line 224
static
remove_extension(string $extension)
Remove an extension from a class.
Note: This will not remove extensions from parent classes, and must be called directly on the class assigned the extension.
Keep in mind that this won't revert any datamodel additions of the extension at runtime, unless its used before the schema building kicks in (in your _config.php). Doesn't remove the extension from any {@link Object} instances which are already created, but will have an effect on new extensions. Clears any previously created singletons through {@link singleton()} to avoid side-effects from stale extension information.
in Extensible at line 264
static array
get_extensions(string $class = null, bool $includeArgumentString = false)
in Extensible at line 298
static array|null
get_extra_config_sources(string $class = null)
Get extra config sources for this class
in Extensible at line 359
static bool
has_extension(string $classOrExtension, string $requiredExtension = null, boolean $strict = false)
Return TRUE if a class has a specified extension.
This supports backwards-compatible format (static Object::has_extension($requiredExtension)) and new format ($object->has_extension($class, $requiredExtension))
in Extensible at line 395
array
invokeWithExtensions(string $method, mixed $arguments)
Calls a method if available on both this object and all applied {@link Extensions}, and then attempts to merge all results into an array
in Extensible at line 424
array
extend(string $method, mixed $arguments)
Run the given function on all of this object's extensions. Note that this method originally returned void, so if you wanted to return results, you're hosed
Currently returns an array, with an index resulting every time the function is called. Only adds returns if they're not NULL, to avoid bogus results from methods just defined on the parent extension. This is important for permission-checks through extend, as they use min() to determine if any of the returns is FALSE. As min() doesn't do type checking, an included NULL return would fail the permission checks.
The extension methods are defined during {@link __construct()} in {@link defineMethods()}.
in Extensible at line 465
Extension|null
getExtensionInstance(string $extension)
Get an extension instance attached to this object by name.
in Extensible at line 494
bool
hasExtension(string $extension)
Returns TRUE if this object instance has a specific extension applied in {@link $extension_instances}. Extension instances are initialized at constructor time, meaning if you use {@link add_extension()} afterwards, the added extension will just be added to new instances of the extended class. Use the static method {@link has_extension()} to check if a class (not an instance) has a specific extension.
Caution: Don't use singleton(
in Extensible at line 508
Extension[]
getExtensionInstances()
Get all extension instances for this specific object instance.
See {@link get_extensions()} to get all applied extension classes for this class (not the instance).
This method also provides lazy-population of the extension_instances property.
in Injectable at line 26
static Injectable
create(array $args)
An implementation of the factory method, allows you to create an instance of a class
This method will defer class substitution to the Injector API, which can be customised via the Config API to declare substitution classes.
This can be called in one of two ways - either calling via the class directly, or calling on Object and passing the class name as the first parameter. The following are equivalent: $list = DataList::create('SiteTree'); $list = SiteTree::get();
in Injectable at line 43
static Injectable
singleton(string $class = null)
Creates a class instance by the "singleton" design pattern.
It will always return the same instance for this class, which can be used for performance reasons and as a simple way to access instance methods which don't rely on instance data (e.g. the custom SilverStripe static handling).
in Configurable at line 20
static Config_ForClass
config()
Get a configuration accessor for this class. Short hand for Config::inst()->get($this->class, .
....).
in Configurable at line 32
mixed
stat(string $name)
deprecated
deprecated 5.0 Use ->config()->get() instead
Get inherited config value
in Configurable at line 44
mixed
uninherited(string $name)
Gets the uninherited value for the given config option
in Configurable at line 57
$this
set_stat(string $name, mixed $value)
deprecated
deprecated 5.0 Use ->config()->set() instead
Update the config value for a given property
in DataObject at line 327
__construct(array|null $record = null, boolean $isSingleton = false, array $queryParams = array())
Construct a new DataObject.
in ViewableData at line 106
bool
__isset(string $property)
Check if a field exists on this object or its failover.
Note that, unlike the core isset() implementation, this will return true if the property is defined and set to null.
in ViewableData at line 129
mixed
__get(string $property)
Get the value of a property/field on this object. This will check if a method called get{$property} exists, then check if a field is available using {@link ViewableData::getField()}, then fall back on a failover object.
in ViewableData at line 152
__set(string $property, mixed $value)
Set a property/field on this object. This will check for the existence of a method called set{$property}, then use the {@link ViewableData::setField()} method.
in ViewableData at line 167
setFailover(ViewableData $failover)
Set a failover object to attempt to get data from if it is not present on this object.
in ViewableData at line 183
ViewableData|null
getFailover()
Get the current failover object if set
in DataObject at line 2827
bool
hasField(string $field)
Returns true if the given field exists in a database column on any of
the objects tables and optionally look up a dynamic getter with
get
in DataObject at line 2470
mixed
getField(string $field)
Gets the value of a field.
Called by {@link __get()} and any getFieldName() methods you might create.
in DataObject at line 2688
$this
setField(string $fieldName, mixed $val)
Set the value of the field Called by {@link __set()} and any setFieldName() methods you might create.
in DataObject at line 717
defineMethods()
Adds methods from the extensions.
Called by Object::__construct() once per class.
in ViewableData at line 258
ViewableData_Customised
customise(array|ViewableData $data)
Merge some arbitrary data in with this object. This method returns a {@link ViewableData_Customised} instance with references to both this and the new custom data.
Note that any fields you specify will take precedence over the fields on this object.
in DataObject at line 755
bool
exists()
Returns true if this object "exists", i.e., has a sensible value.
The default behaviour for a DataObject is to return true if the object exists in the database, you can override this in subclasses.
in ViewableData at line 289
string
__toString()
in ViewableData at line 297
ViewableData
getCustomisedObj()
in ViewableData at line 305
setCustomisedObj(ViewableData $object)
in DataObject at line 2798
string
castingHelper(string $field)
Return the "casting helper" (a piece of PHP code that when evaluated creates a casted value object) for a field on this object. This helper will be a subclass of DBField.
in ViewableData at line 352
string
castingClass(string $field)
Get the class name a field on this object will be casted to.
in ViewableData at line 365
string
escapeTypeForField(string $field)
Return the string-format type for the given field.
in ViewableData at line 389
DBHTMLText
renderWith(string|array|SSViewer $template, array $customFields = null)
Render this object into the template, and get the result as a string. You can pass one of the following as the $template parameter: - a template name (e.g. Page) - an array of possible template names - the first valid one will be used - an SSViewer instance
in ViewableData at line 471
Object|DBField
obj(string $fieldName, array $arguments = [], bool $cache = false, string $cacheName = null)
Get the value of a field on this object, automatically inserting the value into any available casting objects that have been specified.
in ViewableData at line 516
Object|DBField
cachedCall(string $field, array $arguments = [], string $identifier = null)
A simple wrapper around {@link ViewableData::obj()} that automatically caches the result so it can be used again without re-running the method.
in DataObject at line 4091
bool
hasValue(string $field, array $arguments = null, bool $cache = true)
Returns true if the given method/parameter has a value (Uses the DBField::hasValue if the parameter is a database field)
in ViewableData at line 545
string
XML_val(string $field, array $arguments = [], bool $cache = false)
Get the string value of a field on this object that has been suitable escaped to be inserted directly into a template.
in ViewableData at line 558
array
getXMLValues(array $fields)
Get an array of XML-escaped values by field name
in ViewableData at line 579
ArrayIterator
getIterator()
Return a single-item iterator so you can iterate over the fields of a single record.
This is useful so you can use a single record inside a <% control %> block in a template - and then use to access individual fields on this object.
in DataObject at line 2458
array
getViewerTemplates(string $suffix = '')
Find appropriate templates for SSViewer to use to render this object
in ViewableData at line 603
ViewableData
Me()
When rendering some objects it is necessary to iterate over the object being rendered, to do this, you need access to itself.
in ViewableData at line 620
string
ThemeDir()
deprecated
deprecated 4.0.0:5.0.0 Use $resourcePath or $resourceURL template helpers instead
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. .
This method should only be used when a theme is currently active. However, it will fall over to the current project directory.
in ViewableData at line 647
string
CSSClasses(string $stopAtClass = self::class)
Get part of the current classes ancestry to be used as a CSS class.
This method returns an escaped string of CSS classes representing the current classes ancestry until it hits a stop point - e.g. "Page DataObject ViewableData".
in ViewableData at line 676
ViewableData_Debugger
Debug()
Return debug information about this object that can be rendered into a template
in DataObject at line 312
static DataObjectSchema
getSchema()
Get schema object
in DataObject at line 408
destroy()
Destroy all of this objects dependant objects and local caches.
You'll need to call this to get the memory of an object that has components or extensions freed.
in DataObject at line 425
DataObject
duplicate(bool $doWrite = true, array|null|false $relations = null)
Create a duplicate of this node. Can duplicate many_many relations
in DataObject at line 631
string
getObsoleteClassName()
Return obsolete class name, if this is no longer a valid class
in DataObject at line 645
string
getClassName()
Gets name of this class
in DataObject at line 664
$this
setClassName(string $className)
Set the ClassName attribute. {@link $class} is also updated.
Warning: This will produce an inconsistent record, as the object instance will not automatically switch to the new subclass. Please use {@link newClassInstance()} for this purpose, or destroy and reinstanciate the record.
in DataObject at line 692
DataObject
newClassInstance(string $newClassName)
Create a new instance of a different class from this object's record.
This is useful when dynamically changing the type of an instance. Specifically, it ensures that the instance of the class is a match for the className of the record. Don't set the {@link DataObject->class} or {@link DataObject->ClassName} property manually before calling this method, as it will confuse change detection.
If the new class is different to the original class, defaults are populated again because this will only occur automatically on instantiation of a DataObject if there is no record, or the record has no ID. In this case, we do have an ID but we still need to repopulate the defaults.
in DataObject at line 766
boolean
isEmpty()
Returns TRUE if all values (other than "ID") are considered empty (by weak boolean comparison).
in DataObject at line 794
string
i18n_pluralise(string $count)
Pluralise this item given a specific count.
E.g. "0 Pages", "1 File", "3 Images"
at line 3064
string
singular_name()
Default singular name for page / sitetree
in DataObject at line 835
string
i18n_singular_name()
Get the translated user friendly singular name of this DataObject same as singular_name() but runs it through the translating function
Translating string is in the form: $this->class.SINGULARNAME Example: Page.SINGULARNAME
at line 3078
string
plural_name()
Default plural name for page / sitetree
in DataObject at line 870
string
i18n_plural_name()
Get the translated user friendly plural name of this DataObject Same as plural_name but runs it through the translation function Translation string is in the form: $this->class.PLURALNAME Example: Page.PLURALNAME
in DataObject at line 892
string
getTitle()
Standard implementation of a title/label for a specific record. Tries to find properties 'Title' or 'Name', and falls back to the 'ID'. Useful to provide user-friendly identification of a record, e.g. in errormessages or UI-selections.
Overload this method to have a more specialized implementation,
e.g. for an Address record this could be:
function getTitle() {
return "{$this->StreetNumber} {$this->StreetName} {$this->City}";
}
in DataObject at line 911
DataObject
data()
Returns the associated database record - in this case, the object itself.
This is included so that you can call $dataOrController->data() and get a DataObject all the time.
in DataObject at line 921
array
toMap()
Convert this object to a map.
in DataObject at line 935
array
getQueriedDatabaseFields()
Return all currently fetched database fields.
This function is similar to toMap() but doesn't trigger the lazy-loading of all unfetched fields. Obviously, this makes it a lot faster.
in DataObject at line 955
DataObject
update(array $data)
Update a number of fields on this object, given a map of the desired changes.
The field names can be simple names, or you can use a dot syntax to access $has_one relations. For example, array("Author.FirstName" => "Jim") will set $this->Author()->FirstName to "Jim".
Doesn't write the main object, but if you use the dot syntax, it will write() the related objects that it alters.
When using this method with user supplied data, it's very important to whitelist the allowed keys.
in DataObject at line 1016
DataObject
castedUpdate(array $data)
Pass changes as a map, and try to get automatic casting for these fields.
Doesn't write to the database. To write the data, use the write() method.
in DataObject at line 1045
Boolean
merge(DataObject $rightObj, string $priority = 'right', bool $includeRelations = true, bool $overwriteWithEmpty = false)
Merges data and relations from another object of same class, without conflict resolution. Allows to specify which dataset takes priority in case its not empty.
has_one-relations are just transferred with priority 'right'. has_many and many_many-relations are added regardless of priority.
Caution: has_many/many_many relations are moved rather than duplicated, meaning they are not connected to the merged object any longer. Caution: Just saves updated has_many/many_many relations to the database, doesn't write the updated object itself (just writes the object-properties). Caution: Does not delete the merged object. Caution: Does now overwrite Created date on the original object.
in DataObject at line 1126
$this
forceChange()
Forces the record to think that all its data has changed.
Doesn't write to the database. Force-change preseved until next write. Existing CHANGE_VALUE or CHANGE_STRICT values are preserved.
at line 1655
ValidationResult
validate()
Validate the current object.
By default, there is no validation - objects are always valid! However, you can overload this method in your DataObject sub-classes to specify custom validation, or use the hook through DataExtension.
Invalid objects won't be able to be written - a warning will be thrown and no write will occur. onBeforeWrite() and onAfterWrite() won't get called either.
It is expected that you call validate() in your own application to test that an object is valid before attempting a write, and respond appropriately if it isn't.
in DataObject at line 1170
ValidationResult
doValidate()
Public accessor for {see DataObject::validate()}
in DataObject at line 1218
ArrayList
findCascadeDeletes(bool $recursive = true, ArrayList $list = null)
Find all objects that will be cascade deleted if this object is deleted
Notes: - If this object is versioned, objects will only be searched in the same stage as the given record. - This will only be useful prior to deletion, as post-deletion this record will no longer exist.
in DataObject at line 1258
DataObject
populateDefaults()
Load the default values in from the self::$defaults array.
Will traverse the defaults of the current class and all its parent classes. Called by the constructor when creating new records.
in DataObject at line 1517
write(boolean $showDebug = false, boolean $forceInsert = false, boolean $forceWrite = false, boolean|array $writeComponents = false)
Writes all changes to this object to the database.
- It will insert a record whenever ID isn't set, otherwise update.
- All relevant tables will be updated.
- $this->onBeforeWrite() gets called beforehand.
- Extensions such as Versioned will ammend the database-write to ensure that a version is saved.
in DataObject at line 1584
writeRelations()
Writes cached relation lists to the database, if possible
in DataObject at line 1607
DataObject
writeComponents(bool $recursive = false, array $skip = [])
Write the cached components to the database. Cached components could refer to two different instances of the same record.
in DataObject at line 1674
delete()
Delete this data object.
$this->onBeforeDelete() gets called. Note that in Versioned objects, both Stage and Live will be deleted.
in DataObject at line 1718
static
delete_by_id(string $className, int $id)
Delete the record with the given ID.
in DataObject at line 1736
array
getClassAncestry()
Get the class ancestry, including the current class name.
The ancestry will be returned as an array of class names, where the 0th element will be the class that inherits directly from DataObject, and the last element will be the current class.
in DataObject at line 1750
DataObject
getComponent(string $componentName)
Return a unary component object from a one to one relationship, as a DataObject.
If no component is available, an 'empty component' will be returned for non-polymorphic relations, or for polymorphic relations with a class set.
in DataObject at line 1830
$this
setComponent(string $componentName, DataObject|null $item)
Assign an item to the given component
in DataObject at line 1876
HasManyList|UnsavedRelationList
getComponents(string $componentName, int|array $id = null)
Returns a one-to-many relation as a HasManyList
in DataObject at line 1922
string
getRelationClass(string $relationName)
Find the foreign class of a relation on this DataObject, regardless of the relation type.
in DataObject at line 1959
string
getRelationType(string $component)
Given a relation name, determine the relation type
in DataObject at line 1989
DataList|DataObject
inferReciprocalComponent(string $remoteClass, string $remoteRelation)
Given a relation declared on a remote class, generate a substitute component for the opposite side of the relation.
Notes on behaviour: - This can still be used on components that are defined on both sides, but do not need to be. - All has_ones on remote class will be treated as local has_many, even if they are belongs_to - Polymorphic relationships do not have two natural endpoints (only on one side) and thus attempting to infer them will return nothing. - Cannot be used on unsaved objects.
in DataObject at line 2089
ManyManyList|UnsavedRelationList
getManyManyComponents(string $componentName, int|array $id = null)
Returns a many-to-many component, as a ManyManyList.
in DataObject at line 2158
string|array
hasOne()
Return the class of a one-to-one component. If $component is null, return all of the one-to-one components and their classes. If the selected has_one is a polymorphic field then 'DataObject' will be returned for the type.
in DataObject at line 2171
string|array
belongsTo(bool $classOnly = true)
Returns the class of a remote belongs_to relationship. If no component is specified a map of all components and their class name will be returned.
in DataObject at line 2189
string|array|false
hasMany(bool $classOnly = true)
Gets the class of a one-to-many relationship. If no $component is specified then an array of all the one-to-many relationships and their classes will be returned.
in DataObject at line 2207
array|null
manyManyExtraFields()
Return the many-to-many extra fields specification.
If you don't specify a component name, it returns all extra fields for all components available.
in DataObject at line 2220
array|null
manyMany()
Return information about a many-to-many component.
The return value is an array of (parentclass, childclass). If $component is null, then all many-many components are returned.
in DataObject at line 2237
array|false
database_extensions(string $class)
This returns an array (if it exists) describing the database extensions that are required, or false if none
This is experimental, and is currently only a Postgres-specific enhancement.
in DataObject at line 2253
SearchContext
getDefaultSearchContext()
Generates a SearchContext to be used for building and processing a generic search form for properties on this object.
in DataObject at line 2277
FieldList
scaffoldSearchFields(array $_params = null)
Determine which properties on the DataObject are searchable, and map them to their default {@link FormField} representations. Used for scaffolding a searchform for {@link ModelAdmin}.
Some additional logic is included for switching field labels, based on how generic or specific the field type is.
Used by {@link SearchContext}.
in DataObject at line 2352
FieldList
scaffoldFormFields(array $_params = null)
Scaffold a simple edit form for all properties on this dataobject, based on default {@link FormField} mapping in {@link DBField::scaffoldFormField()}.
Field labels/titles will be auto generated from {@link DataObject::fieldLabels()}.
at line 1921
FieldList
getCMSFields()
Returns a FieldList with which to create the main editing form.
You can override this in your child classes to add extra fields - first get the parent fields using parent::getCMSFields(), then use addFieldToTab() on the FieldList.
See {@link getSettingsFields()} for a different set of fields concerned with configuration aspects on the record, e.g. access control.
at line 2319
FieldList
getCMSActions()
Get the actions available in the CMS for this page - eg Save, Publish.
Frontend scripts and styles know how to handle the following FormFields: - top-level FormActions appear as standalone buttons - top-level CompositeField with FormActions within appear as grouped buttons - TabSet & Tabs appear as a drop ups - FormActions within the Tab are restyled as links - major actions can provide alternate states for richer presentation (see ssui.button widget extension)
in DataObject at line 2450
FieldList
getFrontEndFields(array $params = null)
Used for simple frontend forms without relation editing or {@link TabSet} behaviour. Uses {@link scaffoldFormFields()} by default. To customize, either overload this method in your subclass, or extend it by {@link DataExtension->updateFrontEndFields()}.
in DataObject at line 2601
array
getChangedFields(boolean|array $databaseFieldsOnly = false, int $changeLevel = self::CHANGE_STRICT)
Return the fields that have changed since the last write.
The change level affects what the functions defines as "changed": - Level CHANGE_STRICT (integer 1) will return strict changes, even !== ones. - Level CHANGE_VALUE (integer 2) is more lenient, it will only return real data changes, for example a change from 0 to null would not be included.
Example return:
array(
'Title' = array('before' => 'Home', 'after' => 'Home-Changed', 'level' => DataObject::CHANGE_VALUE)
)
in DataObject at line 2669
boolean
isChanged(string $fieldName = null, int $changeLevel = self::CHANGE_STRICT)
Uses {@link getChangedFields()} to determine if fields have been changed since loading them from the database.
in DataObject at line 2780
$this
setCastedField(string $fieldName, mixed $value)
Set the value of the field, using a casting object.
This is useful when you aren't sure that a date is in SQL format, for example. setCastedField() can also be used, by forms, to set related data. For example, uploaded images can be saved into the Image table.
in DataObject at line 2846
boolean
hasDatabaseField(string $field)
Returns true if the given field exists as a database column
at line 1007
boolean
can(string $perm, Member $member = null, array $context = array())
This function should return true if the current user can execute this action. It can be overloaded to customise the security model for an application.
Slightly altered from parent behaviour in {@link DataObject->can()}: - Checks for existence of a method named "can<$perm>()" on the object - Calls decorators and only returns for FALSE "vetoes" - Falls back to {@link Permission::check()} - Does NOT check for many-many relations named "Can<$perm>"
in DataObject at line 2907
boolean|null
extendedCan(string $methodName, Member|int $member, array $context = array())
Process tri-state responses from permission-alterting extensions. The extensions are expected to return one of three values:
- false: Disallow this permission, regardless of what other extensions say
- true: Allow this permission, as long as no other extensions return false
- NULL: Don't affect the outcome
This method itself returns a tri-state value, and is designed to be used like this:
$extended = $this->extendedCan('canDoSomething', $member);
if($extended !== null) return $extended;
else return $normalValue;
at line 1089
boolean
canView(Member $member = null)
This function should return true if the current user can view this page. It can be overloaded to customise the security model for an application.
Denies permission if any of the following conditions is true: - canView() on any extension returns false - "CanViewType" directive is set to "Inherit" and any parent page return false for canView() - "CanViewType" directive is set to "LoggedInUsers" and no user is logged in - "CanViewType" directive is set to "OnlyTheseUsers" and user is not in the given groups
at line 1285
boolean
canEdit(Member $member = null)
This function should return true if the current user can edit this page. It can be overloaded to customise the security model for an application.
Denies permission if any of the following conditions is true: - canEdit() on any extension returns false - canView() return false - "CanEditType" directive is set to "Inherit" and any parent page return false for canEdit() - "CanEditType" directive is set to "LoggedInUsers" and no user is logged in or doesn't have the CMS_Access_CMSMAIN permission code - "CanEditType" directive is set to "OnlyTheseUsers" and user is not in the given groups
at line 1186
boolean
canDelete(Member $member = null)
This function should return true if the current user can delete this page. It can be overloaded to customise the security model for an application.
Denies permission if any of the following conditions is true: - canDelete() returns false on any extension - canEdit() returns false - any descendant page returns false for canDelete()
at line 1230
boolean
canCreate(Member $member = null, array $context = array())
This function should return true if the current user can create new pages of this class, regardless of class. It can be overloaded to customise the security model for an application.
By default, permission to create at the root level is based on the SiteConfig configuration, and permission to create beneath a parent is based on the ability to edit that parent page.
Use {@link canAddChildren()} to control behaviour of creating children under this page.
in DataObject at line 2983
string
debug()
Debugging used by Debug::show()
in DataObject at line 3006
DBField
dbObject(string $fieldName)
Return the DBField object that represents the given field.
This works similarly to obj() with 2 key differences: - it still returns an object even when the field has no value. - it only matches fields and not methods - it matches foreign keys generated by has_one relationships, eg, "ParentID"
in DataObject at line 3054
mixed
relObject(string $fieldPath)
Traverses to a DBField referenced by relationships between data objects.
The path to the related field is specified with dot separated syntax (eg: Parent.Child.Child.FieldName).
If a relation is blank, this will return null instead. If a relation name is invalid (e.g. non-relation on a parent) this can throw a LogicException.
in DataObject at line 3092
mixed
relField(string $fieldName)
Traverses to a field referenced by relationships between data objects, returning the value The path to the related field is specified with dot separated syntax (eg: Parent.Child.Child.FieldName)
in DataObject at line 3119
string
getReverseAssociation(string $className)
Temporary hack to return an association name, based on class, to get around the mangle of having to deal with reverse lookup of relationships to determine autogenerated foreign keys.
in DataObject at line 3160
static DataList
get(string $callerClass = null, string|array $filter = "", string|array $sort = "", string $join = "", string|array $limit = null, string $containerClass = DataList::class)
Return all objects matching the filter sub-classes are automatically selected and included
in DataObject at line 3225
static DataObject|null
get_one(string|null $callerClass = null, string|array $filter = "", boolean $cache = true, string $orderBy = "")
Return the first item matching the given query.
All calls to get_one() are cached.
The filter argument supports parameterised queries (see SQLSelect::addWhere() for syntax examples). Because
of that (and differently from e.g. DataList::filter()) you need to manually escape the field names:
$member = DataObject::get_one('Member', [ '"FirstName"' => 'John' ]);
at line 1629
DataObject
flushCache(boolean $persistent = true)
Flush the cached results for all relations (has_one, has_many, many_many) Also clears any cached aggregate data.
in DataObject at line 3291
static
flush_and_destroy_cache()
Flush the get_one global cache and destroy associated objects.
at line 3176
static
reset()
Clear the permissions cache for SiteTree
in DataObject at line 3332
static DataObject
get_by_id(string|int $classOrID, int|bool $idOrCache = null, boolean $cache = true)
Return the given element, searching by ID.
This can be called either via DataObject::get_by_id(MyClass::class, $id)
or MyClass::get_by_id($id)
in DataObject at line 3354
string
baseTable()
Get the name of the base table for this object
in DataObject at line 3364
string
baseClass()
Get the base class for this object
in DataObject at line 3380
array
getSourceQueryParams()
in DataObject at line 3390
array
getInheritableQueryParams()
Get list of parameters that should be inherited to relations on this object
in DataObject at line 3401
setSourceQueryParams(array $array)
in DataObject at line 3411
setSourceQueryParam(string $key, string $value)
in DataObject at line 3421
string
getSourceQueryParam(string $key)
in DataObject at line 3436
requireTable()
Check the database schema and update it as necessary.
at line 1490
requireDefaultRecords()
Add default records to database.
This function is called whenever the database is built, after the database tables have all been created. Overload this to add default records when the database is built, but make sure you call parent::requireDefaultRecords().
in DataObject at line 3566
array
searchableFields()
Get the default searchable fields for this object, as defined in the $searchable_fields list. If searchable fields are not defined on the data object, uses a default selection of summary fields.
at line 2267
array
fieldLabels(boolean $includerelations = true)
in DataObject at line 3732
string
fieldLabel(string $name)
Get a human-readable label for a single field, see {@link fieldLabels()} for more details.
in DataObject at line 3745
array
summaryFields()
Get the default summary fields for this object.
in DataObject at line 3804
array
defaultSearchFilters()
Defines a default list of filters for the search context.
If a filter class mapping is defined on the data object, it is constructed here. Otherwise, the default filter specified in {@link DBField} is used.
in DataObject at line 3825
boolean
isInDB()
in DataObject at line 3838
static
disable_subclass_access()
Temporarily disable subclass access in data object qeur
in DataObject at line 3843
static
enable_subclass_access()
at line 3151
array
provideI18nEntities()
Overloaded to also provide entities for 'Page' class which is usually located in custom code, hence textcollector picks it up for the wrong folder.
in DataObject at line 4107
DataObject
getJoin()
If selected through a many_many through relation, this is the instance of the joined record
in DataObject at line 4119
$this
setJoin(DataObject $object, string $alias = null)
Set joining object
in DataObject at line 4142
ArrayList
findRelatedObjects(string $source, bool $recursive = true, ArrayList $list = null)
Find objects in the given relationships, merging them into the given list
in DataObject at line 4191
ArrayList
mergeRelatedObjects(ArrayList $list, mixed $items)
Helper method to merge owned/owning items into a list.
Items already present in the list will be skipped.
at line 396
static SiteTree
get_by_link(string $link, bool $cache = true)
Fetches the {@link SiteTree} object that maps to a link.
If you have enabled {@link SiteTree::config()->nested_urls} on this site, then you can use a nested link such as "about-us/staff/", and this function will traverse down the URL chain and grab the appropriate link.
Note that if no model can be found, this method will fall over to a extended alternateGetByLink method provided by a extension attached to {@link SiteTree}
at line 491
static array
page_type_classes()
Return a subclass map of SiteTree that shouldn't be hidden through {@link SiteTree::$hide_ancestor}
at line 537
static string
link_shortcode_handler(array $arguments, string $content = null, ShortcodeParser $parser = null)
Replace a "[sitetree_link id=n]" shortcode with a link to the page with the corresponding ID.
at line 569
string
Link(string $action = null)
Return the link for this {@link SiteTree} object, with the {@link Director::baseURL()} included.
at line 583
string
AbsoluteLink(string $action = null)
Get the absolute URL for this page, including protocol and host.
at line 599
string
PreviewLink(string $action = null)
Base link used for previewing. Defaults to absolute URL, in order to account for domain changes, e.g. on multi site setups. Does not contain hints about the stage, see {@link SilverStripeNavigator} for details.
at line 611
string
getMimeType()
To determine preview mechanism (e.g. embedded / iframe)
at line 628
string
RelativeLink(string $action = null)
Return the link for this {@link SiteTree} object relative to the SilverStripe root.
By default, if this page is the current home page, and there is no action specified then this will return a link to the root of the site. However, if you set the $action parameter to TRUE then the link will not be rewritten and returned in its full form.
at line 663
string
getAbsoluteLiveLink(bool $includeStageEqualsLive = true)
Get the absolute URL for this page on the Live site.
at line 690
string
CMSEditLink()
Generates a link to edit this page in the CMS.
at line 705
string
ElementName()
Return a CSS identifier generated from this page's link.
at line 715
bool
isCurrent()
Returns true if this is the currently active page being used to handle this request.
at line 733
bool
isSection()
Check if this page is in the currently active section (e.g. it is either current or one of its children is currently being viewed).
at line 747
bool
isOrphaned()
Check if the parent of this page has been removed (or made otherwise unavailable), and is still referenced by this child. Any such orphaned page may still require access via the CMS, but should not be shown as accessible to external users.
at line 764
string
LinkOrCurrent()
Return "link" or "current" depending on if this is the {@link SiteTree::isCurrent()} current page.
at line 774
string
LinkOrSection()
Return "link" or "section" depending on if this is the {@link SiteTree::isSeciton()} current section.
at line 785
string
LinkingMode()
Return "link", "current" or "section" depending on if this page is the current page, or not on the current page but in the current section.
at line 802
bool
InSection(string $sectionName)
Check if this page is in the given current section.
at line 820
onBeforeDuplicate(SiteTree $original, bool $doWrite)
Reset Sort on duped page
at line 830
SiteTree
duplicateWithChildren()
Duplicates each child of this node recursively and returns the top-level duplicate node.
at line 858
duplicateAsChild(int $id)
Duplicate this node and its children as a child of the node with the given ID
at line 877
string
Breadcrumbs(int $maxDepth = 20, boolean $unlinked = false, boolean|string $stopAtPageType = false, boolean $showHidden = false, string $delimiter = '»')
Return a breadcrumb trail to this page. Excludes "hidden" pages (with ShowInMenus=0) by default.
at line 898
ArrayList
getBreadcrumbItems(int $maxDepth = 20, boolean|string $stopAtPageType = false, boolean $showHidden = false)
Returns a list of breadcrumbs for the current page.
at line 926
setParent(SiteTree|int $item)
Make this page a child of another page.
If the parent page does not exist, resolve it to a valid ID before updating this page's reference.
at line 943
SiteTree
getParent()
Get the parent of this page.
at line 956
$this
setCreatableChildrenCache(CacheInterface $cache)
at line 966
CacheInterface
getCreatableChildrenCache()
at line 978
string
NestedTitle(int $level = 2, string $separator = " - ")
Return a string of the form "parent - page" or "grandparent - parent - page" using page titles
at line 1048
bool
canAddChildren(Member|int $member = null)
This function should return true if the current user can add children to this page. It can be overloaded to customise the security model for an application.
Denies permission if any of the following conditions is true: - alternateCanAddChildren() on a extension returns false - canEdit() is not granted - There are no classes defined in {@link $allowed_children}
at line 1150
bool
canPublish(Member $member = null)
Check if this page can be published
at line 1312
SiteConfig
getSiteConfig()
Stub method to get the site config, unless the current class can provide an alternate.
at line 1325
static PermissionChecker
getPermissionChecker()
at line 1340
bool
collateDescendants(string $condition, array $collator)
Collate selected descendants of this page.
{@link $condition} will be evaluated on each descendant, and if it is succeeds, that item will be added to the $collator array.
at line 1381
array
MetaComponents()
Return attributes for various meta tags, plus a title tag, in a keyed array.
Array structure corresponds to arguments for HTML::create_tag(). Example:
$tags['description'] = [ // html tag type, if omitted defaults to 'meta' 'tag' => 'meta', // attributes of html tag 'attributes' => [ 'name' => 'description', 'content' => $this->customMetaDescription(), ], // content of html tag. (True meta tags don't contain content) 'content' => null ];
at line 1444
string
MetaTags(bool $includeTitle = true)
Return the title, description, keywords and language metatags.