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 | ||
| 100 | class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvider, CMSPreviewable, Resettable | ||
| 101 | { | ||
| 102 | |||
| 103 | /** | ||
| 104 | * Indicates what kind of children this page type can have. | ||
| 105 | * This can be an array of allowed child classes, or the string "none" - | ||
| 106 | * indicating that this page type can't have children. | ||
| 107 | * If a classname is prefixed by "*", such as "*Page", then only that | ||
| 108 | * class is allowed - no subclasses. Otherwise, the class and all its | ||
| 109 | * subclasses are allowed. | ||
| 110 |      * To control allowed children on root level (no parent), use {@link $can_be_root}. | ||
| 111 | * | ||
| 112 | * Note that this setting is cached when used in the CMS, use the "flush" query parameter to clear it. | ||
| 113 | * | ||
| 114 | * @config | ||
| 115 | * @var array | ||
| 116 | */ | ||
| 117 | private static $allowed_children = [ | ||
| 118 | self::class | ||
| 119 | ]; | ||
| 120 | |||
| 121 | /** | ||
| 122 | * The default child class for this page. | ||
| 123 |      * Note: Value might be cached, see {@link $allowed_chilren}. | ||
| 124 | * | ||
| 125 | * @config | ||
| 126 | * @var string | ||
| 127 | */ | ||
| 128 | private static $default_child = "Page"; | ||
| 129 | |||
| 130 | /** | ||
| 131 | * Default value for SiteTree.ClassName enum | ||
| 132 |      * {@see DBClassName::getDefault} | ||
| 133 | * | ||
| 134 | * @config | ||
| 135 | * @var string | ||
| 136 | */ | ||
| 137 | private static $default_classname = "Page"; | ||
|  | |||
| 138 | |||
| 139 | /** | ||
| 140 | * The default parent class for this page. | ||
| 141 |      * Note: Value might be cached, see {@link $allowed_chilren}. | ||
| 142 | * | ||
| 143 | * @config | ||
| 144 | * @var string | ||
| 145 | */ | ||
| 146 | private static $default_parent = null; | ||
| 147 | |||
| 148 | /** | ||
| 149 | * Controls whether a page can be in the root of the site tree. | ||
| 150 |      * Note: Value might be cached, see {@link $allowed_chilren}. | ||
| 151 | * | ||
| 152 | * @config | ||
| 153 | * @var bool | ||
| 154 | */ | ||
| 155 | private static $can_be_root = true; | ||
| 156 | |||
| 157 | /** | ||
| 158 | * List of permission codes a user can have to allow a user to create a page of this type. | ||
| 159 |      * Note: Value might be cached, see {@link $allowed_chilren}. | ||
| 160 | * | ||
| 161 | * @config | ||
| 162 | * @var array | ||
| 163 | */ | ||
| 164 | private static $need_permission = null; | ||
| 165 | |||
| 166 | /** | ||
| 167 | * If you extend a class, and don't want to be able to select the old class | ||
| 168 | * in the cms, set this to the old class name. Eg, if you extended Product | ||
| 169 | * to make ImprovedProduct, then you would set $hide_ancestor to Product. | ||
| 170 | * | ||
| 171 | * @config | ||
| 172 | * @var string | ||
| 173 | */ | ||
| 174 | private static $hide_ancestor = null; | ||
| 175 | |||
| 176 | private static $db = array( | ||
| 177 | "URLSegment" => "Varchar(255)", | ||
| 178 | "Title" => "Varchar(255)", | ||
| 179 | "MenuTitle" => "Varchar(100)", | ||
| 180 | "Content" => "HTMLText", | ||
| 181 | "MetaDescription" => "Text", | ||
| 182 | "ExtraMeta" => "HTMLFragment(['whitelist' => ['meta', 'link']])", | ||
| 183 | "ShowInMenus" => "Boolean", | ||
| 184 | "ShowInSearch" => "Boolean", | ||
| 185 | "Sort" => "Int", | ||
| 186 | "HasBrokenFile" => "Boolean", | ||
| 187 | "HasBrokenLink" => "Boolean", | ||
| 188 | "ReportClass" => "Varchar", | ||
| 189 | ); | ||
| 190 | |||
| 191 | private static $indexes = array( | ||
| 192 | "URLSegment" => true, | ||
| 193 | ); | ||
| 194 | |||
| 195 | private static $has_many = array( | ||
| 196 | "VirtualPages" => VirtualPage::class . '.CopyContentFrom' | ||
| 197 | ); | ||
| 198 | |||
| 199 | private static $owned_by = array( | ||
| 200 | "VirtualPages" | ||
| 201 | ); | ||
| 202 | |||
| 203 | private static $cascade_deletes = [ | ||
| 204 | 'VirtualPages', | ||
| 205 | ]; | ||
| 206 | |||
| 207 | private static $casting = array( | ||
| 208 | "Breadcrumbs" => "HTMLFragment", | ||
| 209 | "LastEdited" => "Datetime", | ||
| 210 | "Created" => "Datetime", | ||
| 211 | 'Link' => 'Text', | ||
| 212 | 'RelativeLink' => 'Text', | ||
| 213 | 'AbsoluteLink' => 'Text', | ||
| 214 | 'CMSEditLink' => 'Text', | ||
| 215 | 'TreeTitle' => 'HTMLFragment', | ||
| 216 | 'MetaTags' => 'HTMLFragment', | ||
| 217 | ); | ||
| 218 | |||
| 219 | private static $defaults = array( | ||
| 220 | "ShowInMenus" => 1, | ||
| 221 | "ShowInSearch" => 1, | ||
| 222 | ); | ||
| 223 | |||
| 224 | private static $table_name = 'SiteTree'; | ||
| 225 | |||
| 226 | private static $versioning = array( | ||
| 227 | "Stage", "Live" | ||
| 228 | ); | ||
| 229 | |||
| 230 | private static $default_sort = "\"Sort\""; | ||
| 231 | |||
| 232 | /** | ||
| 233 | * If this is false, the class cannot be created in the CMS by regular content authors, only by ADMINs. | ||
| 234 | * @var boolean | ||
| 235 | * @config | ||
| 236 | */ | ||
| 237 | private static $can_create = true; | ||
| 238 | |||
| 239 | /** | ||
| 240 | * Icon to use in the CMS page tree. This should be the full filename, relative to the webroot. | ||
| 241 | * Also supports custom CSS rule contents (applied to the correct selector for the tree UI implementation). | ||
| 242 | * | ||
| 243 | * @see CMSMain::generateTreeStylingCSS() | ||
| 244 | * @config | ||
| 245 | * @var string | ||
| 246 | */ | ||
| 247 | private static $icon = null; | ||
| 248 | |||
| 249 | private static $extensions = [ | ||
| 250 | Hierarchy::class, | ||
| 251 | Versioned::class, | ||
| 252 | SiteTreeLinkTracking::class, | ||
| 253 | InheritedPermissionsExtension::class, | ||
| 254 | ]; | ||
| 255 | |||
| 256 | private static $searchable_fields = array( | ||
| 257 | 'Title', | ||
| 258 | 'Content', | ||
| 259 | ); | ||
| 260 | |||
| 261 | private static $field_labels = array( | ||
| 262 | 'URLSegment' => 'URL' | ||
| 263 | ); | ||
| 264 | |||
| 265 | /** | ||
| 266 | * @config | ||
| 267 | */ | ||
| 268 | private static $nested_urls = true; | ||
| 269 | |||
| 270 | /** | ||
| 271 | * @config | ||
| 272 | */ | ||
| 273 | private static $create_default_pages = true; | ||
| 274 | |||
| 275 | /** | ||
| 276 | * This controls whether of not extendCMSFields() is called by getCMSFields. | ||
| 277 | */ | ||
| 278 | private static $runCMSFieldsExtensions = true; | ||
| 279 | |||
| 280 | /** | ||
| 281 | * @config | ||
| 282 | * @var boolean | ||
| 283 | */ | ||
| 284 | private static $enforce_strict_hierarchy = true; | ||
| 285 | |||
| 286 | /** | ||
| 287 | * The value used for the meta generator tag. Leave blank to omit the tag. | ||
| 288 | * | ||
| 289 | * @config | ||
| 290 | * @var string | ||
| 291 | */ | ||
| 292 | private static $meta_generator = 'SilverStripe - http://silverstripe.org'; | ||
| 293 | |||
| 294 | protected $_cache_statusFlags = null; | ||
| 295 | |||
| 296 | /** | ||
| 297 | * Plural form for SiteTree / Page classes. Not inherited by subclasses. | ||
| 298 | * | ||
| 299 | * @config | ||
| 300 | * @var string | ||
| 301 | */ | ||
| 302 | private static $base_plural_name = 'Pages'; | ||
| 303 | |||
| 304 | /** | ||
| 305 | * Plural form for SiteTree / Page classes. Not inherited by subclasses. | ||
| 306 | * | ||
| 307 | * @config | ||
| 308 | * @var string | ||
| 309 | */ | ||
| 310 | private static $base_singular_name = 'Page'; | ||
| 311 | |||
| 312 | /** | ||
| 313 | * Description of the class functionality, typically shown to a user | ||
| 314 |      * when selecting which page type to create. Translated through {@link provideI18nEntities()}. | ||
| 315 | * | ||
| 316 | * @see SiteTree::classDescription() | ||
| 317 | * @see SiteTree::i18n_classDescription() | ||
| 318 | * | ||
| 319 | * @config | ||
| 320 | * @var string | ||
| 321 | */ | ||
| 322 | private static $description = null; | ||
| 323 | |||
| 324 | /** | ||
| 325 | * Description for Page and SiteTree classes, but not inherited by subclasses. | ||
| 326 | * override SiteTree::$description in subclasses instead. | ||
| 327 | * | ||
| 328 | * @see SiteTree::classDescription() | ||
| 329 | * @see SiteTree::i18n_classDescription() | ||
| 330 | * | ||
| 331 | * @config | ||
| 332 | * @var string | ||
| 333 | */ | ||
| 334 | private static $base_description = 'Generic content page'; | ||
| 335 | |||
| 336 | /** | ||
| 337 |      * Fetches the {@link SiteTree} object that maps to a link. | ||
| 338 | * | ||
| 339 |      * If you have enabled {@link SiteTree::config()->nested_urls} on this site, then you can use a nested link such as | ||
| 340 | * "about-us/staff/", and this function will traverse down the URL chain and grab the appropriate link. | ||
| 341 | * | ||
| 342 | * Note that if no model can be found, this method will fall over to a extended alternateGetByLink method provided | ||
| 343 |      * by a extension attached to {@link SiteTree} | ||
| 344 | * | ||
| 345 | * @param string $link The link of the page to search for | ||
| 346 | * @param bool $cache True (default) to use caching, false to force a fresh search from the database | ||
| 347 | * @return SiteTree | ||
| 348 | */ | ||
| 349 | public static function get_by_link($link, $cache = true) | ||
| 350 |     { | ||
| 351 |         if (trim($link, '/')) { | ||
| 352 | $link = trim(Director::makeRelative($link), '/'); | ||
| 353 |         } else { | ||
| 354 | $link = RootURLController::get_homepage_link(); | ||
| 355 | } | ||
| 356 | |||
| 357 |         $parts = preg_split('|/+|', $link); | ||
| 358 | |||
| 359 | // Grab the initial root level page to traverse down from. | ||
| 360 | $URLSegment = array_shift($parts); | ||
| 361 |         $conditions = array('"SiteTree"."URLSegment"' => rawurlencode($URLSegment)); | ||
| 362 |         if (self::config()->nested_urls) { | ||
| 363 |             $conditions[] = array('"SiteTree"."ParentID"' => 0); | ||
| 364 | } | ||
| 365 | /** @var SiteTree $sitetree */ | ||
| 366 | $sitetree = DataObject::get_one(self::class, $conditions, $cache); | ||
| 367 | |||
| 368 | /// Fall back on a unique URLSegment for b/c. | ||
| 369 | if (!$sitetree | ||
| 370 | && self::config()->nested_urls | ||
| 371 | && $sitetree = DataObject::get_one(self::class, array( | ||
| 372 | '"SiteTree"."URLSegment"' => $URLSegment | ||
| 373 | ), $cache) | ||
| 374 |         ) { | ||
| 375 | return $sitetree; | ||
| 376 | } | ||
| 377 | |||
| 378 | // Attempt to grab an alternative page from extensions. | ||
| 379 |         if (!$sitetree) { | ||
| 380 | $parentID = self::config()->nested_urls ? 0 : null; | ||
| 381 | |||
| 382 | View Code Duplication |             if ($alternatives = static::singleton()->extend('alternateGetByLink', $URLSegment, $parentID)) { | |
| 383 |                 foreach ($alternatives as $alternative) { | ||
| 384 |                     if ($alternative) { | ||
| 385 | $sitetree = $alternative; | ||
| 386 | } | ||
| 387 | } | ||
| 388 | } | ||
| 389 | |||
| 390 |             if (!$sitetree) { | ||
| 391 | return null; | ||
| 392 | } | ||
| 393 | } | ||
| 394 | |||
| 395 | // Check if we have any more URL parts to parse. | ||
| 396 |         if (!self::config()->nested_urls || !count($parts)) { | ||
| 397 | return $sitetree; | ||
| 398 | } | ||
| 399 | |||
| 400 | // Traverse down the remaining URL segments and grab the relevant SiteTree objects. | ||
| 401 |         foreach ($parts as $segment) { | ||
| 402 | $next = DataObject::get_one( | ||
| 403 | self::class, | ||
| 404 | array( | ||
| 405 | '"SiteTree"."URLSegment"' => $segment, | ||
| 406 | '"SiteTree"."ParentID"' => $sitetree->ID | ||
| 407 | ), | ||
| 408 | $cache | ||
| 409 | ); | ||
| 410 | |||
| 411 |             if (!$next) { | ||
| 412 | $parentID = (int) $sitetree->ID; | ||
| 413 | |||
| 414 | View Code Duplication |                 if ($alternatives = static::singleton()->extend('alternateGetByLink', $segment, $parentID)) { | |
| 415 |                     foreach ($alternatives as $alternative) { | ||
| 416 |                         if ($alternative) { | ||
| 417 | $next = $alternative; | ||
| 418 | } | ||
| 419 | } | ||
| 420 | } | ||
| 421 | |||
| 422 |                 if (!$next) { | ||
| 423 | return null; | ||
| 424 | } | ||
| 425 | } | ||
| 426 | |||
| 427 | $sitetree->destroy(); | ||
| 428 | $sitetree = $next; | ||
| 429 | } | ||
| 430 | |||
| 431 | return $sitetree; | ||
| 432 | } | ||
| 433 | |||
| 434 | /** | ||
| 435 |      * Return a subclass map of SiteTree that shouldn't be hidden through {@link SiteTree::$hide_ancestor} | ||
| 436 | * | ||
| 437 | * @return array | ||
| 438 | */ | ||
| 439 | public static function page_type_classes() | ||
| 440 |     { | ||
| 441 | $classes = ClassInfo::getValidSubClasses(); | ||
| 442 | |||
| 443 | $baseClassIndex = array_search(self::class, $classes); | ||
| 444 |         if ($baseClassIndex !== false) { | ||
| 445 | unset($classes[$baseClassIndex]); | ||
| 446 | } | ||
| 447 | |||
| 448 | $kill_ancestors = array(); | ||
| 449 | |||
| 450 | // figure out if there are any classes we don't want to appear | ||
| 451 |         foreach ($classes as $class) { | ||
| 452 | $instance = singleton($class); | ||
| 453 | |||
| 454 | // do any of the progeny want to hide an ancestor? | ||
| 455 |             if ($ancestor_to_hide = $instance->stat('hide_ancestor')) { | ||
| 456 | // note for killing later | ||
| 457 | $kill_ancestors[] = $ancestor_to_hide; | ||
| 458 | } | ||
| 459 | } | ||
| 460 | |||
| 461 | // If any of the descendents don't want any of the elders to show up, cruelly render the elders surplus to | ||
| 462 | // requirements | ||
| 463 |         if ($kill_ancestors) { | ||
| 464 | $kill_ancestors = array_unique($kill_ancestors); | ||
| 465 |             foreach ($kill_ancestors as $mark) { | ||
| 466 | // unset from $classes | ||
| 467 | $idx = array_search($mark, $classes, true); | ||
| 468 |                 if ($idx !== false) { | ||
| 469 | unset($classes[$idx]); | ||
| 470 | } | ||
| 471 | } | ||
| 472 | } | ||
| 473 | |||
| 474 | return $classes; | ||
| 475 | } | ||
| 476 | |||
| 477 | /** | ||
| 478 | * Replace a "[sitetree_link id=n]" shortcode with a link to the page with the corresponding ID. | ||
| 479 | * | ||
| 480 | * @param array $arguments | ||
| 481 | * @param string $content | ||
| 482 | * @param ShortcodeParser $parser | ||
| 483 | * @return string | ||
| 484 | */ | ||
| 485 | public static function link_shortcode_handler($arguments, $content = null, $parser = null) | ||
| 486 |     { | ||
| 487 |         if (!isset($arguments['id']) || !is_numeric($arguments['id'])) { | ||
| 488 | return null; | ||
| 489 | } | ||
| 490 | |||
| 491 | /** @var SiteTree $page */ | ||
| 492 | if (!($page = DataObject::get_by_id(self::class, $arguments['id'])) // Get the current page by ID. | ||
| 493 | && !($page = Versioned::get_latest_version(self::class, $arguments['id'])) // Attempt link to old version. | ||
| 494 |         ) { | ||
| 495 | return null; // There were no suitable matches at all. | ||
| 496 | } | ||
| 497 | |||
| 498 | /** @var SiteTree $page */ | ||
| 499 | $link = Convert::raw2att($page->Link()); | ||
| 500 | |||
| 501 |         if ($content) { | ||
| 502 |             return sprintf('<a href="%s">%s</a>', $link, $parser->parse($content)); | ||
| 503 |         } else { | ||
| 504 | return $link; | ||
| 505 | } | ||
| 506 | } | ||
| 507 | |||
| 508 | /** | ||
| 509 |      * Return the link for this {@link SiteTree} object, with the {@link Director::baseURL()} included. | ||
| 510 | * | ||
| 511 | * @param string $action Optional controller action (method). | ||
| 512 | * Note: URI encoding of this parameter is applied automatically through template casting, | ||
| 513 |      *                       don't encode the passed parameter. Please use {@link Controller::join_links()} instead to | ||
| 514 | * append GET parameters. | ||
| 515 | * @return string | ||
| 516 | */ | ||
| 517 | public function Link($action = null) | ||
| 518 |     { | ||
| 519 | return Controller::join_links(Director::baseURL(), $this->RelativeLink($action)); | ||
| 520 | } | ||
| 521 | |||
| 522 | /** | ||
| 523 | * Get the absolute URL for this page, including protocol and host. | ||
| 524 | * | ||
| 525 |      * @param string $action See {@link Link()} | ||
| 526 | * @return string | ||
| 527 | */ | ||
| 528 | public function AbsoluteLink($action = null) | ||
| 529 |     { | ||
| 530 |         if ($this->hasMethod('alternateAbsoluteLink')) { | ||
| 531 | return $this->alternateAbsoluteLink($action); | ||
| 532 |         } else { | ||
| 533 | return Director::absoluteURL($this->Link($action)); | ||
| 534 | } | ||
| 535 | } | ||
| 536 | |||
| 537 | /** | ||
| 538 | * Base link used for previewing. Defaults to absolute URL, in order to account for domain changes, e.g. on multi | ||
| 539 |      * site setups. Does not contain hints about the stage, see {@link SilverStripeNavigator} for details. | ||
| 540 | * | ||
| 541 |      * @param string $action See {@link Link()} | ||
| 542 | * @return string | ||
| 543 | */ | ||
| 544 | public function PreviewLink($action = null) | ||
| 545 |     { | ||
| 546 |         if ($this->hasMethod('alternatePreviewLink')) { | ||
| 547 |             Deprecation::notice('5.0', 'Use updatePreviewLink or override PreviewLink method'); | ||
| 548 | return $this->alternatePreviewLink($action); | ||
| 549 | } | ||
| 550 | |||
| 551 | $link = $this->AbsoluteLink($action); | ||
| 552 |         $this->extend('updatePreviewLink', $link, $action); | ||
| 553 | return $link; | ||
| 554 | } | ||
| 555 | |||
| 556 | public function getMimeType() | ||
| 557 |     { | ||
| 558 | return 'text/html'; | ||
| 559 | } | ||
| 560 | |||
| 561 | /** | ||
| 562 |      * Return the link for this {@link SiteTree} object relative to the SilverStripe root. | ||
| 563 | * | ||
| 564 | * By default, if this page is the current home page, and there is no action specified then this will return a link | ||
| 565 | * to the root of the site. However, if you set the $action parameter to TRUE then the link will not be rewritten | ||
| 566 | * and returned in its full form. | ||
| 567 | * | ||
| 568 | * @uses RootURLController::get_homepage_link() | ||
| 569 | * | ||
| 570 |      * @param string $action See {@link Link()} | ||
| 571 | * @return string | ||
| 572 | */ | ||
| 573 | public function RelativeLink($action = null) | ||
| 574 |     { | ||
| 575 |         if ($this->ParentID && self::config()->nested_urls) { | ||
| 576 | $parent = $this->Parent(); | ||
| 577 | // If page is removed select parent from version history (for archive page view) | ||
| 578 |             if ((!$parent || !$parent->exists()) && !$this->isOnDraft()) { | ||
| 579 | $parent = Versioned::get_latest_version(self::class, $this->ParentID); | ||
| 580 | } | ||
| 581 | $base = $parent->RelativeLink($this->URLSegment); | ||
| 582 |         } elseif (!$action && $this->URLSegment == RootURLController::get_homepage_link()) { | ||
| 583 | // Unset base for root-level homepages. | ||
| 584 | // Note: Homepages with action parameters (or $action === true) | ||
| 585 | // need to retain their URLSegment. | ||
| 586 | $base = null; | ||
| 587 |         } else { | ||
| 588 | $base = $this->URLSegment; | ||
| 589 | } | ||
| 590 | |||
| 591 |         $this->extend('updateRelativeLink', $base, $action); | ||
| 592 | |||
| 593 | // Legacy support: If $action === true, retain URLSegment for homepages, | ||
| 594 | // but don't append any action | ||
| 595 |         if ($action === true) { | ||
| 596 | $action = null; | ||
| 597 | } | ||
| 598 | |||
| 599 | return Controller::join_links($base, '/', $action); | ||
| 600 | } | ||
| 601 | |||
| 602 | /** | ||
| 603 | * Get the absolute URL for this page on the Live site. | ||
| 604 | * | ||
| 605 | * @param bool $includeStageEqualsLive Whether to append the URL with ?stage=Live to force Live mode | ||
| 606 | * @return string | ||
| 607 | */ | ||
| 608 | public function getAbsoluteLiveLink($includeStageEqualsLive = true) | ||
| 609 |     { | ||
| 610 | $oldReadingMode = Versioned::get_reading_mode(); | ||
| 611 | Versioned::set_stage(Versioned::LIVE); | ||
| 612 | /** @var SiteTree $live */ | ||
| 613 | $live = Versioned::get_one_by_stage(self::class, Versioned::LIVE, array( | ||
| 614 | '"SiteTree"."ID"' => $this->ID | ||
| 615 | )); | ||
| 616 |         if ($live) { | ||
| 617 | $link = $live->AbsoluteLink(); | ||
| 618 |             if ($includeStageEqualsLive) { | ||
| 619 | $link = Controller::join_links($link, '?stage=Live'); | ||
| 620 | } | ||
| 621 |         } else { | ||
| 622 | $link = null; | ||
| 623 | } | ||
| 624 | |||
| 625 | Versioned::set_reading_mode($oldReadingMode); | ||
| 626 | return $link; | ||
| 627 | } | ||
| 628 | |||
| 629 | /** | ||
| 630 | * Generates a link to edit this page in the CMS. | ||
| 631 | * | ||
| 632 | * @return string | ||
| 633 | */ | ||
| 634 | public function CMSEditLink() | ||
| 635 |     { | ||
| 636 | $link = Controller::join_links( | ||
| 637 |             CMSPageEditController::singleton()->Link('show'), | ||
| 638 | $this->ID | ||
| 639 | ); | ||
| 640 | return Director::absoluteURL($link); | ||
| 641 | } | ||
| 642 | |||
| 643 | |||
| 644 | /** | ||
| 645 | * Return a CSS identifier generated from this page's link. | ||
| 646 | * | ||
| 647 | * @return string The URL segment | ||
| 648 | */ | ||
| 649 | public function ElementName() | ||
| 650 |     { | ||
| 651 |         return str_replace('/', '-', trim($this->RelativeLink(true), '/')); | ||
| 652 | } | ||
| 653 | |||
| 654 | /** | ||
| 655 | * Returns true if this is the currently active page being used to handle this request. | ||
| 656 | * | ||
| 657 | * @return bool | ||
| 658 | */ | ||
| 659 | public function isCurrent() | ||
| 660 |     { | ||
| 661 | $currentPage = Director::get_current_page(); | ||
| 662 |         if ($currentPage instanceof ContentController) { | ||
| 663 | $currentPage = $currentPage->data(); | ||
| 664 | } | ||
| 665 |         if ($currentPage instanceof SiteTree) { | ||
| 666 | return $currentPage === $this || $currentPage->ID === $this->ID; | ||
| 667 | } | ||
| 668 | return false; | ||
| 669 | } | ||
| 670 | |||
| 671 | /** | ||
| 672 | * Check if this page is in the currently active section (e.g. it is either current or one of its children is | ||
| 673 | * currently being viewed). | ||
| 674 | * | ||
| 675 | * @return bool | ||
| 676 | */ | ||
| 677 | public function isSection() | ||
| 678 |     { | ||
| 679 | return $this->isCurrent() || ( | ||
| 680 | Director::get_current_page() instanceof SiteTree && in_array($this->ID, Director::get_current_page()->getAncestors()->column()) | ||
| 681 | ); | ||
| 682 | } | ||
| 683 | |||
| 684 | /** | ||
| 685 | * Check if the parent of this page has been removed (or made otherwise unavailable), and is still referenced by | ||
| 686 | * this child. Any such orphaned page may still require access via the CMS, but should not be shown as accessible | ||
| 687 | * to external users. | ||
| 688 | * | ||
| 689 | * @return bool | ||
| 690 | */ | ||
| 691 | public function isOrphaned() | ||
| 692 |     { | ||
| 693 | // Always false for root pages | ||
| 694 |         if (empty($this->ParentID)) { | ||
| 695 | return false; | ||
| 696 | } | ||
| 697 | |||
| 698 | // Parent must exist and not be an orphan itself | ||
| 699 | $parent = $this->Parent(); | ||
| 700 | return !$parent || !$parent->exists() || $parent->isOrphaned(); | ||
| 701 | } | ||
| 702 | |||
| 703 | /** | ||
| 704 |      * Return "link" or "current" depending on if this is the {@link SiteTree::isCurrent()} current page. | ||
| 705 | * | ||
| 706 | * @return string | ||
| 707 | */ | ||
| 708 | public function LinkOrCurrent() | ||
| 709 |     { | ||
| 710 | return $this->isCurrent() ? 'current' : 'link'; | ||
| 711 | } | ||
| 712 | |||
| 713 | /** | ||
| 714 |      * Return "link" or "section" depending on if this is the {@link SiteTree::isSeciton()} current section. | ||
| 715 | * | ||
| 716 | * @return string | ||
| 717 | */ | ||
| 718 | public function LinkOrSection() | ||
| 719 |     { | ||
| 720 | return $this->isSection() ? 'section' : 'link'; | ||
| 721 | } | ||
| 722 | |||
| 723 | /** | ||
| 724 | * Return "link", "current" or "section" depending on if this page is the current page, or not on the current page | ||
| 725 | * but in the current section. | ||
| 726 | * | ||
| 727 | * @return string | ||
| 728 | */ | ||
| 729 | public function LinkingMode() | ||
| 730 |     { | ||
| 731 |         if ($this->isCurrent()) { | ||
| 732 | return 'current'; | ||
| 733 |         } elseif ($this->isSection()) { | ||
| 734 | return 'section'; | ||
| 735 |         } else { | ||
| 736 | return 'link'; | ||
| 737 | } | ||
| 738 | } | ||
| 739 | |||
| 740 | /** | ||
| 741 | * Check if this page is in the given current section. | ||
| 742 | * | ||
| 743 | * @param string $sectionName Name of the section to check | ||
| 744 | * @return bool True if we are in the given section | ||
| 745 | */ | ||
| 746 | public function InSection($sectionName) | ||
| 747 |     { | ||
| 748 | $page = Director::get_current_page(); | ||
| 749 |         while ($page && $page->exists()) { | ||
| 750 |             if ($sectionName == $page->URLSegment) { | ||
| 751 | return true; | ||
| 752 | } | ||
| 753 | $page = $page->Parent(); | ||
| 754 | } | ||
| 755 | return false; | ||
| 756 | } | ||
| 757 | |||
| 758 | /** | ||
| 759 | * Reset Sort on duped page | ||
| 760 | * | ||
| 761 | * @param SiteTree $original | ||
| 762 | * @param bool $doWrite | ||
| 763 | */ | ||
| 764 | public function onBeforeDuplicate($original, $doWrite) | ||
| 765 |     { | ||
| 766 | $this->Sort = 0; | ||
| 767 | } | ||
| 768 | |||
| 769 | /** | ||
| 770 | * Duplicates each child of this node recursively and returns the top-level duplicate node. | ||
| 771 | * | ||
| 772 | * @return static The duplicated object | ||
| 773 | */ | ||
| 774 | public function duplicateWithChildren() | ||
| 775 |     { | ||
| 776 | /** @var SiteTree $clone */ | ||
| 777 | $clone = $this->duplicate(); | ||
| 778 | $children = $this->AllChildren(); | ||
| 779 | |||
| 780 |         if ($children) { | ||
| 781 | /** @var SiteTree $child */ | ||
| 782 | $sort = 0; | ||
| 783 |             foreach ($children as $child) { | ||
| 784 | $childClone = method_exists($child, 'duplicateWithChildren') | ||
| 785 | ? $child->duplicateWithChildren() | ||
| 786 | : $child->duplicate(); | ||
| 787 | $childClone->ParentID = $clone->ID; | ||
| 788 | //retain sort order by manually setting sort values | ||
| 789 | $childClone->Sort = ++$sort; | ||
| 790 | $childClone->write(); | ||
| 791 | } | ||
| 792 | } | ||
| 793 | |||
| 794 | return $clone; | ||
| 795 | } | ||
| 796 | |||
| 797 | /** | ||
| 798 | * Duplicate this node and its children as a child of the node with the given ID | ||
| 799 | * | ||
| 800 | * @param int $id ID of the new node's new parent | ||
| 801 | */ | ||
| 802 | public function duplicateAsChild($id) | ||
| 810 | |||
| 811 | /** | ||
| 812 | * Return a breadcrumb trail to this page. Excludes "hidden" pages (with ShowInMenus=0) by default. | ||
| 813 | * | ||
| 814 | * @param int $maxDepth The maximum depth to traverse. | ||
| 815 | * @param boolean $unlinked Whether to link page titles. | ||
| 816 | * @param boolean|string $stopAtPageType ClassName of a page to stop the upwards traversal. | ||
| 817 | * @param boolean $showHidden Include pages marked with the attribute ShowInMenus = 0 | ||
| 818 | * @return string The breadcrumb trail. | ||
| 819 | */ | ||
| 820 | public function Breadcrumbs($maxDepth = 20, $unlinked = false, $stopAtPageType = false, $showHidden = false, $delimiter = '»') | ||
| 821 |     { | ||
| 822 | $pages = $this->getBreadcrumbItems($maxDepth, $stopAtPageType, $showHidden); | ||
| 823 |         $template = SSViewer::create('BreadcrumbsTemplate'); | ||
| 824 | return $template->process($this->customise(new ArrayData(array( | ||
| 825 | "Pages" => $pages, | ||
| 826 | "Unlinked" => $unlinked, | ||
| 827 | "Delimiter" => $delimiter, | ||
| 828 | )))); | ||
| 829 | } | ||
| 830 | |||
| 831 | |||
| 832 | /** | ||
| 833 | * Returns a list of breadcrumbs for the current page. | ||
| 834 | * | ||
| 835 | * @param int $maxDepth The maximum depth to traverse. | ||
| 836 | * @param boolean|string $stopAtPageType ClassName of a page to stop the upwards traversal. | ||
| 837 | * @param boolean $showHidden Include pages marked with the attribute ShowInMenus = 0 | ||
| 838 | * | ||
| 839 | * @return ArrayList | ||
| 840 | */ | ||
| 841 | public function getBreadcrumbItems($maxDepth = 20, $stopAtPageType = false, $showHidden = false) | ||
| 860 | |||
| 861 | |||
| 862 | /** | ||
| 863 | * Make this page a child of another page. | ||
| 864 | * | ||
| 865 | * If the parent page does not exist, resolve it to a valid ID before updating this page's reference. | ||
| 866 | * | ||
| 867 | * @param SiteTree|int $item Either the parent object, or the parent ID | ||
| 868 | */ | ||
| 869 | public function setParent($item) | ||
| 880 | |||
| 881 | /** | ||
| 882 | * Get the parent of this page. | ||
| 883 | * | ||
| 884 | * @return SiteTree Parent of this page | ||
| 885 | */ | ||
| 886 | public function getParent() | ||
| 893 | |||
| 894 | /** | ||
| 895 | * Return a string of the form "parent - page" or "grandparent - parent - page" using page titles | ||
| 896 | * | ||
| 897 | * @param int $level The maximum amount of levels to traverse. | ||
| 898 | * @param string $separator Seperating string | ||
| 899 | * @return string The resulting string | ||
| 900 | */ | ||
| 901 | public function NestedTitle($level = 2, $separator = " - ") | ||
| 912 | |||
| 913 | /** | ||
| 914 | * This function should return true if the current user can execute this action. It can be overloaded to customise | ||
| 915 | * the security model for an application. | ||
| 916 | * | ||
| 917 |      * Slightly altered from parent behaviour in {@link DataObject->can()}: | ||
| 918 | * - Checks for existence of a method named "can<$perm>()" on the object | ||
| 919 | * - Calls decorators and only returns for FALSE "vetoes" | ||
| 920 |      * - Falls back to {@link Permission::check()} | ||
| 921 | * - Does NOT check for many-many relations named "Can<$perm>" | ||
| 922 | * | ||
| 923 | * @uses DataObjectDecorator->can() | ||
| 924 | * | ||
| 925 | * @param string $perm The permission to be checked, such as 'View' | ||
| 926 | * @param Member $member The member whose permissions need checking. Defaults to the currently logged in user. | ||
| 927 | * @param array $context Context argument for canCreate() | ||
| 928 | * @return bool True if the the member is allowed to do the given action | ||
| 929 | */ | ||
| 930 | public function can($perm, $member = null, $context = array()) | ||
| 954 | |||
| 955 | /** | ||
| 956 | * This function should return true if the current user can add children to this page. It can be overloaded to | ||
| 957 | * customise the security model for an application. | ||
| 958 | * | ||
| 959 | * Denies permission if any of the following conditions is true: | ||
| 960 | * - alternateCanAddChildren() on a extension returns false | ||
| 961 | * - canEdit() is not granted | ||
| 962 |      * - There are no classes defined in {@link $allowed_children} | ||
| 963 | * | ||
| 964 | * @uses SiteTreeExtension->canAddChildren() | ||
| 965 | * @uses canEdit() | ||
| 966 | * @uses $allowed_children | ||
| 967 | * | ||
| 968 | * @param Member|int $member | ||
| 969 | * @return bool True if the current user can add children | ||
| 970 | */ | ||
| 971 | public function canAddChildren($member = null) | ||
| 995 | |||
| 996 | /** | ||
| 997 | * This function should return true if the current user can view this page. It can be overloaded to customise the | ||
| 998 | * security model for an application. | ||
| 999 | * | ||
| 1000 | * Denies permission if any of the following conditions is true: | ||
| 1001 | * - canView() on any extension returns false | ||
| 1002 | * - "CanViewType" directive is set to "Inherit" and any parent page return false for canView() | ||
| 1003 | * - "CanViewType" directive is set to "LoggedInUsers" and no user is logged in | ||
| 1004 | * - "CanViewType" directive is set to "OnlyTheseUsers" and user is not in the given groups | ||
| 1005 | * | ||
| 1006 | * @uses DataExtension->canView() | ||
| 1007 | * @uses ViewerGroups() | ||
| 1008 | * | ||
| 1009 | * @param Member $member | ||
| 1010 | * @return bool True if the current user can view this page | ||
| 1011 | */ | ||
| 1012 | public function canView($member = null) | ||
| 1066 | |||
| 1067 | /** | ||
| 1068 | * Check if this page can be published | ||
| 1069 | * | ||
| 1070 | * @param Member $member | ||
| 1071 | * @return bool | ||
| 1072 | */ | ||
| 1073 | View Code Duplication | public function canPublish($member = null) | |
| 1092 | |||
| 1093 | /** | ||
| 1094 | * This function should return true if the current user can delete this page. It can be overloaded to customise the | ||
| 1095 | * security model for an application. | ||
| 1096 | * | ||
| 1097 | * Denies permission if any of the following conditions is true: | ||
| 1098 | * - canDelete() returns false on any extension | ||
| 1099 | * - canEdit() returns false | ||
| 1100 | * - any descendant page returns false for canDelete() | ||
| 1101 | * | ||
| 1102 | * @uses canDelete() | ||
| 1103 | * @uses SiteTreeExtension->canDelete() | ||
| 1104 | * @uses canEdit() | ||
| 1105 | * | ||
| 1106 | * @param Member $member | ||
| 1107 | * @return bool True if the current user can delete this page | ||
| 1108 | */ | ||
| 1109 | public function canDelete($member = null) | ||
| 1134 | |||
| 1135 | /** | ||
| 1136 | * This function should return true if the current user can create new pages of this class, regardless of class. It | ||
| 1137 | * can be overloaded to customise the security model for an application. | ||
| 1138 | * | ||
| 1139 | * By default, permission to create at the root level is based on the SiteConfig configuration, and permission to | ||
| 1140 | * create beneath a parent is based on the ability to edit that parent page. | ||
| 1141 | * | ||
| 1142 |      * Use {@link canAddChildren()} to control behaviour of creating children under this page. | ||
| 1143 | * | ||
| 1144 | * @uses $can_create | ||
| 1145 | * @uses DataExtension->canCreate() | ||
| 1146 | * | ||
| 1147 | * @param Member $member | ||
| 1148 |      * @param array $context Optional array which may contain array('Parent' => $parentObj) | ||
| 1149 | * If a parent page is known, it will be checked for validity. | ||
| 1150 | * If omitted, it will be assumed this is to be created as a top level page. | ||
| 1151 | * @return bool True if the current user can create pages on this class. | ||
| 1152 | */ | ||
| 1153 | public function canCreate($member = null, $context = array()) | ||
| 1154 |     { | ||
| 1155 |         if (!$member) { | ||
| 1187 | |||
| 1188 | /** | ||
| 1189 | * This function should return true if the current user can edit this page. It can be overloaded to customise the | ||
| 1190 | * security model for an application. | ||
| 1191 | * | ||
| 1192 | * Denies permission if any of the following conditions is true: | ||
| 1193 | * - canEdit() on any extension returns false | ||
| 1194 | * - canView() return false | ||
| 1195 | * - "CanEditType" directive is set to "Inherit" and any parent page return false for canEdit() | ||
| 1196 | * - "CanEditType" directive is set to "LoggedInUsers" and no user is logged in or doesn't have the | ||
| 1197 | * CMS_Access_CMSMAIN permission code | ||
| 1198 | * - "CanEditType" directive is set to "OnlyTheseUsers" and user is not in the given groups | ||
| 1199 | * | ||
| 1200 | * @uses canView() | ||
| 1201 | * @uses EditorGroups() | ||
| 1202 | * @uses DataExtension->canEdit() | ||
| 1203 | * | ||
| 1204 | * @param Member $member Set to false if you want to explicitly test permissions without a valid user (useful for | ||
| 1205 | * unit tests) | ||
| 1206 | * @return bool True if the current user can edit this page | ||
| 1207 | */ | ||
| 1208 | View Code Duplication | public function canEdit($member = null) | |
| 1229 | |||
| 1230 | /** | ||
| 1231 | * Stub method to get the site config, unless the current class can provide an alternate. | ||
| 1232 | * | ||
| 1233 | * @return SiteConfig | ||
| 1234 | */ | ||
| 1235 | public function getSiteConfig() | ||
| 1244 | |||
| 1245 | /** | ||
| 1246 | * @return PermissionChecker | ||
| 1247 | */ | ||
| 1248 | public static function getPermissionChecker() | ||
| 1252 | |||
| 1253 | /** | ||
| 1254 | * Collate selected descendants of this page. | ||
| 1255 | * | ||
| 1256 |      * {@link $condition} will be evaluated on each descendant, and if it is succeeds, that item will be added to the | ||
| 1257 | * $collator array. | ||
| 1258 | * | ||
| 1259 | * @param string $condition The PHP condition to be evaluated. The page will be called $item | ||
| 1260 | * @param array $collator An array, passed by reference, to collect all of the matching descendants. | ||
| 1261 | * @return bool | ||
| 1262 | */ | ||
| 1263 | public function collateDescendants($condition, &$collator) | ||
| 1284 | |||
| 1285 | /** | ||
| 1286 | * Return the title, description, keywords and language metatags. | ||
| 1287 | * | ||
| 1288 | * @todo Move <title> tag in separate getter for easier customization and more obvious usage | ||
| 1289 | * | ||
| 1290 | * @param bool $includeTitle Show default <title>-tag, set to false for custom templating | ||
| 1291 | * @return string The XHTML metatags | ||
| 1292 | */ | ||
| 1293 | public function MetaTags($includeTitle = true) | ||
| 1342 | |||
| 1343 | /** | ||
| 1344 | * Returns the object that contains the content that a user would associate with this page. | ||
| 1345 | * | ||
| 1346 | * Ordinarily, this is just the page itself, but for example on RedirectorPages or VirtualPages ContentSource() will | ||
| 1347 | * return the page that is linked to. | ||
| 1348 | * | ||
| 1349 | * @return $this | ||
| 1350 | */ | ||
| 1351 | public function ContentSource() | ||
| 1355 | |||
| 1356 | /** | ||
| 1357 | * Add default records to database. | ||
| 1358 | * | ||
| 1359 | * This function is called whenever the database is built, after the database tables have all been created. Overload | ||
| 1360 | * this to add default records when the database is built, but make sure you call parent::requireDefaultRecords(). | ||
| 1361 | */ | ||
| 1362 | public function requireDefaultRecords() | ||
| 1407 | |||
| 1408 | protected function onBeforeWrite() | ||
| 1462 | |||
| 1463 | /** | ||
| 1464 | * Trigger synchronisation of link tracking | ||
| 1465 | * | ||
| 1466 |      * {@see SiteTreeLinkTracking::augmentSyncLinkTracking} | ||
| 1467 | */ | ||
| 1468 | public function syncLinkTracking() | ||
| 1472 | |||
| 1473 | public function onBeforeDelete() | ||
| 1485 | |||
| 1486 | public function onAfterDelete() | ||
| 1491 | |||
| 1492 | public function flushCache($persistent = true) | ||
| 1497 | |||
| 1498 | public function validate() | ||
| 1539 | |||
| 1540 | /** | ||
| 1541 | * Returns true if this object has a URLSegment value that does not conflict with any other objects. This method | ||
| 1542 | * checks for: | ||
| 1543 | * - A page with the same URLSegment that has a conflict | ||
| 1544 | * - Conflicts with actions on the parent page | ||
| 1545 | * - A conflict caused by a root page having the same URLSegment as a class name | ||
| 1546 | * | ||
| 1547 | * @return bool | ||
| 1548 | */ | ||
| 1549 | public function validURLSegment() | ||
| 1588 | |||
| 1589 | /** | ||
| 1590 | * Generate a URL segment based on the title provided. | ||
| 1591 | * | ||
| 1592 |      * If {@link Extension}s wish to alter URL segment generation, they can do so by defining | ||
| 1593 | * updateURLSegment(&$url, $title). $url will be passed by reference and should be modified. $title will contain | ||
| 1594 | * the title that was originally used as the source of this generated URL. This lets extensions either start from | ||
| 1595 | * scratch, or incrementally modify the generated URL. | ||
| 1596 | * | ||
| 1597 | * @param string $title Page title | ||
| 1598 | * @return string Generated url segment | ||
| 1599 | */ | ||
| 1600 | public function generateURLSegment($title) | ||
| 1615 | |||
| 1616 | /** | ||
| 1617 | * Gets the URL segment for the latest draft version of this page. | ||
| 1618 | * | ||
| 1619 | * @return string | ||
| 1620 | */ | ||
| 1621 | public function getStageURLSegment() | ||
| 1628 | |||
| 1629 | /** | ||
| 1630 | * Gets the URL segment for the currently published version of this page. | ||
| 1631 | * | ||
| 1632 | * @return string | ||
| 1633 | */ | ||
| 1634 | public function getLiveURLSegment() | ||
| 1641 | |||
| 1642 | /** | ||
| 1643 | * Returns the pages that depend on this page. This includes virtual pages, pages that link to it, etc. | ||
| 1644 | * | ||
| 1645 | * @param bool $includeVirtuals Set to false to exlcude virtual pages. | ||
| 1646 | * @return ArrayList | ||
| 1647 | */ | ||
| 1648 | public function DependentPages($includeVirtuals = true) | ||
| 1701 | |||
| 1702 | /** | ||
| 1703 | * Return all virtual pages that link to this page. | ||
| 1704 | * | ||
| 1705 | * @return DataList | ||
| 1706 | */ | ||
| 1707 | public function VirtualPages() | ||
| 1718 | |||
| 1719 | /** | ||
| 1720 | * Returns a FieldList with which to create the main editing form. | ||
| 1721 | * | ||
| 1722 | * You can override this in your child classes to add extra fields - first get the parent fields using | ||
| 1723 | * parent::getCMSFields(), then use addFieldToTab() on the FieldList. | ||
| 1724 | * | ||
| 1725 |      * See {@link getSettingsFields()} for a different set of fields concerned with configuration aspects on the record, | ||
| 1726 | * e.g. access control. | ||
| 1727 | * | ||
| 1728 | * @return FieldList The fields to be displayed in the CMS | ||
| 1729 | */ | ||
| 1730 | public function getCMSFields() | ||
| 1922 | |||
| 1923 | |||
| 1924 | /** | ||
| 1925 |      * Returns fields related to configuration aspects on this record, e.g. access control. See {@link getCMSFields()} | ||
| 1926 | * for content-related fields. | ||
| 1927 | * | ||
| 1928 | * @return FieldList | ||
| 1929 | */ | ||
| 1930 | public function getSettingsFields() | ||
| 2067 | |||
| 2068 | /** | ||
| 2069 | * @param bool $includerelations A boolean value to indicate if the labels returned should include relation fields | ||
| 2070 | * @return array | ||
| 2071 | */ | ||
| 2072 | public function fieldLabels($includerelations = true) | ||
| 2111 | |||
| 2112 | /** | ||
| 2113 | * Get the actions available in the CMS for this page - eg Save, Publish. | ||
| 2114 | * | ||
| 2115 | * Frontend scripts and styles know how to handle the following FormFields: | ||
| 2116 | * - top-level FormActions appear as standalone buttons | ||
| 2117 | * - top-level CompositeField with FormActions within appear as grouped buttons | ||
| 2118 | * - TabSet & Tabs appear as a drop ups | ||
| 2119 | * - FormActions within the Tab are restyled as links | ||
| 2120 | * - major actions can provide alternate states for richer presentation (see ssui.button widget extension) | ||
| 2121 | * | ||
| 2122 | * @return FieldList The available actions for this page. | ||
| 2123 | */ | ||
| 2124 | public function getCMSActions() | ||
| 2283 | |||
| 2284 | public function onAfterPublish() | ||
| 2294 | |||
| 2295 | /** | ||
| 2296 | * Update draft dependant pages | ||
| 2297 | */ | ||
| 2298 | public function onAfterRevertToLive() | ||
| 2311 | |||
| 2312 | /** | ||
| 2313 | * Determine if this page references a parent which is archived, and not available in stage | ||
| 2314 | * | ||
| 2315 | * @return bool True if there is an archived parent | ||
| 2316 | */ | ||
| 2317 | protected function isParentArchived() | ||
| 2328 | |||
| 2329 | /** | ||
| 2330 | * Restore the content in the active copy of this SiteTree page to the stage site. | ||
| 2331 | * | ||
| 2332 | * @return self | ||
| 2333 | */ | ||
| 2334 | public function doRestoreToStage() | ||
| 2373 | |||
| 2374 | /** | ||
| 2375 | * Check if this page is new - that is, if it has yet to have been written to the database. | ||
| 2376 | * | ||
| 2377 | * @return bool | ||
| 2378 | */ | ||
| 2379 | public function isNew() | ||
| 2395 | |||
| 2396 | /** | ||
| 2397 | * Get the class dropdown used in the CMS to change the class of a page. This returns the list of options in the | ||
| 2398 |      * dropdown as a Map from class name to singular name. Filters by {@link SiteTree->canCreate()}, as well as | ||
| 2399 |      * {@link SiteTree::$needs_permission}. | ||
| 2400 | * | ||
| 2401 | * @return array | ||
| 2402 | */ | ||
| 2403 | protected function getClassDropdown() | ||
| 2453 | |||
| 2454 | /** | ||
| 2455 | * Returns an array of the class names of classes that are allowed to be children of this class. | ||
| 2456 | * | ||
| 2457 | * @return string[] | ||
| 2458 | */ | ||
| 2459 | public function allowedChildren() | ||
| 2493 | |||
| 2494 | /** | ||
| 2495 | * Returns the class name of the default class for children of this page. | ||
| 2496 | * | ||
| 2497 | * @return string | ||
| 2498 | */ | ||
| 2499 | public function defaultChild() | ||
| 2511 | |||
| 2512 | /** | ||
| 2513 | * Returns the class name of the default class for the parent of this page. | ||
| 2514 | * | ||
| 2515 | * @return string | ||
| 2516 | */ | ||
| 2517 | public function defaultParent() | ||
| 2521 | |||
| 2522 | /** | ||
| 2523 | * Get the title for use in menus for this page. If the MenuTitle field is set it returns that, else it returns the | ||
| 2524 | * Title field. | ||
| 2525 | * | ||
| 2526 | * @return string | ||
| 2527 | */ | ||
| 2528 | public function getMenuTitle() | ||
| 2536 | |||
| 2537 | |||
| 2538 | /** | ||
| 2539 | * Set the menu title for this page. | ||
| 2540 | * | ||
| 2541 | * @param string $value | ||
| 2542 | */ | ||
| 2543 | public function setMenuTitle($value) | ||
| 2551 | |||
| 2552 | /** | ||
| 2553 | * A flag provides the user with additional data about the current page status, for example a "removed from draft" | ||
| 2554 | * status. Each page can have more than one status flag. Returns a map of a unique key to a (localized) title for | ||
| 2555 | * the flag. The unique key can be reused as a CSS class. Use the 'updateStatusFlags' extension point to customize | ||
| 2556 | * the flags. | ||
| 2557 | * | ||
| 2558 | * Example (simple): | ||
| 2559 | * "deletedonlive" => "Deleted" | ||
| 2560 | * | ||
| 2561 | * Example (with optional title attribute): | ||
| 2562 |      *   "deletedonlive" => array('text' => "Deleted", 'title' => 'This page has been deleted') | ||
| 2563 | * | ||
| 2564 | * @param bool $cached Whether to serve the fields from cache; false regenerate them | ||
| 2565 | * @return array | ||
| 2566 | */ | ||
| 2567 | public function getStatusFlags($cached = true) | ||
| 2600 | |||
| 2601 | /** | ||
| 2602 | * getTreeTitle will return three <span> html DOM elements, an empty <span> with the class 'jstree-pageicon' in | ||
| 2603 | * front, following by a <span> wrapping around its MenutTitle, then following by a <span> indicating its | ||
| 2604 | * publication status. | ||
| 2605 | * | ||
| 2606 | * @return string An HTML string ready to be directly used in a template | ||
| 2607 | */ | ||
| 2608 | public function getTreeTitle() | ||
| 2642 | |||
| 2643 | /** | ||
| 2644 | * Returns the page in the current page stack of the given level. Level(1) will return the main menu item that | ||
| 2645 | * we're currently inside, etc. | ||
| 2646 | * | ||
| 2647 | * @param int $level | ||
| 2648 | * @return SiteTree | ||
| 2649 | */ | ||
| 2650 | public function Level($level) | ||
| 2660 | |||
| 2661 | /** | ||
| 2662 | * Gets the depth of this page in the sitetree, where 1 is the root level | ||
| 2663 | * | ||
| 2664 | * @return int | ||
| 2665 | */ | ||
| 2666 | public function getPageLevel() | ||
| 2673 | |||
| 2674 | /** | ||
| 2675 |      * Find the controller name by our convention of {$ModelClass}Controller | ||
| 2676 | * | ||
| 2677 | * @return string | ||
| 2678 | */ | ||
| 2679 | public function getControllerName() | ||
| 2710 | |||
| 2711 | /** | ||
| 2712 | * Return the CSS classes to apply to this node in the CMS tree. | ||
| 2713 | * | ||
| 2714 | * @return string | ||
| 2715 | */ | ||
| 2716 | public function CMSTreeClasses() | ||
| 2741 | |||
| 2742 | /** | ||
| 2743 | * Stops extendCMSFields() being called on getCMSFields(). This is useful when you need access to fields added by | ||
| 2744 | * subclasses of SiteTree in a extension. Call before calling parent::getCMSFields(), and reenable afterwards. | ||
| 2745 | */ | ||
| 2746 | public static function disableCMSFieldsExtensions() | ||
| 2750 | |||
| 2751 | /** | ||
| 2752 | * Reenables extendCMSFields() being called on getCMSFields() after it has been disabled by | ||
| 2753 | * disableCMSFieldsExtensions(). | ||
| 2754 | */ | ||
| 2755 | public static function enableCMSFieldsExtensions() | ||
| 2759 | |||
| 2760 | public function providePermissions() | ||
| 2795 | |||
| 2796 | /** | ||
| 2797 | * Default singular name for page / sitetree | ||
| 2798 | * | ||
| 2799 | * @return string | ||
| 2800 | */ | ||
| 2801 | View Code Duplication | public function singular_name() | |
| 2809 | |||
| 2810 | /** | ||
| 2811 | * Default plural name for page / sitetree | ||
| 2812 | * | ||
| 2813 | * @return string | ||
| 2814 | */ | ||
| 2815 | View Code Duplication | public function plural_name() | |
| 2823 | |||
| 2824 | /** | ||
| 2825 | * Get description for this page type | ||
| 2826 | * | ||
| 2827 | * @return string|null | ||
| 2828 | */ | ||
| 2829 | public function classDescription() | ||
| 2837 | |||
| 2838 | /** | ||
| 2839 | * Get localised description for this page | ||
| 2840 | * | ||
| 2841 | * @return string|null | ||
| 2842 | */ | ||
| 2843 | public function i18n_classDescription() | ||
| 2851 | |||
| 2852 | /** | ||
| 2853 | * Overloaded to also provide entities for 'Page' class which is usually located in custom code, hence textcollector | ||
| 2854 | * picks it up for the wrong folder. | ||
| 2855 | * | ||
| 2856 | * @return array | ||
| 2857 | */ | ||
| 2858 | public function provideI18nEntities() | ||
| 2869 | |||
| 2870 | /** | ||
| 2871 | * Returns 'root' if the current page has no parent, or 'subpage' otherwise | ||
| 2872 | * | ||
| 2873 | * @return string | ||
| 2874 | */ | ||
| 2875 | public function getParentType() | ||
| 2879 | |||
| 2880 | /** | ||
| 2881 | * Clear the permissions cache for SiteTree | ||
| 2882 | */ | ||
| 2883 | public static function reset() | ||
| 2890 | |||
| 2891 | /** | ||
| 2892 | * Update dependant pages | ||
| 2893 | */ | ||
| 2894 | protected function updateDependentPages() | ||
| 2908 | } | ||
| 2909 |