2011-03-18 04:01:06 +01:00
|
|
|
<?php
|
2016-06-16 06:57:19 +02:00
|
|
|
|
2016-07-22 01:32:32 +02:00
|
|
|
namespace SilverStripe\CMS\Model;
|
|
|
|
|
2017-12-05 23:59:30 +01:00
|
|
|
use Page;
|
2016-08-23 04:36:06 +02:00
|
|
|
use SilverStripe\Core\Convert;
|
2018-04-06 05:53:57 +02:00
|
|
|
use SilverStripe\Dev\Deprecation;
|
2017-05-19 03:34:43 +02:00
|
|
|
use SilverStripe\Forms\FieldList;
|
2016-08-23 04:36:06 +02:00
|
|
|
use SilverStripe\Forms\LiteralField;
|
|
|
|
use SilverStripe\Forms\ReadonlyTransformation;
|
|
|
|
use SilverStripe\Forms\TreeDropdownField;
|
2016-06-16 06:57:19 +02:00
|
|
|
use SilverStripe\ORM\DataObject;
|
2016-12-09 04:00:46 +01:00
|
|
|
use SilverStripe\ORM\ValidationResult;
|
2016-07-25 00:05:03 +02:00
|
|
|
use SilverStripe\Security\Member;
|
2017-12-05 23:59:30 +01:00
|
|
|
use SilverStripe\Versioned\Versioned;
|
2018-04-06 05:53:57 +02:00
|
|
|
use SilverStripe\View\HTML;
|
2016-06-16 06:57:19 +02:00
|
|
|
|
2011-03-18 04:01:06 +01:00
|
|
|
/**
|
2016-08-23 04:36:06 +02:00
|
|
|
* Virtual Page creates an instance of a page, with the same fields that the original page had, but readonly.
|
2017-05-19 03:34:43 +02:00
|
|
|
* This allows you can have a page in mulitple places in the site structure, with different children without
|
|
|
|
* duplicating the content.
|
|
|
|
*
|
2016-08-23 04:36:06 +02:00
|
|
|
* Note: This Only duplicates $db fields and not the $has_one etc..
|
2016-03-17 01:02:50 +01:00
|
|
|
*
|
|
|
|
* @method SiteTree CopyContentFrom()
|
2016-07-25 00:05:03 +02:00
|
|
|
* @property int $CopyContentFromID
|
2016-08-23 04:36:06 +02:00
|
|
|
*/
|
2017-01-25 21:59:25 +01:00
|
|
|
class VirtualPage extends Page
|
|
|
|
{
|
|
|
|
private static $description = 'Displays the content of another page';
|
|
|
|
|
2019-01-14 01:16:30 +01:00
|
|
|
private static $icon_class = 'font-icon-p-virtual';
|
|
|
|
|
2017-01-25 21:59:25 +01:00
|
|
|
public static $virtualFields;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var array Define fields that are not virtual - the virtual page must define these fields themselves.
|
|
|
|
* Note that anything in {@link self::config()->initially_copied_fields} is implicitly included in this list.
|
|
|
|
*/
|
|
|
|
private static $non_virtual_fields = array(
|
|
|
|
"ID",
|
|
|
|
"ClassName",
|
|
|
|
"ObsoleteClassName",
|
|
|
|
"SecurityTypeID",
|
|
|
|
"OwnerID",
|
|
|
|
"ParentID",
|
|
|
|
"URLSegment",
|
|
|
|
"Sort",
|
|
|
|
"Status",
|
|
|
|
'ShowInMenus',
|
|
|
|
// 'Locale'
|
|
|
|
'ShowInSearch',
|
|
|
|
'Version',
|
|
|
|
"Embargo",
|
|
|
|
"Expiry",
|
|
|
|
"CanViewType",
|
|
|
|
"CanEditType",
|
|
|
|
"CopyContentFromID",
|
|
|
|
"HasBrokenLink",
|
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var array Define fields that are initially copied to virtual pages but left modifiable after that.
|
|
|
|
*/
|
|
|
|
private static $initially_copied_fields = array(
|
|
|
|
'ShowInMenus',
|
|
|
|
'ShowInSearch',
|
|
|
|
'URLSegment',
|
|
|
|
);
|
|
|
|
|
|
|
|
private static $has_one = array(
|
2017-08-09 00:56:08 +02:00
|
|
|
"CopyContentFrom" => SiteTree::class,
|
2017-01-25 21:59:25 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
private static $owns = array(
|
|
|
|
"CopyContentFrom",
|
|
|
|
);
|
|
|
|
|
|
|
|
private static $db = array(
|
|
|
|
"VersionID" => "Int",
|
|
|
|
);
|
|
|
|
|
|
|
|
private static $table_name = 'VirtualPage';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generates the array of fields required for the page type.
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function getVirtualFields()
|
|
|
|
{
|
|
|
|
// Check if copied page exists
|
|
|
|
$record = $this->CopyContentFrom();
|
|
|
|
if (!$record || !$record->exists()) {
|
|
|
|
return array();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Diff db with non-virtual fields
|
|
|
|
$fields = array_keys(static::getSchema()->fieldSpecs($record));
|
|
|
|
$nonVirtualFields = $this->getNonVirtualisedFields();
|
|
|
|
return array_diff($fields, $nonVirtualFields);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* List of fields or properties to never virtualise
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function getNonVirtualisedFields()
|
|
|
|
{
|
2018-04-06 05:53:57 +02:00
|
|
|
$config = self::config();
|
2017-02-16 05:51:54 +01:00
|
|
|
return array_merge(
|
2018-04-06 05:53:57 +02:00
|
|
|
$config->get('non_virtual_fields'),
|
|
|
|
$config->get('initially_copied_fields')
|
2017-02-16 05:51:54 +01:00
|
|
|
);
|
2017-01-25 21:59:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function setCopyContentFromID($val)
|
|
|
|
{
|
|
|
|
// Sanity check to prevent pages virtualising other virtual pages
|
2017-09-20 03:51:07 +02:00
|
|
|
if ($val && DataObject::get_by_id(SiteTree::class, $val) instanceof VirtualPage) {
|
2017-01-25 21:59:25 +01:00
|
|
|
$val = 0;
|
|
|
|
}
|
|
|
|
return $this->setField("CopyContentFromID", $val);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function ContentSource()
|
|
|
|
{
|
|
|
|
$copied = $this->CopyContentFrom();
|
|
|
|
if ($copied && $copied->exists()) {
|
|
|
|
return $copied;
|
|
|
|
}
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* For VirtualPage, add a canonical link tag linking to the original page
|
|
|
|
* See TRAC #6828 & http://support.google.com/webmasters/bin/answer.py?hl=en&answer=139394
|
|
|
|
*
|
|
|
|
* @param boolean $includeTitle Show default <title>-tag, set to false for custom templating
|
|
|
|
* @return string The XHTML metatags
|
|
|
|
*/
|
|
|
|
public function MetaTags($includeTitle = true)
|
|
|
|
{
|
|
|
|
$tags = parent::MetaTags($includeTitle);
|
|
|
|
$copied = $this->CopyContentFrom();
|
|
|
|
if ($copied && $copied->exists()) {
|
2018-04-06 05:53:57 +02:00
|
|
|
$tags .= HTML::createTag('link', [
|
|
|
|
'rel' => 'canonical',
|
|
|
|
'href' => $copied->Link()
|
|
|
|
]);
|
|
|
|
$tags .= "\n";
|
2017-01-25 21:59:25 +01:00
|
|
|
}
|
|
|
|
return $tags;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function allowedChildren()
|
|
|
|
{
|
|
|
|
$copy = $this->CopyContentFrom();
|
|
|
|
if ($copy && $copy->exists()) {
|
|
|
|
return $copy->allowedChildren();
|
|
|
|
}
|
|
|
|
return array();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function syncLinkTracking()
|
|
|
|
{
|
|
|
|
if ($this->CopyContentFromID) {
|
2017-06-21 06:29:40 +02:00
|
|
|
$this->HasBrokenLink = Versioned::get_by_stage(SiteTree::class, Versioned::DRAFT)
|
2018-04-06 05:53:57 +02:00
|
|
|
->filter('ID', $this->CopyContentFromID)
|
|
|
|
->count() === 0;
|
2017-01-25 21:59:25 +01:00
|
|
|
} else {
|
|
|
|
$this->HasBrokenLink = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* We can only publish the page if there is a published source page
|
|
|
|
*
|
|
|
|
* @param Member $member Member to check
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function canPublish($member = null)
|
|
|
|
{
|
|
|
|
return $this->isPublishable() && parent::canPublish($member);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if is page is publishable by anyone at all
|
|
|
|
* Return false if the source page isn't published yet.
|
|
|
|
*
|
|
|
|
* Note that isPublishable doesn't affect ete from live, only publish.
|
|
|
|
*/
|
|
|
|
public function isPublishable()
|
|
|
|
{
|
|
|
|
// No source
|
|
|
|
if (!$this->CopyContentFrom() || !$this->CopyContentFrom()->ID) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Unpublished source
|
2017-05-19 03:34:43 +02:00
|
|
|
if (!Versioned::get_versionnumber_by_stage(
|
2017-09-20 03:51:07 +02:00
|
|
|
SiteTree::class,
|
2017-05-19 03:34:43 +02:00
|
|
|
'Live',
|
|
|
|
$this->CopyContentFromID
|
|
|
|
)) {
|
2017-01-25 21:59:25 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Default - publishable
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generate the CMS fields from the fields from the original page.
|
|
|
|
*/
|
|
|
|
public function getCMSFields()
|
|
|
|
{
|
2017-05-19 03:34:43 +02:00
|
|
|
$this->beforeUpdateCMSFields(function (FieldList $fields) {
|
|
|
|
// Setup the linking to the original page.
|
|
|
|
$copyContentFromField = TreeDropdownField::create(
|
|
|
|
'CopyContentFromID',
|
2018-04-06 05:53:57 +02:00
|
|
|
_t(self::class . '.CHOOSE', "Linked Page"),
|
|
|
|
SiteTree::class
|
2017-05-19 03:34:43 +02:00
|
|
|
);
|
2017-01-25 21:59:25 +01:00
|
|
|
|
2017-05-19 03:34:43 +02:00
|
|
|
// Setup virtual fields
|
|
|
|
if ($virtualFields = $this->getVirtualFields()) {
|
|
|
|
$roTransformation = new ReadonlyTransformation();
|
|
|
|
foreach ($virtualFields as $virtualField) {
|
|
|
|
if ($fields->dataFieldByName($virtualField)) {
|
|
|
|
$fields->replaceField(
|
|
|
|
$virtualField,
|
|
|
|
$fields->dataFieldByName($virtualField)->transform($roTransformation)
|
|
|
|
);
|
|
|
|
}
|
2017-01-25 21:59:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-19 03:34:43 +02:00
|
|
|
$msgs = array();
|
|
|
|
|
|
|
|
$fields->addFieldToTab('Root.Main', $copyContentFromField, 'Title');
|
|
|
|
|
|
|
|
// Create links back to the original object in the CMS
|
|
|
|
if ($this->CopyContentFrom()->exists()) {
|
2018-04-06 05:53:57 +02:00
|
|
|
$link = HTML::createTag(
|
|
|
|
'a',
|
|
|
|
[
|
|
|
|
'class' => 'cmsEditlink',
|
|
|
|
'href' => 'admin/pages/edit/show/' . $this->CopyContentFromID,
|
|
|
|
],
|
|
|
|
_t(self::class . '.EditLink', 'edit')
|
|
|
|
);
|
2017-05-19 03:34:43 +02:00
|
|
|
$msgs[] = _t(
|
2018-04-06 05:53:57 +02:00
|
|
|
self::class . '.HEADERWITHLINK',
|
2017-05-19 03:34:43 +02:00
|
|
|
"This is a virtual page copying content from \"{title}\" ({link})",
|
2018-04-06 05:53:57 +02:00
|
|
|
[
|
2017-05-19 03:34:43 +02:00
|
|
|
'title' => $this->CopyContentFrom()->obj('Title'),
|
|
|
|
'link' => $link,
|
2018-04-06 05:53:57 +02:00
|
|
|
]
|
2017-05-19 03:34:43 +02:00
|
|
|
);
|
|
|
|
} else {
|
2018-04-06 05:53:57 +02:00
|
|
|
$msgs[] = _t(self::class . '.HEADER', "This is a virtual page");
|
2017-05-19 03:34:43 +02:00
|
|
|
$msgs[] = _t(
|
|
|
|
'SilverStripe\\CMS\\Model\\SiteTree.VIRTUALPAGEWARNING',
|
|
|
|
'Please choose a linked page and save first in order to publish this page'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
if ($this->CopyContentFromID && !Versioned::get_versionnumber_by_stage(
|
|
|
|
SiteTree::class,
|
|
|
|
Versioned::LIVE,
|
|
|
|
$this->CopyContentFromID
|
2018-04-06 05:53:57 +02:00
|
|
|
)) {
|
2017-05-19 03:34:43 +02:00
|
|
|
$msgs[] = _t(
|
|
|
|
'SilverStripe\\CMS\\Model\\SiteTree.VIRTUALPAGEDRAFTWARNING',
|
|
|
|
'Please publish the linked page in order to publish the virtual page'
|
|
|
|
);
|
|
|
|
}
|
2017-01-25 21:59:25 +01:00
|
|
|
|
2017-05-19 03:34:43 +02:00
|
|
|
$fields->addFieldToTab("Root.Main", new LiteralField(
|
2017-01-25 21:59:25 +01:00
|
|
|
'VirtualPageMessage',
|
|
|
|
'<div class="message notice">' . implode('. ', $msgs) . '.</div>'
|
2017-05-19 03:34:43 +02:00
|
|
|
), 'CopyContentFromID');
|
|
|
|
});
|
2017-01-25 21:59:25 +01:00
|
|
|
|
2017-05-19 03:34:43 +02:00
|
|
|
return parent::getCMSFields();
|
2017-01-25 21:59:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function onBeforeWrite()
|
|
|
|
{
|
|
|
|
$this->refreshFromCopied();
|
2017-12-05 23:59:30 +01:00
|
|
|
parent::onBeforeWrite();
|
2017-01-25 21:59:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Copy any fields from the copied record to bootstrap /backup
|
|
|
|
*/
|
|
|
|
protected function refreshFromCopied()
|
|
|
|
{
|
|
|
|
// Skip if copied record isn't available
|
|
|
|
$source = $this->CopyContentFrom();
|
|
|
|
if (!$source || !$source->exists()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We also want to copy certain, but only if we're copying the source page for the first
|
|
|
|
// time. After this point, the user is free to customise these for the virtual page themselves.
|
|
|
|
if ($this->isChanged('CopyContentFromID', 2) && $this->CopyContentFromID) {
|
2018-04-06 05:53:57 +02:00
|
|
|
foreach (self::config()->get('initially_copied_fields') as $fieldName) {
|
2017-01-25 21:59:25 +01:00
|
|
|
$this->$fieldName = $source->$fieldName;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Copy fields to the original record in case the class type changes
|
|
|
|
foreach ($this->getVirtualFields() as $virtualField) {
|
|
|
|
$this->$virtualField = $source->$virtualField;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getSettingsFields()
|
|
|
|
{
|
|
|
|
$fields = parent::getSettingsFields();
|
|
|
|
if (!$this->CopyContentFrom()->exists()) {
|
|
|
|
$fields->addFieldToTab(
|
|
|
|
"Root.Settings",
|
|
|
|
new LiteralField(
|
|
|
|
'VirtualPageWarning',
|
|
|
|
'<div class="message notice">'
|
2017-12-18 22:31:25 +01:00
|
|
|
. _t(
|
|
|
|
'SilverStripe\\CMS\\Model\\SiteTree.VIRTUALPAGEWARNINGSETTINGS',
|
|
|
|
'Please choose a linked page in the main content fields in order to publish'
|
|
|
|
)
|
2017-01-25 21:59:25 +01:00
|
|
|
. '</div>'
|
|
|
|
),
|
|
|
|
'ClassName'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $fields;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function validate()
|
|
|
|
{
|
|
|
|
$result = parent::validate();
|
|
|
|
|
|
|
|
// "Can be root" validation
|
|
|
|
$orig = $this->CopyContentFrom();
|
2017-08-22 23:46:46 +02:00
|
|
|
if ($orig && $orig->exists() && !$orig->config()->get('can_be_root') && !$this->ParentID) {
|
2017-01-25 21:59:25 +01:00
|
|
|
$result->addError(
|
|
|
|
_t(
|
2018-04-06 05:53:57 +02:00
|
|
|
self::class . '.PageTypNotAllowedOnRoot',
|
2017-01-25 21:59:25 +01:00
|
|
|
'Original page type "{type}" is not allowed on the root level for this virtual page',
|
|
|
|
array('type' => $orig->i18n_singular_name())
|
|
|
|
),
|
|
|
|
ValidationResult::TYPE_ERROR,
|
|
|
|
'CAN_BE_ROOT_VIRTUAL'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
2018-04-06 05:53:57 +02:00
|
|
|
/**
|
|
|
|
* @deprecated 4.2..5.0
|
|
|
|
*/
|
2017-01-25 21:59:25 +01:00
|
|
|
public function updateImageTracking()
|
|
|
|
{
|
2018-04-06 05:53:57 +02:00
|
|
|
Deprecation::notice('5.0', 'This will be removed in 5.0');
|
|
|
|
|
2017-01-25 21:59:25 +01:00
|
|
|
// Doesn't work on unsaved records
|
2018-04-06 05:53:57 +02:00
|
|
|
if (!$this->isInDB()) {
|
2017-01-25 21:59:25 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove CopyContentFrom() from the cache
|
|
|
|
unset($this->components['CopyContentFrom']);
|
|
|
|
|
|
|
|
// Update ImageTracking
|
2018-04-06 05:53:57 +02:00
|
|
|
$copyContentFrom = $this->CopyContentFrom();
|
|
|
|
if (!$copyContentFrom || !$copyContentFrom->isInDB()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->FileTracking()->setByIDList($copyContentFrom->FileTracking()->column('ID'));
|
2017-01-25 21:59:25 +01:00
|
|
|
}
|
|
|
|
|
2017-04-06 07:38:15 +02:00
|
|
|
public function CMSTreeClasses()
|
2017-01-25 21:59:25 +01:00
|
|
|
{
|
2018-03-05 02:58:32 +01:00
|
|
|
$parentClass = sprintf(
|
|
|
|
' VirtualPage-%s',
|
|
|
|
Convert::raw2htmlid($this->CopyContentFrom()->ClassName)
|
|
|
|
);
|
|
|
|
return parent::CMSTreeClasses() . $parentClass;
|
2017-01-25 21:59:25 +01:00
|
|
|
}
|
|
|
|
|
2017-12-05 23:59:30 +01:00
|
|
|
/**
|
|
|
|
* Use the target page's class name for fetching templates - as we need to take on its appearance
|
|
|
|
*
|
|
|
|
* @param string $suffix
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function getViewerTemplates($suffix = '')
|
|
|
|
{
|
|
|
|
$copy = $this->CopyContentFrom();
|
|
|
|
if ($copy && $copy->exists()) {
|
|
|
|
return $copy->getViewerTemplates($suffix);
|
|
|
|
}
|
|
|
|
|
|
|
|
return parent::getViewerTemplates($suffix);
|
|
|
|
}
|
|
|
|
|
2017-01-25 21:59:25 +01:00
|
|
|
/**
|
|
|
|
* Allow attributes on the master page to pass
|
|
|
|
* through to the virtual page
|
|
|
|
*
|
|
|
|
* @param string $field
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function __get($field)
|
|
|
|
{
|
|
|
|
if (parent::hasMethod($funcName = "get$field")) {
|
|
|
|
return $this->$funcName();
|
|
|
|
}
|
|
|
|
if (parent::hasField($field) || ($field === 'ID' && !$this->exists())) {
|
|
|
|
return $this->getField($field);
|
|
|
|
}
|
|
|
|
if (($copy = $this->CopyContentFrom()) && $copy->exists()) {
|
|
|
|
return $copy->$field;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getField($field)
|
|
|
|
{
|
|
|
|
if ($this->isFieldVirtualised($field)) {
|
|
|
|
return $this->CopyContentFrom()->getField($field);
|
|
|
|
}
|
|
|
|
return parent::getField($field);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if given field is virtualised
|
|
|
|
*
|
|
|
|
* @param string $field
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function isFieldVirtualised($field)
|
|
|
|
{
|
|
|
|
// Don't defer if field is non-virtualised
|
|
|
|
$ignore = $this->getNonVirtualisedFields();
|
|
|
|
if (in_array($field, $ignore)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Don't defer if no virtual page
|
|
|
|
$copied = $this->CopyContentFrom();
|
|
|
|
if (!$copied || !$copied->exists()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if copied object has this field
|
|
|
|
return $copied->hasField($field);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Pass unrecognized method calls on to the original data object
|
|
|
|
*
|
|
|
|
* @param string $method
|
2017-02-16 05:51:54 +01:00
|
|
|
* @param array $args
|
2017-01-25 21:59:25 +01:00
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function __call($method, $args)
|
|
|
|
{
|
|
|
|
if (parent::hasMethod($method)) {
|
|
|
|
return parent::__call($method, $args);
|
|
|
|
} else {
|
|
|
|
return call_user_func_array(array($this->CopyContentFrom(), $method), $args);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $field
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function hasField($field)
|
|
|
|
{
|
|
|
|
if (parent::hasField($field)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
$copy = $this->CopyContentFrom();
|
|
|
|
return $copy && $copy->exists() && $copy->hasField($field);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the "casting helper" (a piece of PHP code that when evaluated creates a casted value object) for a field
|
|
|
|
* on this object.
|
|
|
|
*
|
|
|
|
* @param string $field
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function castingHelper($field)
|
|
|
|
{
|
|
|
|
$copy = $this->CopyContentFrom();
|
|
|
|
if ($copy && $copy->exists() && ($helper = $copy->castingHelper($field))) {
|
|
|
|
return $helper;
|
|
|
|
}
|
|
|
|
return parent::castingHelper($field);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function allMethodNames($custom = false)
|
|
|
|
{
|
|
|
|
$methods = parent::allMethodNames($custom);
|
|
|
|
|
|
|
|
if ($copy = $this->CopyContentFrom()) {
|
|
|
|
$methods = array_merge($methods, $copy->allMethodNames($custom));
|
|
|
|
}
|
|
|
|
|
|
|
|
return $methods;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function getControllerName()
|
|
|
|
{
|
|
|
|
if ($copy = $this->CopyContentFrom()) {
|
|
|
|
return $copy->getControllerName();
|
|
|
|
}
|
|
|
|
|
|
|
|
return parent::getControllerName();
|
|
|
|
}
|
2011-03-18 04:01:06 +01:00
|
|
|
}
|