Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like SiteTree often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use SiteTree, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
93 | class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvider,CMSPreviewable { |
||
94 | |||
95 | /** |
||
96 | * Indicates what kind of children this page type can have. |
||
97 | * This can be an array of allowed child classes, or the string "none" - |
||
98 | * indicating that this page type can't have children. |
||
99 | * If a classname is prefixed by "*", such as "*Page", then only that |
||
100 | * class is allowed - no subclasses. Otherwise, the class and all its |
||
101 | * subclasses are allowed. |
||
102 | * To control allowed children on root level (no parent), use {@link $can_be_root}. |
||
103 | * |
||
104 | * Note that this setting is cached when used in the CMS, use the "flush" query parameter to clear it. |
||
105 | * |
||
106 | * @config |
||
107 | * @var array |
||
108 | */ |
||
109 | private static $allowed_children = array("SilverStripe\\CMS\\Model\\SiteTree"); |
||
110 | |||
111 | /** |
||
112 | * The default child class for this page. |
||
113 | * Note: Value might be cached, see {@link $allowed_chilren}. |
||
114 | * |
||
115 | * @config |
||
116 | * @var string |
||
117 | */ |
||
118 | private static $default_child = "Page"; |
||
119 | |||
120 | /** |
||
121 | * Default value for SiteTree.ClassName enum |
||
122 | * {@see DBClassName::getDefault} |
||
123 | * |
||
124 | * @config |
||
125 | * @var string |
||
126 | */ |
||
127 | private static $default_classname = "Page"; |
||
|
|||
128 | |||
129 | /** |
||
130 | * The default parent class for this page. |
||
131 | * Note: Value might be cached, see {@link $allowed_chilren}. |
||
132 | * |
||
133 | * @config |
||
134 | * @var string |
||
135 | */ |
||
136 | private static $default_parent = null; |
||
137 | |||
138 | /** |
||
139 | * Controls whether a page can be in the root of the site tree. |
||
140 | * Note: Value might be cached, see {@link $allowed_chilren}. |
||
141 | * |
||
142 | * @config |
||
143 | * @var bool |
||
144 | */ |
||
145 | private static $can_be_root = true; |
||
146 | |||
147 | /** |
||
148 | * List of permission codes a user can have to allow a user to create a page of this type. |
||
149 | * Note: Value might be cached, see {@link $allowed_chilren}. |
||
150 | * |
||
151 | * @config |
||
152 | * @var array |
||
153 | */ |
||
154 | private static $need_permission = null; |
||
155 | |||
156 | /** |
||
157 | * If you extend a class, and don't want to be able to select the old class |
||
158 | * in the cms, set this to the old class name. Eg, if you extended Product |
||
159 | * to make ImprovedProduct, then you would set $hide_ancestor to Product. |
||
160 | * |
||
161 | * @config |
||
162 | * @var string |
||
163 | */ |
||
164 | private static $hide_ancestor = null; |
||
165 | |||
166 | private static $db = array( |
||
167 | "URLSegment" => "Varchar(255)", |
||
168 | "Title" => "Varchar(255)", |
||
169 | "MenuTitle" => "Varchar(100)", |
||
170 | "Content" => "HTMLText", |
||
171 | "MetaDescription" => "Text", |
||
172 | "ExtraMeta" => "HTMLFragment(['whitelist' => ['meta', 'link']])", |
||
173 | "ShowInMenus" => "Boolean", |
||
174 | "ShowInSearch" => "Boolean", |
||
175 | "Sort" => "Int", |
||
176 | "HasBrokenFile" => "Boolean", |
||
177 | "HasBrokenLink" => "Boolean", |
||
178 | "ReportClass" => "Varchar", |
||
179 | "CanViewType" => "Enum('Anyone, LoggedInUsers, OnlyTheseUsers, Inherit', 'Inherit')", |
||
180 | "CanEditType" => "Enum('LoggedInUsers, OnlyTheseUsers, Inherit', 'Inherit')", |
||
181 | ); |
||
182 | |||
183 | private static $indexes = array( |
||
184 | "URLSegment" => true, |
||
185 | ); |
||
186 | |||
187 | private static $many_many = array( |
||
188 | "ViewerGroups" => "SilverStripe\\Security\\Group", |
||
189 | "EditorGroups" => "SilverStripe\\Security\\Group", |
||
190 | ); |
||
191 | |||
192 | private static $has_many = array( |
||
193 | "VirtualPages" => "SilverStripe\\CMS\\Model\\VirtualPage.CopyContentFrom" |
||
194 | ); |
||
195 | |||
196 | private static $owned_by = array( |
||
197 | "VirtualPages" |
||
198 | ); |
||
199 | |||
200 | private static $casting = array( |
||
201 | "Breadcrumbs" => "HTMLFragment", |
||
202 | "LastEdited" => "Datetime", |
||
203 | "Created" => "Datetime", |
||
204 | 'Link' => 'Text', |
||
205 | 'RelativeLink' => 'Text', |
||
206 | 'AbsoluteLink' => 'Text', |
||
207 | 'CMSEditLink' => 'Text', |
||
208 | 'TreeTitle' => 'HTMLFragment', |
||
209 | 'MetaTags' => 'HTMLFragment', |
||
210 | ); |
||
211 | |||
212 | private static $defaults = array( |
||
213 | "ShowInMenus" => 1, |
||
214 | "ShowInSearch" => 1, |
||
215 | "CanViewType" => "Inherit", |
||
216 | "CanEditType" => "Inherit" |
||
217 | ); |
||
218 | |||
219 | private static $table_name = 'SiteTree'; |
||
220 | |||
221 | private static $versioning = array( |
||
222 | "Stage", "Live" |
||
223 | ); |
||
224 | |||
225 | private static $default_sort = "\"Sort\""; |
||
226 | |||
227 | /** |
||
228 | * If this is false, the class cannot be created in the CMS by regular content authors, only by ADMINs. |
||
229 | * @var boolean |
||
230 | * @config |
||
231 | */ |
||
232 | private static $can_create = true; |
||
233 | |||
234 | /** |
||
235 | * Icon to use in the CMS page tree. This should be the full filename, relative to the webroot. |
||
236 | * Also supports custom CSS rule contents (applied to the correct selector for the tree UI implementation). |
||
237 | * |
||
238 | * @see CMSMain::generateTreeStylingCSS() |
||
239 | * @config |
||
240 | * @var string |
||
241 | */ |
||
242 | private static $icon = null; |
||
243 | |||
244 | /** |
||
245 | * @config |
||
246 | * @var string Description of the class functionality, typically shown to a user |
||
247 | * when selecting which page type to create. Translated through {@link provideI18nEntities()}. |
||
248 | */ |
||
249 | private static $description = 'Generic content page'; |
||
250 | |||
251 | private static $extensions = array( |
||
252 | 'SilverStripe\\ORM\\Hierarchy\\Hierarchy', |
||
253 | 'SilverStripe\\ORM\\Versioning\\Versioned', |
||
254 | "SilverStripe\\CMS\\Model\\SiteTreeLinkTracking" |
||
255 | ); |
||
256 | |||
257 | private static $searchable_fields = array( |
||
258 | 'Title', |
||
259 | 'Content', |
||
260 | ); |
||
261 | |||
262 | private static $field_labels = array( |
||
263 | 'URLSegment' => 'URL' |
||
264 | ); |
||
265 | |||
266 | /** |
||
267 | * @config |
||
268 | */ |
||
269 | private static $nested_urls = true; |
||
270 | |||
271 | /** |
||
272 | * @config |
||
273 | */ |
||
274 | private static $create_default_pages = true; |
||
275 | |||
276 | /** |
||
277 | * This controls whether of not extendCMSFields() is called by getCMSFields. |
||
278 | */ |
||
279 | private static $runCMSFieldsExtensions = true; |
||
280 | |||
281 | /** |
||
282 | * Cache for canView/Edit/Publish/Delete permissions. |
||
283 | * Keyed by permission type (e.g. 'edit'), with an array |
||
284 | * of IDs mapped to their boolean permission ability (true=allow, false=deny). |
||
285 | * See {@link batch_permission_check()} for details. |
||
286 | */ |
||
287 | private static $cache_permissions = array(); |
||
288 | |||
289 | /** |
||
290 | * @config |
||
291 | * @var boolean |
||
292 | */ |
||
293 | private static $enforce_strict_hierarchy = true; |
||
294 | |||
295 | /** |
||
296 | * The value used for the meta generator tag. Leave blank to omit the tag. |
||
297 | * |
||
298 | * @config |
||
299 | * @var string |
||
300 | */ |
||
301 | private static $meta_generator = 'SilverStripe - http://silverstripe.org'; |
||
302 | |||
303 | protected $_cache_statusFlags = null; |
||
304 | |||
305 | /** |
||
306 | * Fetches the {@link SiteTree} object that maps to a link. |
||
307 | * |
||
308 | * If you have enabled {@link SiteTree::config()->nested_urls} on this site, then you can use a nested link such as |
||
309 | * "about-us/staff/", and this function will traverse down the URL chain and grab the appropriate link. |
||
310 | * |
||
311 | * Note that if no model can be found, this method will fall over to a extended alternateGetByLink method provided |
||
312 | * by a extension attached to {@link SiteTree} |
||
313 | * |
||
314 | * @param string $link The link of the page to search for |
||
315 | * @param bool $cache True (default) to use caching, false to force a fresh search from the database |
||
316 | * @return SiteTree |
||
317 | */ |
||
318 | static public function get_by_link($link, $cache = true) { |
||
319 | if(trim($link, '/')) { |
||
320 | $link = trim(Director::makeRelative($link), '/'); |
||
321 | } else { |
||
322 | $link = RootURLController::get_homepage_link(); |
||
323 | } |
||
324 | |||
325 | $parts = preg_split('|/+|', $link); |
||
326 | |||
327 | // Grab the initial root level page to traverse down from. |
||
328 | $URLSegment = array_shift($parts); |
||
329 | $conditions = array('"SiteTree"."URLSegment"' => rawurlencode($URLSegment)); |
||
330 | if(self::config()->nested_urls) { |
||
331 | $conditions[] = array('"SiteTree"."ParentID"' => 0); |
||
332 | } |
||
333 | /** @var SiteTree $sitetree */ |
||
334 | $sitetree = DataObject::get_one(self::class, $conditions, $cache); |
||
335 | |||
336 | /// Fall back on a unique URLSegment for b/c. |
||
337 | if( !$sitetree |
||
338 | && self::config()->nested_urls |
||
339 | && $sitetree = DataObject::get_one(self::class, array( |
||
340 | '"SiteTree"."URLSegment"' => $URLSegment |
||
341 | ), $cache) |
||
342 | ) { |
||
343 | return $sitetree; |
||
344 | } |
||
345 | |||
346 | // Attempt to grab an alternative page from extensions. |
||
347 | if(!$sitetree) { |
||
348 | $parentID = self::config()->nested_urls ? 0 : null; |
||
349 | |||
350 | View Code Duplication | if($alternatives = static::singleton()->extend('alternateGetByLink', $URLSegment, $parentID)) { |
|
351 | foreach($alternatives as $alternative) { |
||
352 | if($alternative) { |
||
353 | $sitetree = $alternative; |
||
354 | } |
||
355 | } |
||
356 | } |
||
357 | |||
358 | if(!$sitetree) { |
||
359 | return null; |
||
360 | } |
||
361 | } |
||
362 | |||
363 | // Check if we have any more URL parts to parse. |
||
364 | if(!self::config()->nested_urls || !count($parts)) { |
||
365 | return $sitetree; |
||
366 | } |
||
367 | |||
368 | // Traverse down the remaining URL segments and grab the relevant SiteTree objects. |
||
369 | foreach($parts as $segment) { |
||
370 | $next = DataObject::get_one(self::class, array( |
||
371 | '"SiteTree"."URLSegment"' => $segment, |
||
372 | '"SiteTree"."ParentID"' => $sitetree->ID |
||
373 | ), |
||
374 | $cache |
||
375 | ); |
||
376 | |||
377 | if(!$next) { |
||
378 | $parentID = (int) $sitetree->ID; |
||
379 | |||
380 | View Code Duplication | if($alternatives = static::singleton()->extend('alternateGetByLink', $segment, $parentID)) { |
|
381 | foreach($alternatives as $alternative) if($alternative) $next = $alternative; |
||
382 | } |
||
383 | |||
384 | if(!$next) { |
||
385 | return null; |
||
386 | } |
||
387 | } |
||
388 | |||
389 | $sitetree->destroy(); |
||
390 | $sitetree = $next; |
||
391 | } |
||
392 | |||
393 | return $sitetree; |
||
394 | } |
||
395 | |||
396 | /** |
||
397 | * Return a subclass map of SiteTree that shouldn't be hidden through {@link SiteTree::$hide_ancestor} |
||
398 | * |
||
399 | * @return array |
||
400 | */ |
||
401 | public static function page_type_classes() { |
||
402 | $classes = ClassInfo::getValidSubClasses(); |
||
403 | |||
404 | $baseClassIndex = array_search(self::class, $classes); |
||
405 | if($baseClassIndex !== false) { |
||
406 | unset($classes[$baseClassIndex]); |
||
407 | } |
||
408 | |||
409 | $kill_ancestors = array(); |
||
410 | |||
411 | // figure out if there are any classes we don't want to appear |
||
412 | foreach($classes as $class) { |
||
413 | $instance = singleton($class); |
||
414 | |||
415 | // do any of the progeny want to hide an ancestor? |
||
416 | if($ancestor_to_hide = $instance->stat('hide_ancestor')) { |
||
417 | // note for killing later |
||
418 | $kill_ancestors[] = $ancestor_to_hide; |
||
419 | } |
||
420 | } |
||
421 | |||
422 | // If any of the descendents don't want any of the elders to show up, cruelly render the elders surplus to |
||
423 | // requirements |
||
424 | if($kill_ancestors) { |
||
425 | $kill_ancestors = array_unique($kill_ancestors); |
||
426 | foreach($kill_ancestors as $mark) { |
||
427 | // unset from $classes |
||
428 | $idx = array_search($mark, $classes, true); |
||
429 | if ($idx !== false) { |
||
430 | unset($classes[$idx]); |
||
431 | } |
||
432 | } |
||
433 | } |
||
434 | |||
435 | return $classes; |
||
436 | } |
||
437 | |||
438 | /** |
||
439 | * Replace a "[sitetree_link id=n]" shortcode with a link to the page with the corresponding ID. |
||
440 | * |
||
441 | * @param array $arguments |
||
442 | * @param string $content |
||
443 | * @param ShortcodeParser $parser |
||
444 | * @return string |
||
445 | */ |
||
446 | static public function link_shortcode_handler($arguments, $content = null, $parser = null) { |
||
447 | if(!isset($arguments['id']) || !is_numeric($arguments['id'])) { |
||
448 | return null; |
||
449 | } |
||
450 | |||
451 | /** @var SiteTree $page */ |
||
452 | if ( |
||
453 | !($page = DataObject::get_by_id(self::class, $arguments['id'])) // Get the current page by ID. |
||
454 | && !($page = Versioned::get_latest_version(self::class, $arguments['id'])) // Attempt link to old version. |
||
455 | ) { |
||
456 | return null; // There were no suitable matches at all. |
||
457 | } |
||
458 | |||
459 | /** @var SiteTree $page */ |
||
460 | $link = Convert::raw2att($page->Link()); |
||
461 | |||
462 | if($content) { |
||
463 | return sprintf('<a href="%s">%s</a>', $link, $parser->parse($content)); |
||
464 | } else { |
||
465 | return $link; |
||
466 | } |
||
467 | } |
||
468 | |||
469 | /** |
||
470 | * Return the link for this {@link SiteTree} object, with the {@link Director::baseURL()} included. |
||
471 | * |
||
472 | * @param string $action Optional controller action (method). |
||
473 | * Note: URI encoding of this parameter is applied automatically through template casting, |
||
474 | * don't encode the passed parameter. Please use {@link Controller::join_links()} instead to |
||
475 | * append GET parameters. |
||
476 | * @return string |
||
477 | */ |
||
478 | public function Link($action = null) { |
||
481 | |||
482 | /** |
||
483 | * Get the absolute URL for this page, including protocol and host. |
||
484 | * |
||
485 | * @param string $action See {@link Link()} |
||
486 | * @return string |
||
487 | */ |
||
488 | public function AbsoluteLink($action = null) { |
||
495 | |||
496 | /** |
||
497 | * Base link used for previewing. Defaults to absolute URL, in order to account for domain changes, e.g. on multi |
||
498 | * site setups. Does not contain hints about the stage, see {@link SilverStripeNavigator} for details. |
||
499 | * |
||
500 | * @param string $action See {@link Link()} |
||
501 | * @return string |
||
502 | */ |
||
503 | public function PreviewLink($action = null) { |
||
513 | |||
514 | public function getMimeType() { |
||
515 | return 'text/html'; |
||
516 | } |
||
517 | |||
518 | /** |
||
519 | * Return the link for this {@link SiteTree} object relative to the SilverStripe root. |
||
520 | * |
||
521 | * By default, if this page is the current home page, and there is no action specified then this will return a link |
||
522 | * to the root of the site. However, if you set the $action parameter to TRUE then the link will not be rewritten |
||
523 | * and returned in its full form. |
||
524 | * |
||
525 | * @uses RootURLController::get_homepage_link() |
||
526 | * |
||
527 | * @param string $action See {@link Link()} |
||
528 | * @return string |
||
529 | */ |
||
530 | public function RelativeLink($action = null) { |
||
531 | if($this->ParentID && self::config()->nested_urls) { |
||
532 | $parent = $this->Parent(); |
||
533 | // If page is removed select parent from version history (for archive page view) |
||
534 | if((!$parent || !$parent->exists()) && !$this->isOnDraft()) { |
||
535 | $parent = Versioned::get_latest_version(self::class, $this->ParentID); |
||
536 | } |
||
537 | $base = $parent->RelativeLink($this->URLSegment); |
||
538 | } elseif(!$action && $this->URLSegment == RootURLController::get_homepage_link()) { |
||
539 | // Unset base for root-level homepages. |
||
540 | // Note: Homepages with action parameters (or $action === true) |
||
541 | // need to retain their URLSegment. |
||
542 | $base = null; |
||
543 | } else { |
||
544 | $base = $this->URLSegment; |
||
545 | } |
||
546 | |||
547 | $this->extend('updateRelativeLink', $base, $action); |
||
548 | |||
549 | // Legacy support: If $action === true, retain URLSegment for homepages, |
||
550 | // but don't append any action |
||
551 | if($action === true) $action = null; |
||
552 | |||
553 | return Controller::join_links($base, '/', $action); |
||
554 | } |
||
555 | |||
556 | /** |
||
557 | * Get the absolute URL for this page on the Live site. |
||
558 | * |
||
559 | * @param bool $includeStageEqualsLive Whether to append the URL with ?stage=Live to force Live mode |
||
560 | * @return string |
||
561 | */ |
||
562 | public function getAbsoluteLiveLink($includeStageEqualsLive = true) { |
||
563 | $oldReadingMode = Versioned::get_reading_mode(); |
||
564 | Versioned::set_stage(Versioned::LIVE); |
||
565 | /** @var SiteTree $live */ |
||
566 | $live = Versioned::get_one_by_stage(self::class, Versioned::LIVE, array( |
||
567 | '"SiteTree"."ID"' => $this->ID |
||
568 | )); |
||
569 | if($live) { |
||
570 | $link = $live->AbsoluteLink(); |
||
571 | if($includeStageEqualsLive) { |
||
572 | $link = Controller::join_links($link, '?stage=Live'); |
||
573 | } |
||
574 | } else { |
||
575 | $link = null; |
||
576 | } |
||
577 | |||
578 | Versioned::set_reading_mode($oldReadingMode); |
||
579 | return $link; |
||
580 | } |
||
581 | |||
582 | /** |
||
583 | * Generates a link to edit this page in the CMS. |
||
584 | * |
||
585 | * @return string |
||
586 | */ |
||
587 | public function CMSEditLink() { |
||
588 | $link = Controller::join_links( |
||
589 | CMSPageEditController::singleton()->Link('show'), |
||
590 | $this->ID |
||
591 | ); |
||
592 | return Director::absoluteURL($link); |
||
593 | } |
||
594 | |||
595 | |||
596 | /** |
||
597 | * Return a CSS identifier generated from this page's link. |
||
598 | * |
||
599 | * @return string The URL segment |
||
600 | */ |
||
601 | public function ElementName() { |
||
604 | |||
605 | /** |
||
606 | * Returns true if this is the currently active page being used to handle this request. |
||
607 | * |
||
608 | * @return bool |
||
609 | */ |
||
610 | public function isCurrent() { |
||
611 | $currentPage = Director::get_current_page(); |
||
612 | if ($currentPage instanceof ContentController) { |
||
613 | $currentPage = $currentPage->data(); |
||
614 | } |
||
615 | if($currentPage instanceof SiteTree) { |
||
616 | return $currentPage === $this || $currentPage->ID === $this->ID; |
||
617 | } |
||
618 | return false; |
||
619 | } |
||
620 | |||
621 | /** |
||
622 | * Check if this page is in the currently active section (e.g. it is either current or one of its children is |
||
623 | * currently being viewed). |
||
624 | * |
||
625 | * @return bool |
||
626 | */ |
||
627 | public function isSection() { |
||
632 | |||
633 | /** |
||
634 | * Check if the parent of this page has been removed (or made otherwise unavailable), and is still referenced by |
||
635 | * this child. Any such orphaned page may still require access via the CMS, but should not be shown as accessible |
||
636 | * to external users. |
||
637 | * |
||
638 | * @return bool |
||
639 | */ |
||
640 | public function isOrphaned() { |
||
641 | // Always false for root pages |
||
642 | if(empty($this->ParentID)) { |
||
643 | return false; |
||
644 | } |
||
645 | |||
646 | // Parent must exist and not be an orphan itself |
||
647 | $parent = $this->Parent(); |
||
648 | return !$parent || !$parent->exists() || $parent->isOrphaned(); |
||
649 | } |
||
650 | |||
651 | /** |
||
652 | * Return "link" or "current" depending on if this is the {@link SiteTree::isCurrent()} current page. |
||
653 | * |
||
654 | * @return string |
||
655 | */ |
||
656 | public function LinkOrCurrent() { |
||
659 | |||
660 | /** |
||
661 | * Return "link" or "section" depending on if this is the {@link SiteTree::isSeciton()} current section. |
||
662 | * |
||
663 | * @return string |
||
664 | */ |
||
665 | public function LinkOrSection() { |
||
666 | return $this->isSection() ? 'section' : 'link'; |
||
667 | } |
||
668 | |||
669 | /** |
||
670 | * Return "link", "current" or "section" depending on if this page is the current page, or not on the current page |
||
671 | * but in the current section. |
||
672 | * |
||
673 | * @return string |
||
674 | */ |
||
675 | public function LinkingMode() { |
||
684 | |||
685 | /** |
||
686 | * Check if this page is in the given current section. |
||
687 | * |
||
688 | * @param string $sectionName Name of the section to check |
||
689 | * @return bool True if we are in the given section |
||
690 | */ |
||
691 | public function InSection($sectionName) { |
||
692 | $page = Director::get_current_page(); |
||
693 | while($page && $page->exists()) { |
||
694 | if($sectionName == $page->URLSegment) { |
||
695 | return true; |
||
696 | } |
||
697 | $page = $page->Parent(); |
||
698 | } |
||
699 | return false; |
||
700 | } |
||
701 | |||
702 | /** |
||
703 | * Reset Sort on duped page |
||
704 | * |
||
705 | * @param SiteTree $original |
||
706 | * @param bool $doWrite |
||
707 | */ |
||
708 | public function onBeforeDuplicate($original, $doWrite) { |
||
711 | |||
712 | /** |
||
713 | * Duplicates each child of this node recursively and returns the top-level duplicate node. |
||
714 | * |
||
715 | * @return static The duplicated object |
||
716 | */ |
||
717 | public function duplicateWithChildren() { |
||
718 | /** @var SiteTree $clone */ |
||
719 | $clone = $this->duplicate(); |
||
720 | $children = $this->AllChildren(); |
||
721 | |||
722 | if($children) { |
||
736 | |||
737 | /** |
||
738 | * Duplicate this node and its children as a child of the node with the given ID |
||
739 | * |
||
740 | * @param int $id ID of the new node's new parent |
||
741 | */ |
||
742 | public function duplicateAsChild($id) { |
||
749 | |||
750 | /** |
||
751 | * Return a breadcrumb trail to this page. Excludes "hidden" pages (with ShowInMenus=0) by default. |
||
752 | * |
||
753 | * @param int $maxDepth The maximum depth to traverse. |
||
754 | * @param boolean $unlinked Whether to link page titles. |
||
755 | * @param boolean|string $stopAtPageType ClassName of a page to stop the upwards traversal. |
||
756 | * @param boolean $showHidden Include pages marked with the attribute ShowInMenus = 0 |
||
757 | * @return string The breadcrumb trail. |
||
758 | */ |
||
759 | public function Breadcrumbs($maxDepth = 20, $unlinked = false, $stopAtPageType = false, $showHidden = false) { |
||
767 | |||
768 | |||
769 | /** |
||
770 | * Returns a list of breadcrumbs for the current page. |
||
771 | * |
||
772 | * @param int $maxDepth The maximum depth to traverse. |
||
773 | * @param boolean|string $stopAtPageType ClassName of a page to stop the upwards traversal. |
||
774 | * @param boolean $showHidden Include pages marked with the attribute ShowInMenus = 0 |
||
775 | * |
||
776 | * @return ArrayList |
||
777 | */ |
||
778 | public function getBreadcrumbItems($maxDepth = 20, $stopAtPageType = false, $showHidden = false) { |
||
797 | |||
798 | |||
799 | /** |
||
800 | * Make this page a child of another page. |
||
801 | * |
||
802 | * If the parent page does not exist, resolve it to a valid ID before updating this page's reference. |
||
803 | * |
||
804 | * @param SiteTree|int $item Either the parent object, or the parent ID |
||
805 | */ |
||
806 | public function setParent($item) { |
||
814 | |||
815 | /** |
||
816 | * Get the parent of this page. |
||
817 | * |
||
818 | * @return SiteTree Parent of this page |
||
819 | */ |
||
820 | public function getParent() { |
||
826 | |||
827 | /** |
||
828 | * Return a string of the form "parent - page" or "grandparent - parent - page" using page titles |
||
829 | * |
||
830 | * @param int $level The maximum amount of levels to traverse. |
||
831 | * @param string $separator Seperating string |
||
832 | * @return string The resulting string |
||
833 | */ |
||
834 | public function NestedTitle($level = 2, $separator = " - ") { |
||
844 | |||
845 | /** |
||
846 | * This function should return true if the current user can execute this action. It can be overloaded to customise |
||
847 | * the security model for an application. |
||
848 | * |
||
849 | * Slightly altered from parent behaviour in {@link DataObject->can()}: |
||
850 | * - Checks for existence of a method named "can<$perm>()" on the object |
||
851 | * - Calls decorators and only returns for FALSE "vetoes" |
||
852 | * - Falls back to {@link Permission::check()} |
||
853 | * - Does NOT check for many-many relations named "Can<$perm>" |
||
854 | * |
||
855 | * @uses DataObjectDecorator->can() |
||
856 | * |
||
857 | * @param string $perm The permission to be checked, such as 'View' |
||
858 | * @param Member $member The member whose permissions need checking. Defaults to the currently logged in user. |
||
859 | * @param array $context Context argument for canCreate() |
||
860 | * @return bool True if the the member is allowed to do the given action |
||
861 | */ |
||
862 | public function can($perm, $member = null, $context = array()) { |
||
879 | |||
880 | /** |
||
881 | * This function should return true if the current user can add children to this page. It can be overloaded to |
||
882 | * customise the security model for an application. |
||
883 | * |
||
884 | * Denies permission if any of the following conditions is true: |
||
885 | * - alternateCanAddChildren() on a extension returns false |
||
886 | * - canEdit() is not granted |
||
887 | * - There are no classes defined in {@link $allowed_children} |
||
888 | * |
||
889 | * @uses SiteTreeExtension->canAddChildren() |
||
890 | * @uses canEdit() |
||
891 | * @uses $allowed_children |
||
892 | * |
||
893 | * @param Member|int $member |
||
894 | * @return bool True if the current user can add children |
||
895 | */ |
||
896 | public function canAddChildren($member = null) { |
||
919 | |||
920 | /** |
||
921 | * This function should return true if the current user can view this page. It can be overloaded to customise the |
||
922 | * security model for an application. |
||
923 | * |
||
924 | * Denies permission if any of the following conditions is true: |
||
925 | * - canView() on any extension returns false |
||
926 | * - "CanViewType" directive is set to "Inherit" and any parent page return false for canView() |
||
927 | * - "CanViewType" directive is set to "LoggedInUsers" and no user is logged in |
||
928 | * - "CanViewType" directive is set to "OnlyTheseUsers" and user is not in the given groups |
||
929 | * |
||
930 | * @uses DataExtension->canView() |
||
931 | * @uses ViewerGroups() |
||
932 | * |
||
933 | * @param Member|int $member |
||
934 | * @return bool True if the current user can view this page |
||
935 | */ |
||
936 | public function canView($member = null) { |
||
985 | |||
986 | /** |
||
987 | * Check if this page can be published |
||
988 | * |
||
989 | * @param Member $member |
||
990 | * @return bool |
||
991 | */ |
||
992 | public function canPublish($member = null) { |
||
1010 | |||
1011 | /** |
||
1012 | * This function should return true if the current user can delete this page. It can be overloaded to customise the |
||
1013 | * security model for an application. |
||
1014 | * |
||
1015 | * Denies permission if any of the following conditions is true: |
||
1016 | * - canDelete() returns false on any extension |
||
1017 | * - canEdit() returns false |
||
1018 | * - any descendant page returns false for canDelete() |
||
1019 | * |
||
1020 | * @uses canDelete() |
||
1021 | * @uses SiteTreeExtension->canDelete() |
||
1022 | * @uses canEdit() |
||
1023 | * |
||
1024 | * @param Member $member |
||
1025 | * @return bool True if the current user can delete this page |
||
1026 | */ |
||
1027 | public function canDelete($member = null) { |
||
1050 | |||
1051 | /** |
||
1052 | * This function should return true if the current user can create new pages of this class, regardless of class. It |
||
1053 | * can be overloaded to customise the security model for an application. |
||
1054 | * |
||
1055 | * By default, permission to create at the root level is based on the SiteConfig configuration, and permission to |
||
1056 | * create beneath a parent is based on the ability to edit that parent page. |
||
1057 | * |
||
1058 | * Use {@link canAddChildren()} to control behaviour of creating children under this page. |
||
1059 | * |
||
1060 | * @uses $can_create |
||
1061 | * @uses DataExtension->canCreate() |
||
1062 | * |
||
1063 | * @param Member $member |
||
1064 | * @param array $context Optional array which may contain array('Parent' => $parentObj) |
||
1065 | * If a parent page is known, it will be checked for validity. |
||
1066 | * If omitted, it will be assumed this is to be created as a top level page. |
||
1067 | * @return bool True if the current user can create pages on this class. |
||
1068 | */ |
||
1069 | public function canCreate($member = null, $context = array()) { |
||
1070 | View Code Duplication | if(!$member || !(is_a($member, 'SilverStripe\\Security\\Member')) || is_numeric($member)) { |
|
1071 | $member = Member::currentUserID(); |
||
1072 | } |
||
1073 | |||
1074 | // Check parent (custom canCreate option for SiteTree) |
||
1075 | // Block children not allowed for this parent type |
||
1076 | $parent = isset($context['Parent']) ? $context['Parent'] : null; |
||
1077 | if($parent && !in_array(static::class, $parent->allowedChildren())) { |
||
1078 | return false; |
||
1079 | } |
||
1080 | |||
1081 | // Standard mechanism for accepting permission changes from extensions |
||
1082 | $extended = $this->extendedCan(__FUNCTION__, $member, $context); |
||
1083 | if($extended !== null) { |
||
1084 | return $extended; |
||
1085 | } |
||
1086 | |||
1087 | // Check permission |
||
1088 | if($member && Permission::checkMember($member, "ADMIN")) { |
||
1089 | return true; |
||
1090 | } |
||
1091 | |||
1092 | // Fall over to inherited permissions |
||
1093 | if($parent && $parent->exists()) { |
||
1094 | return $parent->canAddChildren($member); |
||
1095 | } else { |
||
1096 | // This doesn't necessarily mean we are creating a root page, but that |
||
1097 | // we don't know if there is a parent, so default to this permission |
||
1098 | return SiteConfig::current_site_config()->canCreateTopLevel($member); |
||
1099 | } |
||
1100 | } |
||
1101 | |||
1102 | /** |
||
1103 | * This function should return true if the current user can edit this page. It can be overloaded to customise the |
||
1104 | * security model for an application. |
||
1105 | * |
||
1106 | * Denies permission if any of the following conditions is true: |
||
1107 | * - canEdit() on any extension returns false |
||
1108 | * - canView() return false |
||
1109 | * - "CanEditType" directive is set to "Inherit" and any parent page return false for canEdit() |
||
1110 | * - "CanEditType" directive is set to "LoggedInUsers" and no user is logged in or doesn't have the |
||
1111 | * CMS_Access_CMSMAIN permission code |
||
1112 | * - "CanEditType" directive is set to "OnlyTheseUsers" and user is not in the given groups |
||
1113 | * |
||
1114 | * @uses canView() |
||
1115 | * @uses EditorGroups() |
||
1116 | * @uses DataExtension->canEdit() |
||
1117 | * |
||
1118 | * @param Member $member Set to false if you want to explicitly test permissions without a valid user (useful for |
||
1119 | * unit tests) |
||
1120 | * @return bool True if the current user can edit this page |
||
1121 | */ |
||
1122 | public function canEdit($member = null) { |
||
1151 | |||
1152 | /** |
||
1153 | * Stub method to get the site config, unless the current class can provide an alternate. |
||
1154 | * |
||
1155 | * @return SiteConfig |
||
1156 | */ |
||
1157 | public function getSiteConfig() { |
||
1165 | |||
1166 | /** |
||
1167 | * Pre-populate the cache of canEdit, canView, canDelete, canPublish permissions. This method will use the static |
||
1168 | * can_(perm)_multiple method for efficiency. |
||
1169 | * |
||
1170 | * @param string $permission The permission: edit, view, publish, approve, etc. |
||
1171 | * @param array $ids An array of page IDs |
||
1172 | * @param callable|string $batchCallback The function/static method to call to calculate permissions. Defaults |
||
1173 | * to 'SiteTree::can_(permission)_multiple' |
||
1174 | */ |
||
1175 | static public function prepopulate_permission_cache($permission = 'CanEditType', $ids, $batchCallback = null) { |
||
1187 | |||
1188 | /** |
||
1189 | * This method is NOT a full replacement for the individual can*() methods, e.g. {@link canEdit()}. Rather than |
||
1190 | * checking (potentially slow) PHP logic, it relies on the database group associations, e.g. the "CanEditType" field |
||
1191 | * plus the "SiteTree_EditorGroups" many-many table. By batch checking multiple records, we can combine the queries |
||
1192 | * efficiently. |
||
1193 | * |
||
1194 | * Caches based on $typeField data. To invalidate the cache, use {@link SiteTree::reset()} or set the $useCached |
||
1195 | * property to FALSE. |
||
1196 | * |
||
1197 | * @param array $ids Of {@link SiteTree} IDs |
||
1198 | * @param int $memberID Member ID |
||
1199 | * @param string $typeField A property on the data record, e.g. "CanEditType". |
||
1200 | * @param string $groupJoinTable A many-many table name on this record, e.g. "SiteTree_EditorGroups" |
||
1201 | * @param string $siteConfigMethod Method to call on {@link SiteConfig} for toplevel items, e.g. "canEdit" |
||
1202 | * @param string $globalPermission If the member doesn't have this permission code, don't bother iterating deeper |
||
1203 | * @param bool $useCached |
||
1204 | * @return array An map of {@link SiteTree} ID keys to boolean values |
||
1205 | */ |
||
1206 | public static function batch_permission_check($ids, $memberID, $typeField, $groupJoinTable, $siteConfigMethod, |
||
1334 | |||
1335 | /** |
||
1336 | * Get the 'can edit' information for a number of SiteTree pages. |
||
1337 | * |
||
1338 | * @param array $ids An array of IDs of the SiteTree pages to look up |
||
1339 | * @param int $memberID ID of member |
||
1340 | * @param bool $useCached Return values from the permission cache if they exist |
||
1341 | * @return array A map where the IDs are keys and the values are booleans stating whether the given page can be |
||
1342 | * edited |
||
1343 | */ |
||
1344 | static public function can_edit_multiple($ids, $memberID, $useCached = true) { |
||
1347 | |||
1348 | /** |
||
1349 | * Get the 'can edit' information for a number of SiteTree pages. |
||
1350 | * |
||
1351 | * @param array $ids An array of IDs of the SiteTree pages to look up |
||
1352 | * @param int $memberID ID of member |
||
1353 | * @param bool $useCached Return values from the permission cache if they exist |
||
1354 | * @return array |
||
1355 | */ |
||
1356 | static public function can_delete_multiple($ids, $memberID, $useCached = true) { |
||
1413 | |||
1414 | /** |
||
1415 | * Collate selected descendants of this page. |
||
1416 | * |
||
1417 | * {@link $condition} will be evaluated on each descendant, and if it is succeeds, that item will be added to the |
||
1418 | * $collator array. |
||
1419 | * |
||
1420 | * @param string $condition The PHP condition to be evaluated. The page will be called $item |
||
1421 | * @param array $collator An array, passed by reference, to collect all of the matching descendants. |
||
1422 | * @return bool |
||
1423 | */ |
||
1424 | public function collateDescendants($condition, &$collator) { |
||
1439 | |||
1440 | /** |
||
1441 | * Return the title, description, keywords and language metatags. |
||
1442 | * |
||
1443 | * @todo Move <title> tag in separate getter for easier customization and more obvious usage |
||
1444 | * |
||
1445 | * @param bool $includeTitle Show default <title>-tag, set to false for custom templating |
||
1446 | * @return string The XHTML metatags |
||
1447 | */ |
||
1448 | public function MetaTags($includeTitle = true) { |
||
1497 | |||
1498 | /** |
||
1499 | * Returns the object that contains the content that a user would associate with this page. |
||
1500 | * |
||
1501 | * Ordinarily, this is just the page itself, but for example on RedirectorPages or VirtualPages ContentSource() will |
||
1502 | * return the page that is linked to. |
||
1503 | * |
||
1504 | * @return $this |
||
1505 | */ |
||
1506 | public function ContentSource() { |
||
1509 | |||
1510 | /** |
||
1511 | * Add default records to database. |
||
1512 | * |
||
1513 | * This function is called whenever the database is built, after the database tables have all been created. Overload |
||
1514 | * this to add default records when the database is built, but make sure you call parent::requireDefaultRecords(). |
||
1515 | */ |
||
1516 | public function requireDefaultRecords() { |
||
1560 | |||
1561 | protected function onBeforeWrite() { |
||
1611 | |||
1612 | /** |
||
1613 | * Trigger synchronisation of link tracking |
||
1614 | * |
||
1615 | * {@see SiteTreeLinkTracking::augmentSyncLinkTracking} |
||
1616 | */ |
||
1617 | public function syncLinkTracking() { |
||
1620 | |||
1621 | public function onBeforeDelete() { |
||
1632 | |||
1633 | public function onAfterDelete() { |
||
1646 | |||
1647 | public function flushCache($persistent = true) { |
||
1651 | |||
1652 | public function validate() { |
||
1692 | |||
1693 | /** |
||
1694 | * Returns true if this object has a URLSegment value that does not conflict with any other objects. This method |
||
1695 | * checks for: |
||
1696 | * - A page with the same URLSegment that has a conflict |
||
1697 | * - Conflicts with actions on the parent page |
||
1698 | * - A conflict caused by a root page having the same URLSegment as a class name |
||
1699 | * |
||
1700 | * @return bool |
||
1701 | */ |
||
1702 | public function validURLSegment() { |
||
1736 | |||
1737 | /** |
||
1738 | * Generate a URL segment based on the title provided. |
||
1739 | * |
||
1740 | * If {@link Extension}s wish to alter URL segment generation, they can do so by defining |
||
1741 | * updateURLSegment(&$url, $title). $url will be passed by reference and should be modified. $title will contain |
||
1742 | * the title that was originally used as the source of this generated URL. This lets extensions either start from |
||
1743 | * scratch, or incrementally modify the generated URL. |
||
1744 | * |
||
1745 | * @param string $title Page title |
||
1746 | * @return string Generated url segment |
||
1747 | */ |
||
1748 | public function generateURLSegment($title){ |
||
1760 | |||
1761 | /** |
||
1762 | * Gets the URL segment for the latest draft version of this page. |
||
1763 | * |
||
1764 | * @return string |
||
1765 | */ |
||
1766 | public function getStageURLSegment() { |
||
1772 | |||
1773 | /** |
||
1774 | * Gets the URL segment for the currently published version of this page. |
||
1775 | * |
||
1776 | * @return string |
||
1777 | */ |
||
1778 | public function getLiveURLSegment() { |
||
1784 | |||
1785 | /** |
||
1786 | * Returns the pages that depend on this page. This includes virtual pages, pages that link to it, etc. |
||
1787 | * |
||
1788 | * @param bool $includeVirtuals Set to false to exlcude virtual pages. |
||
1789 | * @return ArrayList |
||
1790 | */ |
||
1791 | public function DependentPages($includeVirtuals = true) { |
||
1843 | |||
1844 | /** |
||
1845 | * Return all virtual pages that link to this page. |
||
1846 | * |
||
1847 | * @return DataList |
||
1848 | */ |
||
1849 | public function VirtualPages() { |
||
1859 | |||
1860 | /** |
||
1861 | * Returns a FieldList with which to create the main editing form. |
||
1862 | * |
||
1863 | * You can override this in your child classes to add extra fields - first get the parent fields using |
||
1864 | * parent::getCMSFields(), then use addFieldToTab() on the FieldList. |
||
1865 | * |
||
1866 | * See {@link getSettingsFields()} for a different set of fields concerned with configuration aspects on the record, |
||
1867 | * e.g. access control. |
||
1868 | * |
||
1869 | * @return FieldList The fields to be displayed in the CMS |
||
1870 | */ |
||
1871 | public function getCMSFields() { |
||
2047 | |||
2048 | |||
2049 | /** |
||
2050 | * Returns fields related to configuration aspects on this record, e.g. access control. See {@link getCMSFields()} |
||
2051 | * for content-related fields. |
||
2052 | * |
||
2053 | * @return FieldList |
||
2054 | */ |
||
2055 | public function getSettingsFields() { |
||
2162 | |||
2163 | /** |
||
2164 | * @param bool $includerelations A boolean value to indicate if the labels returned should include relation fields |
||
2165 | * @return array |
||
2166 | */ |
||
2167 | public function fieldLabels($includerelations = true) { |
||
2205 | |||
2206 | /** |
||
2207 | * Get the actions available in the CMS for this page - eg Save, Publish. |
||
2208 | * |
||
2209 | * Frontend scripts and styles know how to handle the following FormFields: |
||
2210 | * - top-level FormActions appear as standalone buttons |
||
2211 | * - top-level CompositeField with FormActions within appear as grouped buttons |
||
2212 | * - TabSet & Tabs appear as a drop ups |
||
2213 | * - FormActions within the Tab are restyled as links |
||
2214 | * - major actions can provide alternate states for richer presentation (see ssui.button widget extension) |
||
2215 | * |
||
2216 | * @return FieldList The available actions for this page. |
||
2217 | */ |
||
2218 | public function getCMSActions() { |
||
2374 | |||
2375 | public function onAfterPublish() { |
||
2383 | |||
2384 | /** |
||
2385 | * Update draft dependant pages |
||
2386 | */ |
||
2387 | public function onAfterRevertToLive() { |
||
2399 | |||
2400 | /** |
||
2401 | * Determine if this page references a parent which is archived, and not available in stage |
||
2402 | * |
||
2403 | * @return bool True if there is an archived parent |
||
2404 | */ |
||
2405 | protected function isParentArchived() { |
||
2415 | |||
2416 | /** |
||
2417 | * Restore the content in the active copy of this SiteTree page to the stage site. |
||
2418 | * |
||
2419 | * @return self |
||
2420 | */ |
||
2421 | public function doRestoreToStage() { |
||
2458 | |||
2459 | /** |
||
2460 | * Check if this page is new - that is, if it has yet to have been written to the database. |
||
2461 | * |
||
2462 | * @return bool |
||
2463 | */ |
||
2464 | public function isNew() { |
||
2475 | |||
2476 | /** |
||
2477 | * Get the class dropdown used in the CMS to change the class of a page. This returns the list of options in the |
||
2478 | * dropdown as a Map from class name to singular name. Filters by {@link SiteTree->canCreate()}, as well as |
||
2479 | * {@link SiteTree::$needs_permission}. |
||
2480 | * |
||
2481 | * @return array |
||
2482 | */ |
||
2483 | protected function getClassDropdown() { |
||
2526 | |||
2527 | /** |
||
2528 | * Returns an array of the class names of classes that are allowed to be children of this class. |
||
2529 | * |
||
2530 | * @return string[] |
||
2531 | */ |
||
2532 | public function allowedChildren() { |
||
2555 | |||
2556 | /** |
||
2557 | * Returns the class name of the default class for children of this page. |
||
2558 | * |
||
2559 | * @return string |
||
2560 | */ |
||
2561 | public function defaultChild() { |
||
2572 | |||
2573 | /** |
||
2574 | * Returns the class name of the default class for the parent of this page. |
||
2575 | * |
||
2576 | * @return string |
||
2577 | */ |
||
2578 | public function defaultParent() { |
||
2581 | |||
2582 | /** |
||
2583 | * Get the title for use in menus for this page. If the MenuTitle field is set it returns that, else it returns the |
||
2584 | * Title field. |
||
2585 | * |
||
2586 | * @return string |
||
2587 | */ |
||
2588 | public function getMenuTitle(){ |
||
2595 | |||
2596 | |||
2597 | /** |
||
2598 | * Set the menu title for this page. |
||
2599 | * |
||
2600 | * @param string $value |
||
2601 | */ |
||
2602 | public function setMenuTitle($value) { |
||
2609 | |||
2610 | /** |
||
2611 | * A flag provides the user with additional data about the current page status, for example a "removed from draft" |
||
2612 | * status. Each page can have more than one status flag. Returns a map of a unique key to a (localized) title for |
||
2613 | * the flag. The unique key can be reused as a CSS class. Use the 'updateStatusFlags' extension point to customize |
||
2614 | * the flags. |
||
2615 | * |
||
2616 | * Example (simple): |
||
2617 | * "deletedonlive" => "Deleted" |
||
2618 | * |
||
2619 | * Example (with optional title attribute): |
||
2620 | * "deletedonlive" => array('text' => "Deleted", 'title' => 'This page has been deleted') |
||
2621 | * |
||
2622 | * @param bool $cached Whether to serve the fields from cache; false regenerate them |
||
2623 | * @return array |
||
2624 | */ |
||
2625 | public function getStatusFlags($cached = true) { |
||
2657 | |||
2658 | /** |
||
2659 | * getTreeTitle will return three <span> html DOM elements, an empty <span> with the class 'jstree-pageicon' in |
||
2660 | * front, following by a <span> wrapping around its MenutTitle, then following by a <span> indicating its |
||
2661 | * publication status. |
||
2662 | * |
||
2663 | * @return string An HTML string ready to be directly used in a template |
||
2664 | */ |
||
2665 | public function getTreeTitle() { |
||
2694 | |||
2695 | /** |
||
2696 | * Returns the page in the current page stack of the given level. Level(1) will return the main menu item that |
||
2697 | * we're currently inside, etc. |
||
2698 | * |
||
2699 | * @param int $level |
||
2700 | * @return SiteTree |
||
2701 | */ |
||
2702 | public function Level($level) { |
||
2711 | |||
2712 | /** |
||
2713 | * Gets the depth of this page in the sitetree, where 1 is the root level |
||
2714 | * |
||
2715 | * @return int |
||
2716 | */ |
||
2717 | public function getPageLevel() { |
||
2723 | |||
2724 | /** |
||
2725 | * Find the controller name by our convention of {$ModelClass}Controller |
||
2726 | * |
||
2727 | * @return string |
||
2728 | */ |
||
2729 | public function getControllerName() { |
||
2759 | |||
2760 | /** |
||
2761 | * Return the CSS classes to apply to this node in the CMS tree. |
||
2762 | * |
||
2763 | * @param string $numChildrenMethod |
||
2764 | * @return string |
||
2765 | */ |
||
2766 | public function CMSTreeClasses($numChildrenMethod="numChildren") { |
||
2797 | |||
2798 | /** |
||
2799 | * Stops extendCMSFields() being called on getCMSFields(). This is useful when you need access to fields added by |
||
2800 | * subclasses of SiteTree in a extension. Call before calling parent::getCMSFields(), and reenable afterwards. |
||
2801 | */ |
||
2802 | static public function disableCMSFieldsExtensions() { |
||
2805 | |||
2806 | /** |
||
2807 | * Reenables extendCMSFields() being called on getCMSFields() after it has been disabled by |
||
2808 | * disableCMSFieldsExtensions(). |
||
2809 | */ |
||
2810 | static public function enableCMSFieldsExtensions() { |
||
2813 | |||
2814 | public function providePermissions() { |
||
2848 | |||
2849 | /** |
||
2850 | * Return the translated Singular name. |
||
2851 | * |
||
2852 | * @return string |
||
2853 | */ |
||
2854 | public function i18n_singular_name() { |
||
2863 | |||
2864 | /** |
||
2865 | * Overloaded to also provide entities for 'Page' class which is usually located in custom code, hence textcollector |
||
2866 | * picks it up for the wrong folder. |
||
2867 | * |
||
2868 | * @return array |
||
2869 | */ |
||
2870 | public function provideI18nEntities() { |
||
2886 | |||
2887 | /** |
||
2888 | * Returns 'root' if the current page has no parent, or 'subpage' otherwise |
||
2889 | * |
||
2890 | * @return string |
||
2891 | */ |
||
2892 | public function getParentType() { |
||
2895 | |||
2896 | /** |
||
2897 | * Clear the permissions cache for SiteTree |
||
2898 | */ |
||
2899 | public static function reset() { |
||
2902 | |||
2903 | static public function on_db_reset() { |
||
2906 | |||
2907 | } |
||
2908 |