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 |
||
37 | class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvider,CMSPreviewable { |
||
38 | |||
39 | /** |
||
40 | * Indicates what kind of children this page type can have. |
||
41 | * This can be an array of allowed child classes, or the string "none" - |
||
42 | * indicating that this page type can't have children. |
||
43 | * If a classname is prefixed by "*", such as "*Page", then only that |
||
44 | * class is allowed - no subclasses. Otherwise, the class and all its |
||
45 | * subclasses are allowed. |
||
46 | * To control allowed children on root level (no parent), use {@link $can_be_root}. |
||
47 | * |
||
48 | * Note that this setting is cached when used in the CMS, use the "flush" query parameter to clear it. |
||
49 | * |
||
50 | * @config |
||
51 | * @var array |
||
52 | */ |
||
53 | private static $allowed_children = array("SiteTree"); |
||
54 | |||
55 | /** |
||
56 | * The default child class for this page. |
||
57 | * Note: Value might be cached, see {@link $allowed_chilren}. |
||
58 | * |
||
59 | * @config |
||
60 | * @var string |
||
61 | */ |
||
62 | private static $default_child = "Page"; |
||
63 | |||
64 | /** |
||
65 | * The default parent class for this page. |
||
66 | * Note: Value might be cached, see {@link $allowed_chilren}. |
||
67 | * |
||
68 | * @config |
||
69 | * @var string |
||
70 | */ |
||
71 | private static $default_parent = null; |
||
72 | |||
73 | /** |
||
74 | * Controls whether a page can be in the root of the site tree. |
||
75 | * Note: Value might be cached, see {@link $allowed_chilren}. |
||
76 | * |
||
77 | * @config |
||
78 | * @var bool |
||
79 | */ |
||
80 | private static $can_be_root = true; |
||
81 | |||
82 | /** |
||
83 | * List of permission codes a user can have to allow a user to create a page of this type. |
||
84 | * Note: Value might be cached, see {@link $allowed_chilren}. |
||
85 | * |
||
86 | * @config |
||
87 | * @var array |
||
88 | */ |
||
89 | private static $need_permission = null; |
||
90 | |||
91 | /** |
||
92 | * If you extend a class, and don't want to be able to select the old class |
||
93 | * in the cms, set this to the old class name. Eg, if you extended Product |
||
94 | * to make ImprovedProduct, then you would set $hide_ancestor to Product. |
||
95 | * |
||
96 | * @config |
||
97 | * @var string |
||
98 | */ |
||
99 | private static $hide_ancestor = null; |
||
100 | |||
101 | private static $db = array( |
||
|
|||
102 | "URLSegment" => "Varchar(255)", |
||
103 | "Title" => "Varchar(255)", |
||
104 | "MenuTitle" => "Varchar(100)", |
||
105 | "Content" => "HTMLText", |
||
106 | "MetaDescription" => "Text", |
||
107 | "ExtraMeta" => "HTMLText('meta, link')", |
||
108 | "ShowInMenus" => "Boolean", |
||
109 | "ShowInSearch" => "Boolean", |
||
110 | "Sort" => "Int", |
||
111 | "HasBrokenFile" => "Boolean", |
||
112 | "HasBrokenLink" => "Boolean", |
||
113 | "ReportClass" => "Varchar", |
||
114 | "CanViewType" => "Enum('Anyone, LoggedInUsers, OnlyTheseUsers, Inherit', 'Inherit')", |
||
115 | "CanEditType" => "Enum('LoggedInUsers, OnlyTheseUsers, Inherit', 'Inherit')", |
||
116 | ); |
||
117 | |||
118 | private static $indexes = array( |
||
119 | "URLSegment" => true, |
||
120 | ); |
||
121 | |||
122 | private static $many_many = array( |
||
123 | "LinkTracking" => "SiteTree", |
||
124 | "ImageTracking" => "File", |
||
125 | "ViewerGroups" => "Group", |
||
126 | "EditorGroups" => "Group", |
||
127 | ); |
||
128 | |||
129 | private static $belongs_many_many = array( |
||
130 | "BackLinkTracking" => "SiteTree" |
||
131 | ); |
||
132 | |||
133 | private static $many_many_extraFields = array( |
||
134 | "LinkTracking" => array("FieldName" => "Varchar"), |
||
135 | "ImageTracking" => array("FieldName" => "Varchar") |
||
136 | ); |
||
137 | |||
138 | private static $casting = array( |
||
139 | "Breadcrumbs" => "HTMLText", |
||
140 | "LastEdited" => "SS_Datetime", |
||
141 | "Created" => "SS_Datetime", |
||
142 | 'Link' => 'Text', |
||
143 | 'RelativeLink' => 'Text', |
||
144 | 'AbsoluteLink' => 'Text', |
||
145 | 'TreeTitle' => 'HTMLText', |
||
146 | ); |
||
147 | |||
148 | private static $defaults = array( |
||
149 | "ShowInMenus" => 1, |
||
150 | "ShowInSearch" => 1, |
||
151 | "CanViewType" => "Inherit", |
||
152 | "CanEditType" => "Inherit" |
||
153 | ); |
||
154 | |||
155 | private static $versioning = array( |
||
156 | "Stage", "Live" |
||
157 | ); |
||
158 | |||
159 | private static $default_sort = "\"Sort\""; |
||
160 | |||
161 | /** |
||
162 | * If this is false, the class cannot be created in the CMS by regular content authors, only by ADMINs. |
||
163 | * @var boolean |
||
164 | * @config |
||
165 | */ |
||
166 | private static $can_create = true; |
||
167 | |||
168 | /** |
||
169 | * Icon to use in the CMS page tree. This should be the full filename, relative to the webroot. |
||
170 | * Also supports custom CSS rule contents (applied to the correct selector for the tree UI implementation). |
||
171 | * |
||
172 | * @see CMSMain::generateTreeStylingCSS() |
||
173 | * @config |
||
174 | * @var string |
||
175 | */ |
||
176 | private static $icon = null; |
||
177 | |||
178 | /** |
||
179 | * @config |
||
180 | * @var string Description of the class functionality, typically shown to a user |
||
181 | * when selecting which page type to create. Translated through {@link provideI18nEntities()}. |
||
182 | */ |
||
183 | private static $description = 'Generic content page'; |
||
184 | |||
185 | private static $extensions = array( |
||
186 | "Hierarchy", |
||
187 | "Versioned('Stage', 'Live')", |
||
188 | "SiteTreeLinkTracking" |
||
189 | ); |
||
190 | |||
191 | private static $searchable_fields = array( |
||
192 | 'Title', |
||
193 | 'Content', |
||
194 | ); |
||
195 | |||
196 | private static $field_labels = array( |
||
197 | 'URLSegment' => 'URL' |
||
198 | ); |
||
199 | |||
200 | /** |
||
201 | * @config |
||
202 | */ |
||
203 | private static $nested_urls = true; |
||
204 | |||
205 | /** |
||
206 | * @config |
||
207 | */ |
||
208 | private static $create_default_pages = true; |
||
209 | |||
210 | /** |
||
211 | * This controls whether of not extendCMSFields() is called by getCMSFields. |
||
212 | */ |
||
213 | private static $runCMSFieldsExtensions = true; |
||
214 | |||
215 | /** |
||
216 | * Cache for canView/Edit/Publish/Delete permissions. |
||
217 | * Keyed by permission type (e.g. 'edit'), with an array |
||
218 | * of IDs mapped to their boolean permission ability (true=allow, false=deny). |
||
219 | * See {@link batch_permission_check()} for details. |
||
220 | */ |
||
221 | private static $cache_permissions = array(); |
||
222 | |||
223 | /** |
||
224 | * @config |
||
225 | * @var boolean |
||
226 | */ |
||
227 | private static $enforce_strict_hierarchy = true; |
||
228 | |||
229 | /** |
||
230 | * The value used for the meta generator tag. Leave blank to omit the tag. |
||
231 | * |
||
232 | * @config |
||
233 | * @var string |
||
234 | */ |
||
235 | private static $meta_generator = 'SilverStripe - http://silverstripe.org'; |
||
236 | |||
237 | protected $_cache_statusFlags = null; |
||
238 | |||
239 | /** |
||
240 | * Determines if the system should avoid orphaned pages |
||
241 | * by deleting all children when the their parent is deleted (TRUE), |
||
242 | * or rather preserve this data even if its not reachable through any navigation path (FALSE). |
||
243 | * |
||
244 | * @deprecated 4.0 Use the "SiteTree.enforce_strict_hierarchy" config setting instead |
||
245 | * @param boolean |
||
246 | */ |
||
247 | static public function set_enforce_strict_hierarchy($to) { |
||
251 | |||
252 | /** |
||
253 | * @deprecated 4.0 Use the "SiteTree.enforce_strict_hierarchy" config setting instead |
||
254 | * @return boolean |
||
255 | */ |
||
256 | static public function get_enforce_strict_hierarchy() { |
||
260 | |||
261 | /** |
||
262 | * Returns TRUE if nested URLs (e.g. page/sub-page/) are currently enabled on this site. |
||
263 | * |
||
264 | * @deprecated 4.0 Use the "SiteTree.nested_urls" config setting instead |
||
265 | * @return bool |
||
266 | */ |
||
267 | static public function nested_urls() { |
||
271 | |||
272 | /** |
||
273 | * @deprecated 4.0 Use the "SiteTree.nested_urls" config setting instead |
||
274 | */ |
||
275 | static public function enable_nested_urls() { |
||
279 | |||
280 | /** |
||
281 | * @deprecated 4.0 Use the "SiteTree.nested_urls" config setting instead |
||
282 | */ |
||
283 | static public function disable_nested_urls() { |
||
287 | |||
288 | /** |
||
289 | * Set the (re)creation of default pages on /dev/build |
||
290 | * |
||
291 | * @deprecated 4.0 Use the "SiteTree.create_default_pages" config setting instead |
||
292 | * @param bool $option |
||
293 | */ |
||
294 | static public function set_create_default_pages($option = true) { |
||
298 | |||
299 | /** |
||
300 | * Return true if default pages should be created on /dev/build. |
||
301 | * |
||
302 | * @deprecated 4.0 Use the "SiteTree.create_default_pages" config setting instead |
||
303 | * @return bool |
||
304 | */ |
||
305 | static public function get_create_default_pages() { |
||
309 | |||
310 | /** |
||
311 | * Fetches the {@link SiteTree} object that maps to a link. |
||
312 | * |
||
313 | * If you have enabled {@link SiteTree::config()->nested_urls} on this site, then you can use a nested link such as |
||
314 | * "about-us/staff/", and this function will traverse down the URL chain and grab the appropriate link. |
||
315 | * |
||
316 | * Note that if no model can be found, this method will fall over to a extended alternateGetByLink method provided |
||
317 | * by a extension attached to {@link SiteTree} |
||
318 | * |
||
319 | * @param string $link The link of the page to search for |
||
320 | * @param bool $cache True (default) to use caching, false to force a fresh search from the database |
||
321 | * @return SiteTree |
||
322 | */ |
||
323 | static public function get_by_link($link, $cache = true) { |
||
324 | if(trim($link, '/')) { |
||
325 | $link = trim(Director::makeRelative($link), '/'); |
||
326 | } else { |
||
327 | $link = RootURLController::get_homepage_link(); |
||
328 | } |
||
329 | |||
330 | $parts = preg_split('|/+|', $link); |
||
331 | |||
332 | // Grab the initial root level page to traverse down from. |
||
333 | $URLSegment = array_shift($parts); |
||
334 | $conditions = array('"SiteTree"."URLSegment"' => rawurlencode($URLSegment)); |
||
335 | if(self::config()->nested_urls) { |
||
336 | $conditions[] = array('"SiteTree"."ParentID"' => 0); |
||
337 | } |
||
338 | $sitetree = DataObject::get_one('SiteTree', $conditions, $cache); |
||
339 | |||
340 | /// Fall back on a unique URLSegment for b/c. |
||
341 | if( !$sitetree |
||
342 | && self::config()->nested_urls |
||
343 | && $page = DataObject::get_one('SiteTree', array( |
||
344 | '"SiteTree"."URLSegment"' => $URLSegment |
||
345 | ), $cache) |
||
346 | ) { |
||
347 | return $page; |
||
348 | } |
||
349 | |||
350 | // Attempt to grab an alternative page from extensions. |
||
351 | if(!$sitetree) { |
||
352 | $parentID = self::config()->nested_urls ? 0 : null; |
||
353 | |||
354 | View Code Duplication | if($alternatives = singleton('SiteTree')->extend('alternateGetByLink', $URLSegment, $parentID)) { |
|
355 | foreach($alternatives as $alternative) if($alternative) $sitetree = $alternative; |
||
356 | } |
||
357 | |||
358 | if(!$sitetree) return false; |
||
359 | } |
||
360 | |||
361 | // Check if we have any more URL parts to parse. |
||
362 | if(!self::config()->nested_urls || !count($parts)) return $sitetree; |
||
363 | |||
364 | // Traverse down the remaining URL segments and grab the relevant SiteTree objects. |
||
365 | foreach($parts as $segment) { |
||
366 | $next = DataObject::get_one('SiteTree', array( |
||
367 | '"SiteTree"."URLSegment"' => $segment, |
||
368 | '"SiteTree"."ParentID"' => $sitetree->ID |
||
369 | ), |
||
370 | $cache |
||
371 | ); |
||
372 | |||
373 | if(!$next) { |
||
374 | $parentID = (int) $sitetree->ID; |
||
375 | |||
376 | View Code Duplication | if($alternatives = singleton('SiteTree')->extend('alternateGetByLink', $segment, $parentID)) { |
|
377 | foreach($alternatives as $alternative) if($alternative) $next = $alternative; |
||
378 | } |
||
379 | |||
380 | if(!$next) return false; |
||
381 | } |
||
382 | |||
383 | $sitetree->destroy(); |
||
384 | $sitetree = $next; |
||
385 | } |
||
386 | |||
387 | return $sitetree; |
||
388 | } |
||
389 | |||
390 | /** |
||
391 | * Return a subclass map of SiteTree that shouldn't be hidden through {@link SiteTree::$hide_ancestor} |
||
392 | * |
||
393 | * @return array |
||
394 | */ |
||
395 | static public function page_type_classes() { |
||
396 | $classes = ClassInfo::getValidSubClasses(); |
||
397 | |||
398 | $baseClassIndex = array_search('SiteTree', $classes); |
||
399 | if($baseClassIndex !== FALSE) unset($classes[$baseClassIndex]); |
||
400 | |||
401 | $kill_ancestors = array(); |
||
402 | |||
403 | // figure out if there are any classes we don't want to appear |
||
404 | foreach($classes as $class) { |
||
405 | $instance = singleton($class); |
||
406 | |||
407 | // do any of the progeny want to hide an ancestor? |
||
408 | if($ancestor_to_hide = $instance->stat('hide_ancestor')) { |
||
409 | // note for killing later |
||
410 | $kill_ancestors[] = $ancestor_to_hide; |
||
411 | } |
||
412 | } |
||
413 | |||
414 | // If any of the descendents don't want any of the elders to show up, cruelly render the elders surplus to |
||
415 | // requirements |
||
416 | if($kill_ancestors) { |
||
417 | $kill_ancestors = array_unique($kill_ancestors); |
||
418 | foreach($kill_ancestors as $mark) { |
||
419 | // unset from $classes |
||
420 | $idx = array_search($mark, $classes); |
||
421 | unset($classes[$idx]); |
||
422 | } |
||
423 | } |
||
424 | |||
425 | return $classes; |
||
426 | } |
||
427 | |||
428 | /** |
||
429 | * Replace a "[sitetree_link id=n]" shortcode with a link to the page with the corresponding ID. |
||
430 | * |
||
431 | * @param array $arguments |
||
432 | * @param string $content |
||
433 | * @param TextParser $parser |
||
434 | * @return string |
||
435 | */ |
||
436 | static public function link_shortcode_handler($arguments, $content = null, $parser = null) { |
||
437 | if(!isset($arguments['id']) || !is_numeric($arguments['id'])) return; |
||
438 | |||
439 | if ( |
||
440 | !($page = DataObject::get_by_id('SiteTree', $arguments['id'])) // Get the current page by ID. |
||
441 | && !($page = Versioned::get_latest_version('SiteTree', $arguments['id'])) // Attempt link to old version. |
||
442 | ) { |
||
443 | return; // There were no suitable matches at all. |
||
444 | } |
||
445 | |||
446 | $link = Convert::raw2att($page->Link()); |
||
447 | |||
448 | if($content) { |
||
449 | return sprintf('<a href="%s">%s</a>', $link, $parser->parse($content)); |
||
450 | } else { |
||
451 | return $link; |
||
452 | } |
||
453 | } |
||
454 | |||
455 | /** |
||
456 | * Return the link for this {@link SiteTree} object, with the {@link Director::baseURL()} included. |
||
457 | * |
||
458 | * @param string $action Optional controller action (method). |
||
459 | * Note: URI encoding of this parameter is applied automatically through template casting, |
||
460 | * don't encode the passed parameter. Please use {@link Controller::join_links()} instead to |
||
461 | * append GET parameters. |
||
462 | * @return string |
||
463 | */ |
||
464 | public function Link($action = null) { |
||
467 | |||
468 | /** |
||
469 | * Get the absolute URL for this page, including protocol and host. |
||
470 | * |
||
471 | * @param string $action See {@link Link()} |
||
472 | * @return string |
||
473 | */ |
||
474 | public function AbsoluteLink($action = null) { |
||
475 | if($this->hasMethod('alternateAbsoluteLink')) { |
||
476 | return $this->alternateAbsoluteLink($action); |
||
477 | } else { |
||
478 | return Director::absoluteURL($this->Link($action)); |
||
479 | } |
||
480 | } |
||
481 | |||
482 | /** |
||
483 | * Base link used for previewing. Defaults to absolute URL, in order to account for domain changes, e.g. on multi |
||
484 | * site setups. Does not contain hints about the stage, see {@link SilverStripeNavigator} for details. |
||
485 | * |
||
486 | * @param string $action See {@link Link()} |
||
487 | * @return string |
||
488 | */ |
||
489 | public function PreviewLink($action = null) { |
||
490 | if($this->hasMethod('alternatePreviewLink')) { |
||
491 | return $this->alternatePreviewLink($action); |
||
492 | } else { |
||
493 | return $this->AbsoluteLink($action); |
||
494 | } |
||
495 | } |
||
496 | |||
497 | /** |
||
498 | * Return the link for this {@link SiteTree} object relative to the SilverStripe root. |
||
499 | * |
||
500 | * By default, if this page is the current home page, and there is no action specified then this will return a link |
||
501 | * to the root of the site. However, if you set the $action parameter to TRUE then the link will not be rewritten |
||
502 | * and returned in its full form. |
||
503 | * |
||
504 | * @uses RootURLController::get_homepage_link() |
||
505 | * |
||
506 | * @param string $action See {@link Link()} |
||
507 | * @return string |
||
508 | */ |
||
509 | public function RelativeLink($action = null) { |
||
510 | if($this->ParentID && self::config()->nested_urls) { |
||
511 | $parent = $this->Parent(); |
||
512 | // If page is removed select parent from version history (for archive page view) |
||
513 | if((!$parent || !$parent->exists()) && $this->IsDeletedFromStage) { |
||
514 | $parent = Versioned::get_latest_version('SiteTree', $this->ParentID); |
||
515 | } |
||
516 | $base = $parent->RelativeLink($this->URLSegment); |
||
517 | } elseif(!$action && $this->URLSegment == RootURLController::get_homepage_link()) { |
||
518 | // Unset base for root-level homepages. |
||
519 | // Note: Homepages with action parameters (or $action === true) |
||
520 | // need to retain their URLSegment. |
||
521 | $base = null; |
||
522 | } else { |
||
523 | $base = $this->URLSegment; |
||
524 | } |
||
525 | |||
526 | $this->extend('updateRelativeLink', $base, $action); |
||
527 | |||
528 | // Legacy support: If $action === true, retain URLSegment for homepages, |
||
529 | // but don't append any action |
||
530 | if($action === true) $action = null; |
||
531 | |||
532 | return Controller::join_links($base, '/', $action); |
||
533 | } |
||
534 | |||
535 | /** |
||
536 | * Get the absolute URL for this page on the Live site. |
||
537 | * |
||
538 | * @param bool $includeStageEqualsLive Whether to append the URL with ?stage=Live to force Live mode |
||
539 | * @return string |
||
540 | */ |
||
541 | public function getAbsoluteLiveLink($includeStageEqualsLive = true) { |
||
542 | $oldStage = Versioned::current_stage(); |
||
543 | Versioned::reading_stage('Live'); |
||
544 | $live = Versioned::get_one_by_stage('SiteTree', 'Live', array( |
||
545 | '"SiteTree"."ID"' => $this->ID |
||
546 | )); |
||
547 | if($live) { |
||
548 | $link = $live->AbsoluteLink(); |
||
549 | if($includeStageEqualsLive) $link .= '?stage=Live'; |
||
550 | } else { |
||
551 | $link = null; |
||
552 | } |
||
553 | |||
554 | Versioned::reading_stage($oldStage); |
||
555 | return $link; |
||
556 | } |
||
557 | |||
558 | /** |
||
559 | * Generates a link to edit this page in the CMS. |
||
560 | * |
||
561 | * @return string |
||
562 | */ |
||
563 | public function CMSEditLink() { |
||
566 | |||
567 | |||
568 | /** |
||
569 | * Return a CSS identifier generated from this page's link. |
||
570 | * |
||
571 | * @return string The URL segment |
||
572 | */ |
||
573 | public function ElementName() { |
||
576 | |||
577 | /** |
||
578 | * Returns true if this is the currently active page being used to handle this request. |
||
579 | * |
||
580 | * @return bool |
||
581 | */ |
||
582 | public function isCurrent() { |
||
585 | |||
586 | /** |
||
587 | * Check if this page is in the currently active section (e.g. it is either current or one of its children is |
||
588 | * currently being viewed). |
||
589 | * |
||
590 | * @return bool |
||
591 | */ |
||
592 | public function isSection() { |
||
593 | return $this->isCurrent() || ( |
||
594 | Director::get_current_page() instanceof SiteTree && in_array($this->ID, Director::get_current_page()->getAncestors()->column()) |
||
595 | ); |
||
596 | } |
||
597 | |||
598 | /** |
||
599 | * Check if the parent of this page has been removed (or made otherwise unavailable), and is still referenced by |
||
600 | * this child. Any such orphaned page may still require access via the CMS, but should not be shown as accessible |
||
601 | * to external users. |
||
602 | * |
||
603 | * @return bool |
||
604 | */ |
||
605 | public function isOrphaned() { |
||
613 | |||
614 | /** |
||
615 | * Return "link" or "current" depending on if this is the {@link SiteTree::isCurrent()} current page. |
||
616 | * |
||
617 | * @return string |
||
618 | */ |
||
619 | public function LinkOrCurrent() { |
||
622 | |||
623 | /** |
||
624 | * Return "link" or "section" depending on if this is the {@link SiteTree::isSeciton()} current section. |
||
625 | * |
||
626 | * @return string |
||
627 | */ |
||
628 | public function LinkOrSection() { |
||
631 | |||
632 | /** |
||
633 | * Return "link", "current" or "section" depending on if this page is the current page, or not on the current page |
||
634 | * but in the current section. |
||
635 | * |
||
636 | * @return string |
||
637 | */ |
||
638 | public function LinkingMode() { |
||
639 | if($this->isCurrent()) { |
||
640 | return 'current'; |
||
641 | } elseif($this->isSection()) { |
||
642 | return 'section'; |
||
643 | } else { |
||
644 | return 'link'; |
||
645 | } |
||
646 | } |
||
647 | |||
648 | /** |
||
649 | * Check if this page is in the given current section. |
||
650 | * |
||
651 | * @param string $sectionName Name of the section to check |
||
652 | * @return bool True if we are in the given section |
||
653 | */ |
||
654 | public function InSection($sectionName) { |
||
655 | $page = Director::get_current_page(); |
||
656 | while($page) { |
||
657 | if($sectionName == $page->URLSegment) |
||
658 | return true; |
||
659 | $page = $page->Parent; |
||
660 | } |
||
661 | return false; |
||
662 | } |
||
663 | |||
664 | /** |
||
665 | * Create a duplicate of this node. Doesn't affect joined data - create a custom overloading of this if you need |
||
666 | * such behaviour. |
||
667 | * |
||
668 | * @param bool $doWrite Whether to write the new object before returning it |
||
669 | * @return self The duplicated object |
||
670 | */ |
||
671 | public function duplicate($doWrite = true) { |
||
672 | |||
673 | $page = parent::duplicate(false); |
||
674 | $page->Sort = 0; |
||
675 | $this->invokeWithExtensions('onBeforeDuplicate', $page); |
||
676 | |||
677 | if($doWrite) { |
||
678 | $page->write(); |
||
679 | |||
680 | $page = $this->duplicateManyManyRelations($this, $page); |
||
681 | } |
||
682 | $this->invokeWithExtensions('onAfterDuplicate', $page); |
||
683 | |||
684 | return $page; |
||
685 | } |
||
686 | |||
687 | /** |
||
688 | * Duplicates each child of this node recursively and returns the top-level duplicate node. |
||
689 | * |
||
690 | * @return self The duplicated object |
||
691 | */ |
||
692 | public function duplicateWithChildren() { |
||
708 | |||
709 | /** |
||
710 | * Duplicate this node and its children as a child of the node with the given ID |
||
711 | * |
||
712 | * @param int $id ID of the new node's new parent |
||
713 | */ |
||
714 | public function duplicateAsChild($id) { |
||
715 | $newSiteTree = $this->duplicate(); |
||
716 | $newSiteTree->ParentID = $id; |
||
717 | $newSiteTree->Sort = 0; |
||
718 | $newSiteTree->write(); |
||
719 | } |
||
720 | |||
721 | /** |
||
722 | * Return a breadcrumb trail to this page. Excludes "hidden" pages (with ShowInMenus=0) by default. |
||
723 | * |
||
724 | * @param int $maxDepth The maximum depth to traverse. |
||
725 | * @param boolean $unlinked Whether to link page titles. |
||
726 | * @param boolean|string $stopAtPageType ClassName of a page to stop the upwards traversal. |
||
727 | * @param boolean $showHidden Include pages marked with the attribute ShowInMenus = 0 |
||
728 | * @return HTMLText The breadcrumb trail. |
||
729 | */ |
||
730 | public function Breadcrumbs($maxDepth = 20, $unlinked = false, $stopAtPageType = false, $showHidden = false) { |
||
738 | |||
739 | |||
740 | /** |
||
741 | * Returns a list of breadcrumbs for the current page. |
||
742 | * |
||
743 | * @param int $maxDepth The maximum depth to traverse. |
||
744 | * @param boolean|string $stopAtPageType ClassName of a page to stop the upwards traversal. |
||
745 | * @param boolean $showHidden Include pages marked with the attribute ShowInMenus = 0 |
||
746 | * |
||
747 | * @return ArrayList |
||
748 | */ |
||
749 | public function getBreadcrumbItems($maxDepth = 20, $stopAtPageType = false, $showHidden = false) { |
||
767 | |||
768 | |||
769 | /** |
||
770 | * Make this page a child of another page. |
||
771 | * |
||
772 | * If the parent page does not exist, resolve it to a valid ID before updating this page's reference. |
||
773 | * |
||
774 | * @param SiteTree|int $item Either the parent object, or the parent ID |
||
775 | */ |
||
776 | public function setParent($item) { |
||
784 | |||
785 | /** |
||
786 | * Get the parent of this page. |
||
787 | * |
||
788 | * @return SiteTree Parent of this page |
||
789 | */ |
||
790 | public function getParent() { |
||
795 | |||
796 | /** |
||
797 | * Return a string of the form "parent - page" or "grandparent - parent - page" using page titles |
||
798 | * |
||
799 | * @param int $level The maximum amount of levels to traverse. |
||
800 | * @param string $separator Seperating string |
||
801 | * @return string The resulting string |
||
802 | */ |
||
803 | public function NestedTitle($level = 2, $separator = " - ") { |
||
812 | |||
813 | /** |
||
814 | * This function should return true if the current user can execute this action. It can be overloaded to customise |
||
815 | * the security model for an application. |
||
816 | * |
||
817 | * Slightly altered from parent behaviour in {@link DataObject->can()}: |
||
818 | * - Checks for existence of a method named "can<$perm>()" on the object |
||
819 | * - Calls decorators and only returns for FALSE "vetoes" |
||
820 | * - Falls back to {@link Permission::check()} |
||
821 | * - Does NOT check for many-many relations named "Can<$perm>" |
||
822 | * |
||
823 | * @uses DataObjectDecorator->can() |
||
824 | * |
||
825 | * @param string $perm The permission to be checked, such as 'View' |
||
826 | * @param Member $member The member whose permissions need checking. Defaults to the currently logged in user. |
||
827 | * @return bool True if the the member is allowed to do the given action |
||
828 | */ |
||
829 | public function can($perm, $member = null) { |
||
846 | |||
847 | /** |
||
848 | * This function should return true if the current user can add children to this page. It can be overloaded to |
||
849 | * customise the security model for an application. |
||
850 | * |
||
851 | * Denies permission if any of the following conditions is true: |
||
852 | * - alternateCanAddChildren() on a extension returns false |
||
853 | * - canEdit() is not granted |
||
854 | * - There are no classes defined in {@link $allowed_children} |
||
855 | * |
||
856 | * @uses SiteTreeExtension->canAddChildren() |
||
857 | * @uses canEdit() |
||
858 | * @uses $allowed_children |
||
859 | * |
||
860 | * @param Member|int $member |
||
861 | * @return bool True if the current user can add children |
||
862 | */ |
||
863 | public function canAddChildren($member = null) { |
||
881 | |||
882 | /** |
||
883 | * This function should return true if the current user can view this page. It can be overloaded to customise the |
||
884 | * security model for an application. |
||
885 | * |
||
886 | * Denies permission if any of the following conditions is true: |
||
887 | * - canView() on any extension returns false |
||
888 | * - "CanViewType" directive is set to "Inherit" and any parent page return false for canView() |
||
889 | * - "CanViewType" directive is set to "LoggedInUsers" and no user is logged in |
||
890 | * - "CanViewType" directive is set to "OnlyTheseUsers" and user is not in the given groups |
||
891 | * |
||
892 | * @uses DataExtension->canView() |
||
893 | * @uses ViewerGroups() |
||
894 | * |
||
895 | * @param Member|int $member |
||
896 | * @return bool True if the current user can view this page |
||
897 | */ |
||
898 | public function canView($member = null) { |
||
937 | |||
938 | /** |
||
939 | * This function should return true if the current user can delete this page. It can be overloaded to customise the |
||
940 | * security model for an application. |
||
941 | * |
||
942 | * Denies permission if any of the following conditions is true: |
||
943 | * - canDelete() returns false on any extension |
||
944 | * - canEdit() returns false |
||
945 | * - any descendant page returns false for canDelete() |
||
946 | * |
||
947 | * @uses canDelete() |
||
948 | * @uses SiteTreeExtension->canDelete() |
||
949 | * @uses canEdit() |
||
950 | * |
||
951 | * @param Member $member |
||
952 | * @return bool True if the current user can delete this page |
||
953 | */ |
||
954 | public function canDelete($member = null) { |
||
974 | |||
975 | /** |
||
976 | * This function should return true if the current user can create new pages of this class, regardless of class. It |
||
977 | * can be overloaded to customise the security model for an application. |
||
978 | * |
||
979 | * By default, permission to create at the root level is based on the SiteConfig configuration, and permission to |
||
980 | * create beneath a parent is based on the ability to edit that parent page. |
||
981 | * |
||
982 | * Use {@link canAddChildren()} to control behaviour of creating children under this page. |
||
983 | * |
||
984 | * @uses $can_create |
||
985 | * @uses DataExtension->canCreate() |
||
986 | * |
||
987 | * @param Member $member |
||
988 | * @param array $context Optional array which may contain array('Parent' => $parentObj) |
||
989 | * If a parent page is known, it will be checked for validity. |
||
990 | * If omitted, it will be assumed this is to be created as a top level page. |
||
991 | * @return bool True if the current user can create pages on this class. |
||
992 | */ |
||
993 | public function canCreate($member = null, $context = array()) { |
||
1025 | |||
1026 | /** |
||
1027 | * This function should return true if the current user can edit this page. It can be overloaded to customise the |
||
1028 | * security model for an application. |
||
1029 | * |
||
1030 | * Denies permission if any of the following conditions is true: |
||
1031 | * - canEdit() on any extension returns false |
||
1032 | * - canView() return false |
||
1033 | * - "CanEditType" directive is set to "Inherit" and any parent page return false for canEdit() |
||
1034 | * - "CanEditType" directive is set to "LoggedInUsers" and no user is logged in or doesn't have the |
||
1035 | * CMS_Access_CMSMAIN permission code |
||
1036 | * - "CanEditType" directive is set to "OnlyTheseUsers" and user is not in the given groups |
||
1037 | * |
||
1038 | * @uses canView() |
||
1039 | * @uses EditorGroups() |
||
1040 | * @uses DataExtension->canEdit() |
||
1041 | * |
||
1042 | * @param Member $member Set to false if you want to explicitly test permissions without a valid user (useful for |
||
1043 | * unit tests) |
||
1044 | * @return bool True if the current user can edit this page |
||
1045 | */ |
||
1046 | public function canEdit($member = null) { |
||
1070 | |||
1071 | /** |
||
1072 | * This function should return true if the current user can publish this page. It can be overloaded to customise |
||
1073 | * the security model for an application. |
||
1074 | * |
||
1075 | * Denies permission if any of the following conditions is true: |
||
1076 | * - canPublish() on any extension returns false |
||
1077 | * - canEdit() returns false |
||
1078 | * |
||
1079 | * @uses SiteTreeExtension->canPublish() |
||
1080 | * |
||
1081 | * @param Member $member |
||
1082 | * @return bool True if the current user can publish this page. |
||
1083 | */ |
||
1084 | public function canPublish($member = null) { |
||
1096 | |||
1097 | public function canDeleteFromLive($member = null) { |
||
1104 | |||
1105 | /** |
||
1106 | * Stub method to get the site config, unless the current class can provide an alternate. |
||
1107 | * |
||
1108 | * @return SiteConfig |
||
1109 | */ |
||
1110 | public function getSiteConfig() { |
||
1119 | |||
1120 | /** |
||
1121 | * Pre-populate the cache of canEdit, canView, canDelete, canPublish permissions. This method will use the static |
||
1122 | * can_(perm)_multiple method for efficiency. |
||
1123 | * |
||
1124 | * @param string $permission The permission: edit, view, publish, approve, etc. |
||
1125 | * @param array $ids An array of page IDs |
||
1126 | * @param callable|string $batchCallback The function/static method to call to calculate permissions. Defaults |
||
1127 | * to 'SiteTree::can_(permission)_multiple' |
||
1128 | */ |
||
1129 | static public function prepopulate_permission_cache($permission = 'CanEditType', $ids, $batchCallback = null) { |
||
1139 | |||
1140 | /** |
||
1141 | * This method is NOT a full replacement for the individual can*() methods, e.g. {@link canEdit()}. Rather than |
||
1142 | * checking (potentially slow) PHP logic, it relies on the database group associations, e.g. the "CanEditType" field |
||
1143 | * plus the "SiteTree_EditorGroups" many-many table. By batch checking multiple records, we can combine the queries |
||
1144 | * efficiently. |
||
1145 | * |
||
1146 | * Caches based on $typeField data. To invalidate the cache, use {@link SiteTree::reset()} or set the $useCached |
||
1147 | * property to FALSE. |
||
1148 | * |
||
1149 | * @param array $ids Of {@link SiteTree} IDs |
||
1150 | * @param int $memberID Member ID |
||
1151 | * @param string $typeField A property on the data record, e.g. "CanEditType". |
||
1152 | * @param string $groupJoinTable A many-many table name on this record, e.g. "SiteTree_EditorGroups" |
||
1153 | * @param string $siteConfigMethod Method to call on {@link SiteConfig} for toplevel items, e.g. "canEdit" |
||
1154 | * @param string $globalPermission If the member doesn't have this permission code, don't bother iterating deeper |
||
1155 | * @param bool $useCached |
||
1156 | * @return array An map of {@link SiteTree} ID keys to boolean values |
||
1157 | */ |
||
1158 | public static function batch_permission_check($ids, $memberID, $typeField, $groupJoinTable, $siteConfigMethod, |
||
1281 | |||
1282 | /** |
||
1283 | * Get the 'can edit' information for a number of SiteTree pages. |
||
1284 | * |
||
1285 | * @param array $ids An array of IDs of the SiteTree pages to look up |
||
1286 | * @param int $memberID ID of member |
||
1287 | * @param bool $useCached Return values from the permission cache if they exist |
||
1288 | * @return array A map where the IDs are keys and the values are booleans stating whether the given page can be |
||
1289 | * edited |
||
1290 | */ |
||
1291 | static public function can_edit_multiple($ids, $memberID, $useCached = true) { |
||
1294 | |||
1295 | /** |
||
1296 | * Get the 'can edit' information for a number of SiteTree pages. |
||
1297 | * |
||
1298 | * @param array $ids An array of IDs of the SiteTree pages to look up |
||
1299 | * @param int $memberID ID of member |
||
1300 | * @param bool $useCached Return values from the permission cache if they exist |
||
1301 | * @return array |
||
1302 | */ |
||
1303 | static public function can_delete_multiple($ids, $memberID, $useCached = true) { |
||
1362 | |||
1363 | /** |
||
1364 | * Collate selected descendants of this page. |
||
1365 | * |
||
1366 | * {@link $condition} will be evaluated on each descendant, and if it is succeeds, that item will be added to the |
||
1367 | * $collator array. |
||
1368 | * |
||
1369 | * @param string $condition The PHP condition to be evaluated. The page will be called $item |
||
1370 | * @param array $collator An array, passed by reference, to collect all of the matching descendants. |
||
1371 | * @return bool |
||
1372 | */ |
||
1373 | public function collateDescendants($condition, &$collator) { |
||
1382 | |||
1383 | /** |
||
1384 | * Return the title, description, keywords and language metatags. |
||
1385 | * |
||
1386 | * @todo Move <title> tag in separate getter for easier customization and more obvious usage |
||
1387 | * |
||
1388 | * @param bool $includeTitle Show default <title>-tag, set to false for custom templating |
||
1389 | * @return string The XHTML metatags |
||
1390 | */ |
||
1391 | public function MetaTags($includeTitle = true) { |
||
1424 | |||
1425 | /** |
||
1426 | * Returns the object that contains the content that a user would associate with this page. |
||
1427 | * |
||
1428 | * Ordinarily, this is just the page itself, but for example on RedirectorPages or VirtualPages ContentSource() will |
||
1429 | * return the page that is linked to. |
||
1430 | * |
||
1431 | * @return $this |
||
1432 | */ |
||
1433 | public function ContentSource() { |
||
1436 | |||
1437 | /** |
||
1438 | * Add default records to database. |
||
1439 | * |
||
1440 | * This function is called whenever the database is built, after the database tables have all been created. Overload |
||
1441 | * this to add default records when the database is built, but make sure you call parent::requireDefaultRecords(). |
||
1442 | */ |
||
1443 | public function requireDefaultRecords() { |
||
1492 | |||
1493 | protected function onBeforeWrite() { |
||
1543 | |||
1544 | public function syncLinkTracking() { |
||
1547 | |||
1548 | public function onAfterWrite() { |
||
1567 | |||
1568 | public function onBeforeDelete() { |
||
1578 | |||
1579 | public function onAfterDelete() { |
||
1592 | |||
1593 | public function flushCache($persistent = true) { |
||
1597 | |||
1598 | public function validate() { |
||
1635 | |||
1636 | /** |
||
1637 | * Returns true if this object has a URLSegment value that does not conflict with any other objects. This method |
||
1638 | * checks for: |
||
1639 | * - A page with the same URLSegment that has a conflict |
||
1640 | * - Conflicts with actions on the parent page |
||
1641 | * - A conflict caused by a root page having the same URLSegment as a class name |
||
1642 | * |
||
1643 | * @return bool |
||
1644 | */ |
||
1645 | public function validURLSegment() { |
||
1679 | |||
1680 | /** |
||
1681 | * Generate a URL segment based on the title provided. |
||
1682 | * |
||
1683 | * If {@link Extension}s wish to alter URL segment generation, they can do so by defining |
||
1684 | * updateURLSegment(&$url, $title). $url will be passed by reference and should be modified. $title will contain |
||
1685 | * the title that was originally used as the source of this generated URL. This lets extensions either start from |
||
1686 | * scratch, or incrementally modify the generated URL. |
||
1687 | * |
||
1688 | * @param string $title Page title |
||
1689 | * @return string Generated url segment |
||
1690 | */ |
||
1691 | public function generateURLSegment($title){ |
||
1703 | |||
1704 | /** |
||
1705 | * Gets the URL segment for the latest draft version of this page. |
||
1706 | * |
||
1707 | * @return string |
||
1708 | */ |
||
1709 | public function getStageURLSegment() { |
||
1715 | |||
1716 | /** |
||
1717 | * Gets the URL segment for the currently published version of this page. |
||
1718 | * |
||
1719 | * @return string |
||
1720 | */ |
||
1721 | public function getLiveURLSegment() { |
||
1727 | |||
1728 | /** |
||
1729 | * Rewrites any linked images on this page. |
||
1730 | * Non-image files should be linked via shortcodes |
||
1731 | * Triggers the onRenameLinkedAsset action on extensions. |
||
1732 | * TODO: This doesn't work for HTMLText fields on other tables. |
||
1733 | */ |
||
1734 | public function rewriteFileLinks() { |
||
1768 | |||
1769 | /** |
||
1770 | * Returns the pages that depend on this page. This includes virtual pages, pages that link to it, etc. |
||
1771 | * |
||
1772 | * @param bool $includeVirtuals Set to false to exlcude virtual pages. |
||
1773 | * @return ArrayList |
||
1774 | */ |
||
1775 | public function DependentPages($includeVirtuals = true) { |
||
1825 | |||
1826 | /** |
||
1827 | * Return all virtual pages that link to this page. |
||
1828 | * |
||
1829 | * @return DataList |
||
1830 | */ |
||
1831 | public function VirtualPages() { |
||
1853 | |||
1854 | /** |
||
1855 | * Returns a FieldList with which to create the main editing form. |
||
1856 | * |
||
1857 | * You can override this in your child classes to add extra fields - first get the parent fields using |
||
1858 | * parent::getCMSFields(), then use addFieldToTab() on the FieldList. |
||
1859 | * |
||
1860 | * See {@link getSettingsFields()} for a different set of fields concerned with configuration aspects on the record, |
||
1861 | * e.g. access control. |
||
1862 | * |
||
1863 | * @return FieldList The fields to be displayed in the CMS |
||
1864 | */ |
||
1865 | public function getCMSFields() { |
||
2045 | |||
2046 | |||
2047 | /** |
||
2048 | * Returns fields related to configuration aspects on this record, e.g. access control. See {@link getCMSFields()} |
||
2049 | * for content-related fields. |
||
2050 | * |
||
2051 | * @return FieldList |
||
2052 | */ |
||
2053 | public function getSettingsFields() { |
||
2161 | |||
2162 | /** |
||
2163 | * @param bool $includerelations A boolean value to indicate if the labels returned should include relation fields |
||
2164 | * @return array |
||
2165 | */ |
||
2166 | public function fieldLabels($includerelations = true) { |
||
2204 | |||
2205 | /** |
||
2206 | * Get the actions available in the CMS for this page - eg Save, Publish. |
||
2207 | * |
||
2208 | * Frontend scripts and styles know how to handle the following FormFields: |
||
2209 | * - top-level FormActions appear as standalone buttons |
||
2210 | * - top-level CompositeField with FormActions within appear as grouped buttons |
||
2211 | * - TabSet & Tabs appear as a drop ups |
||
2212 | * - FormActions within the Tab are restyled as links |
||
2213 | * - major actions can provide alternate states for richer presentation (see ssui.button widget extension) |
||
2214 | * |
||
2215 | * @return FieldList The available actions for this page. |
||
2216 | */ |
||
2217 | public function getCMSActions() { |
||
2368 | |||
2369 | /** |
||
2370 | * Publish this page. |
||
2371 | * |
||
2372 | * @uses SiteTreeExtension->onBeforePublish() |
||
2373 | * @uses SiteTreeExtension->onAfterPublish() |
||
2374 | * @return bool True if published |
||
2375 | */ |
||
2376 | public function doPublish() { |
||
2418 | |||
2419 | /** |
||
2420 | * Unpublish this page - remove it from the live site |
||
2421 | * |
||
2422 | * @uses SiteTreeExtension->onBeforeUnpublish() |
||
2423 | * @uses SiteTreeExtension->onAfterUnpublish() |
||
2424 | */ |
||
2425 | public function doUnpublish() { |
||
2463 | |||
2464 | /** |
||
2465 | * Revert the draft changes: replace the draft content with the content on live |
||
2466 | */ |
||
2467 | public function doRevertToLive() { |
||
2485 | |||
2486 | /** |
||
2487 | * Determine if this page references a parent which is archived, and not available in stage |
||
2488 | * |
||
2489 | * @return bool True if there is an archived parent |
||
2490 | */ |
||
2491 | protected function isParentArchived() { |
||
2500 | |||
2501 | /** |
||
2502 | * Restore the content in the active copy of this SiteTree page to the stage site. |
||
2503 | * |
||
2504 | * @return self |
||
2505 | */ |
||
2506 | public function doRestoreToStage() { |
||
2542 | |||
2543 | /** |
||
2544 | * Removes the page from both live and stage |
||
2545 | * |
||
2546 | * @return bool Success |
||
2547 | */ |
||
2548 | public function doArchive() { |
||
2560 | |||
2561 | /** |
||
2562 | * Check if the current user is allowed to archive this page. |
||
2563 | * If extended, ensure that both canDelete and canDeleteFromLive are extended also |
||
2564 | * |
||
2565 | * @param Member $member |
||
2566 | * @return bool |
||
2567 | */ |
||
2568 | public function canArchive($member = null) { |
||
2591 | |||
2592 | /** |
||
2593 | * Synonym of {@link doUnpublish} |
||
2594 | */ |
||
2595 | public function doDeleteFromLive() { |
||
2598 | |||
2599 | /** |
||
2600 | * Check if this page is new - that is, if it has yet to have been written to the database. |
||
2601 | * |
||
2602 | * @return bool |
||
2603 | */ |
||
2604 | public function isNew() { |
||
2615 | |||
2616 | |||
2617 | /** |
||
2618 | * Check if this page has been published. |
||
2619 | * |
||
2620 | * @return bool |
||
2621 | */ |
||
2622 | public function isPublished() { |
||
2630 | |||
2631 | /** |
||
2632 | * Get the class dropdown used in the CMS to change the class of a page. This returns the list of options in the |
||
2633 | * dropdown as a Map from class name to singular name. Filters by {@link SiteTree->canCreate()}, as well as |
||
2634 | * {@link SiteTree::$needs_permission}. |
||
2635 | * |
||
2636 | * @return array |
||
2637 | */ |
||
2638 | protected function getClassDropdown() { |
||
2681 | |||
2682 | /** |
||
2683 | * Returns an array of the class names of classes that are allowed to be children of this class. |
||
2684 | * |
||
2685 | * @return string[] |
||
2686 | */ |
||
2687 | public function allowedChildren() { |
||
2707 | |||
2708 | /** |
||
2709 | * Returns the class name of the default class for children of this page. |
||
2710 | * |
||
2711 | * @return string |
||
2712 | */ |
||
2713 | public function defaultChild() { |
||
2722 | |||
2723 | /** |
||
2724 | * Returns the class name of the default class for the parent of this page. |
||
2725 | * |
||
2726 | * @return string |
||
2727 | */ |
||
2728 | public function defaultParent() { |
||
2731 | |||
2732 | /** |
||
2733 | * Get the title for use in menus for this page. If the MenuTitle field is set it returns that, else it returns the |
||
2734 | * Title field. |
||
2735 | * |
||
2736 | * @return string |
||
2737 | */ |
||
2738 | public function getMenuTitle(){ |
||
2745 | |||
2746 | |||
2747 | /** |
||
2748 | * Set the menu title for this page. |
||
2749 | * |
||
2750 | * @param string $value |
||
2751 | */ |
||
2752 | public function setMenuTitle($value) { |
||
2759 | |||
2760 | /** |
||
2761 | * A flag provides the user with additional data about the current page status, for example a "removed from draft" |
||
2762 | * status. Each page can have more than one status flag. Returns a map of a unique key to a (localized) title for |
||
2763 | * the flag. The unique key can be reused as a CSS class. Use the 'updateStatusFlags' extension point to customize |
||
2764 | * the flags. |
||
2765 | * |
||
2766 | * Example (simple): |
||
2767 | * "deletedonlive" => "Deleted" |
||
2768 | * |
||
2769 | * Example (with optional title attribute): |
||
2770 | * "deletedonlive" => array('text' => "Deleted", 'title' => 'This page has been deleted') |
||
2771 | * |
||
2772 | * @param bool $cached Whether to serve the fields from cache; false regenerate them |
||
2773 | * @return array |
||
2774 | */ |
||
2775 | public function getStatusFlags($cached = true) { |
||
2809 | |||
2810 | /** |
||
2811 | * getTreeTitle will return three <span> html DOM elements, an empty <span> with the class 'jstree-pageicon' in |
||
2812 | * front, following by a <span> wrapping around its MenutTitle, then following by a <span> indicating its |
||
2813 | * publication status. |
||
2814 | * |
||
2815 | * @return string An HTML string ready to be directly used in a template |
||
2816 | */ |
||
2817 | public function getTreeTitle() { |
||
2846 | |||
2847 | /** |
||
2848 | * Returns the page in the current page stack of the given level. Level(1) will return the main menu item that |
||
2849 | * we're currently inside, etc. |
||
2850 | * |
||
2851 | * @param int $level |
||
2852 | * @return SiteTree |
||
2853 | */ |
||
2854 | public function Level($level) { |
||
2863 | |||
2864 | /** |
||
2865 | * Gets the depth of this page in the sitetree, where 1 is the root level |
||
2866 | * |
||
2867 | * @return int |
||
2868 | */ |
||
2869 | public function getPageLevel() { |
||
2875 | |||
2876 | /** |
||
2877 | * Return the CSS classes to apply to this node in the CMS tree. |
||
2878 | * |
||
2879 | * @param string $numChildrenMethod |
||
2880 | * @return string |
||
2881 | */ |
||
2882 | public function CMSTreeClasses($numChildrenMethod="numChildren") { |
||
2913 | |||
2914 | /** |
||
2915 | * Compares current draft with live version, and returns true if no draft version of this page exists but the page |
||
2916 | * is still published (eg, after triggering "Delete from draft site" in the CMS). |
||
2917 | * |
||
2918 | * @return bool |
||
2919 | */ |
||
2920 | public function getIsDeletedFromStage() { |
||
2929 | |||
2930 | /** |
||
2931 | * Return true if this page exists on the live site |
||
2932 | * |
||
2933 | * @return bool |
||
2934 | */ |
||
2935 | public function getExistsOnLive() { |
||
2938 | |||
2939 | /** |
||
2940 | * Compares current draft with live version, and returns true if these versions differ, meaning there have been |
||
2941 | * unpublished changes to the draft site. |
||
2942 | * |
||
2943 | * @return bool |
||
2944 | */ |
||
2945 | public function getIsModifiedOnStage() { |
||
2957 | |||
2958 | /** |
||
2959 | * Compares current draft with live version, and returns true if no live version exists, meaning the page was never |
||
2960 | * published. |
||
2961 | * |
||
2962 | * @return bool |
||
2963 | */ |
||
2964 | public function getIsAddedToStage() { |
||
2973 | |||
2974 | /** |
||
2975 | * Stops extendCMSFields() being called on getCMSFields(). This is useful when you need access to fields added by |
||
2976 | * subclasses of SiteTree in a extension. Call before calling parent::getCMSFields(), and reenable afterwards. |
||
2977 | */ |
||
2978 | static public function disableCMSFieldsExtensions() { |
||
2981 | |||
2982 | /** |
||
2983 | * Reenables extendCMSFields() being called on getCMSFields() after it has been disabled by |
||
2984 | * disableCMSFieldsExtensions(). |
||
2985 | */ |
||
2986 | static public function enableCMSFieldsExtensions() { |
||
2989 | |||
2990 | public function providePermissions() { |
||
3024 | |||
3025 | /** |
||
3026 | * Return the translated Singular name. |
||
3027 | * |
||
3028 | * @return string |
||
3029 | */ |
||
3030 | public function i18n_singular_name() { |
||
3035 | |||
3036 | /** |
||
3037 | * Overloaded to also provide entities for 'Page' class which is usually located in custom code, hence textcollector |
||
3038 | * picks it up for the wrong folder. |
||
3039 | * |
||
3040 | * @return array |
||
3041 | */ |
||
3042 | public function provideI18nEntities() { |
||
3058 | |||
3059 | /** |
||
3060 | * Returns 'root' if the current page has no parent, or 'subpage' otherwise |
||
3061 | * |
||
3062 | * @return string |
||
3063 | */ |
||
3064 | public function getParentType() { |
||
3067 | |||
3068 | /** |
||
3069 | * Clear the permissions cache for SiteTree |
||
3070 | */ |
||
3071 | public static function reset() { |
||
3074 | |||
3075 | static public function on_db_reset() { |
||
3078 | |||
3079 | } |
||
3080 |