mirror of
https://github.com/silverstripe/silverstripe-cms
synced 2024-10-22 08:05:56 +02:00
FIX beforeUpdateCMSFields added to ErrorPage and VirtualPage
References #1756
This commit is contained in:
parent
3d238f7f65
commit
c034ead6df
@ -41,6 +41,7 @@ before_script:
|
||||
- composer install --prefer-dist
|
||||
- composer require --prefer-dist --no-update symfony/config:^3.2 silverstripe/framework:4.0.x-dev silverstripe/siteconfig:4.0.x-dev silverstripe/config:1.0.x-dev silverstripe/admin:1.0.x-dev silverstripe/assets:1.0.x-dev silverstripe/versioned:1.0.x-dev
|
||||
- composer update
|
||||
|
||||
- if [[ $DB == PGSQL ]]; then composer require silverstripe/postgresql:2.0.x-dev --prefer-dist; fi
|
||||
- if [[ $DB == SQLITE ]]; then composer require silverstripe/sqlite3:2.0.x-dev --prefer-dist; fi
|
||||
|
||||
|
@ -218,45 +218,19 @@ class ErrorPage extends Page
|
||||
*/
|
||||
public function getCMSFields()
|
||||
{
|
||||
$fields = parent::getCMSFields();
|
||||
|
||||
$this->beforeUpdateCMSFields(function (FieldList $fields) {
|
||||
$fields->addFieldToTab(
|
||||
"Root.Main",
|
||||
'Root.Main',
|
||||
new DropdownField(
|
||||
"ErrorCode",
|
||||
'ErrorCode',
|
||||
$this->fieldLabel('ErrorCode'),
|
||||
array(
|
||||
400 => _t('SilverStripe\\CMS\\Model\\ErrorPage.CODE_400', '400 - Bad Request'),
|
||||
401 => _t('SilverStripe\\CMS\\Model\\ErrorPage.CODE_401', '401 - Unauthorized'),
|
||||
403 => _t('SilverStripe\\CMS\\Model\\ErrorPage.CODE_403', '403 - Forbidden'),
|
||||
404 => _t('SilverStripe\\CMS\\Model\\ErrorPage.CODE_404', '404 - Not Found'),
|
||||
405 => _t('SilverStripe\\CMS\\Model\\ErrorPage.CODE_405', '405 - Method Not Allowed'),
|
||||
406 => _t('SilverStripe\\CMS\\Model\\ErrorPage.CODE_406', '406 - Not Acceptable'),
|
||||
407 => _t('SilverStripe\\CMS\\Model\\ErrorPage.CODE_407', '407 - Proxy Authentication Required'),
|
||||
408 => _t('SilverStripe\\CMS\\Model\\ErrorPage.CODE_408', '408 - Request Timeout'),
|
||||
409 => _t('SilverStripe\\CMS\\Model\\ErrorPage.CODE_409', '409 - Conflict'),
|
||||
410 => _t('SilverStripe\\CMS\\Model\\ErrorPage.CODE_410', '410 - Gone'),
|
||||
411 => _t('SilverStripe\\CMS\\Model\\ErrorPage.CODE_411', '411 - Length Required'),
|
||||
412 => _t('SilverStripe\\CMS\\Model\\ErrorPage.CODE_412', '412 - Precondition Failed'),
|
||||
413 => _t('SilverStripe\\CMS\\Model\\ErrorPage.CODE_413', '413 - Request Entity Too Large'),
|
||||
414 => _t('SilverStripe\\CMS\\Model\\ErrorPage.CODE_414', '414 - Request-URI Too Long'),
|
||||
415 => _t('SilverStripe\\CMS\\Model\\ErrorPage.CODE_415', '415 - Unsupported Media Type'),
|
||||
416 => _t('SilverStripe\\CMS\\Model\\ErrorPage.CODE_416', '416 - Request Range Not Satisfiable'),
|
||||
417 => _t('SilverStripe\\CMS\\Model\\ErrorPage.CODE_417', '417 - Expectation Failed'),
|
||||
422 => _t('SilverStripe\\CMS\\Model\\ErrorPage.CODE_422', '422 - Unprocessable Entity'),
|
||||
429 => _t('SilverStripe\\CMS\\Model\\ErrorPage.CODE_429', '429 - Too Many Requests'),
|
||||
500 => _t('SilverStripe\\CMS\\Model\\ErrorPage.CODE_500', '500 - Internal Server Error'),
|
||||
501 => _t('SilverStripe\\CMS\\Model\\ErrorPage.CODE_501', '501 - Not Implemented'),
|
||||
502 => _t('SilverStripe\\CMS\\Model\\ErrorPage.CODE_502', '502 - Bad Gateway'),
|
||||
503 => _t('SilverStripe\\CMS\\Model\\ErrorPage.CODE_503', '503 - Service Unavailable'),
|
||||
504 => _t('SilverStripe\\CMS\\Model\\ErrorPage.CODE_504', '504 - Gateway Timeout'),
|
||||
505 => _t('SilverStripe\\CMS\\Model\\ErrorPage.CODE_505', '505 - HTTP Version Not Supported'),
|
||||
$this->getCodes(),
|
||||
'Content'
|
||||
)
|
||||
),
|
||||
"Content"
|
||||
);
|
||||
});
|
||||
|
||||
return $fields;
|
||||
return parent::getCMSFields();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -355,6 +329,37 @@ class ErrorPage extends Page
|
||||
return self::get_asset_handler()->getContent($storeFilename);
|
||||
}
|
||||
|
||||
protected function getCodes()
|
||||
{
|
||||
return [
|
||||
400 => _t('SilverStripe\\CMS\\Model\\ErrorPage.CODE_400', '400 - Bad Request'),
|
||||
401 => _t('SilverStripe\\CMS\\Model\\ErrorPage.CODE_401', '401 - Unauthorized'),
|
||||
403 => _t('SilverStripe\\CMS\\Model\\ErrorPage.CODE_403', '403 - Forbidden'),
|
||||
404 => _t('SilverStripe\\CMS\\Model\\ErrorPage.CODE_404', '404 - Not Found'),
|
||||
405 => _t('SilverStripe\\CMS\\Model\\ErrorPage.CODE_405', '405 - Method Not Allowed'),
|
||||
406 => _t('SilverStripe\\CMS\\Model\\ErrorPage.CODE_406', '406 - Not Acceptable'),
|
||||
407 => _t('SilverStripe\\CMS\\Model\\ErrorPage.CODE_407', '407 - Proxy Authentication Required'),
|
||||
408 => _t('SilverStripe\\CMS\\Model\\ErrorPage.CODE_408', '408 - Request Timeout'),
|
||||
409 => _t('SilverStripe\\CMS\\Model\\ErrorPage.CODE_409', '409 - Conflict'),
|
||||
410 => _t('SilverStripe\\CMS\\Model\\ErrorPage.CODE_410', '410 - Gone'),
|
||||
411 => _t('SilverStripe\\CMS\\Model\\ErrorPage.CODE_411', '411 - Length Required'),
|
||||
412 => _t('SilverStripe\\CMS\\Model\\ErrorPage.CODE_412', '412 - Precondition Failed'),
|
||||
413 => _t('SilverStripe\\CMS\\Model\\ErrorPage.CODE_413', '413 - Request Entity Too Large'),
|
||||
414 => _t('SilverStripe\\CMS\\Model\\ErrorPage.CODE_414', '414 - Request-URI Too Long'),
|
||||
415 => _t('SilverStripe\\CMS\\Model\\ErrorPage.CODE_415', '415 - Unsupported Media Type'),
|
||||
416 => _t('SilverStripe\\CMS\\Model\\ErrorPage.CODE_416', '416 - Request Range Not Satisfiable'),
|
||||
417 => _t('SilverStripe\\CMS\\Model\\ErrorPage.CODE_417', '417 - Expectation Failed'),
|
||||
422 => _t('SilverStripe\\CMS\\Model\\ErrorPage.CODE_422', '422 - Unprocessable Entity'),
|
||||
429 => _t('SilverStripe\\CMS\\Model\\ErrorPage.CODE_429', '429 - Too Many Requests'),
|
||||
500 => _t('SilverStripe\\CMS\\Model\\ErrorPage.CODE_500', '500 - Internal Server Error'),
|
||||
501 => _t('SilverStripe\\CMS\\Model\\ErrorPage.CODE_501', '501 - Not Implemented'),
|
||||
502 => _t('SilverStripe\\CMS\\Model\\ErrorPage.CODE_502', '502 - Bad Gateway'),
|
||||
503 => _t('SilverStripe\\CMS\\Model\\ErrorPage.CODE_503', '503 - Service Unavailable'),
|
||||
504 => _t('SilverStripe\\CMS\\Model\\ErrorPage.CODE_504', '504 - Gateway Timeout'),
|
||||
505 => _t('SilverStripe\\CMS\\Model\\ErrorPage.CODE_505', '505 - HTTP Version Not Supported'),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the filename identifier for the given error code.
|
||||
* Used when handling responses under error conditions.
|
||||
|
@ -3,11 +3,11 @@
|
||||
namespace SilverStripe\CMS\Model;
|
||||
|
||||
use SilverStripe\Core\Convert;
|
||||
use SilverStripe\Forms\FieldList;
|
||||
use SilverStripe\Forms\LiteralField;
|
||||
use SilverStripe\Forms\ReadonlyTransformation;
|
||||
use SilverStripe\Forms\TreeDropdownField;
|
||||
use SilverStripe\ORM\DataObject;
|
||||
use SilverStripe\ORM\Hierarchy\MarkedSet;
|
||||
use SilverStripe\ORM\ValidationResult;
|
||||
use SilverStripe\Versioned\Versioned;
|
||||
use SilverStripe\Security\Member;
|
||||
@ -15,7 +15,9 @@ use Page;
|
||||
|
||||
/**
|
||||
* Virtual Page creates an instance of a page, with the same fields that the original page had, but readonly.
|
||||
* This allows you can have a page in mulitple places in the site structure, with different children without duplicating the content
|
||||
* This allows you can have a page in mulitple places in the site structure, with different children without
|
||||
* duplicating the content.
|
||||
*
|
||||
* Note: This Only duplicates $db fields and not the $has_one etc..
|
||||
*
|
||||
* @method SiteTree CopyContentFrom()
|
||||
@ -157,7 +159,8 @@ class VirtualPage extends Page
|
||||
public function syncLinkTracking()
|
||||
{
|
||||
if ($this->CopyContentFromID) {
|
||||
$this->HasBrokenLink = !(bool) DataObject::get_by_id('SilverStripe\\CMS\\Model\\SiteTree', $this->CopyContentFromID);
|
||||
$copyPage = DataObject::get_by_id('SilverStripe\\CMS\\Model\\SiteTree', $this->CopyContentFromID);
|
||||
$this->HasBrokenLink = !$copyPage;
|
||||
} else {
|
||||
$this->HasBrokenLink = true;
|
||||
}
|
||||
@ -188,7 +191,11 @@ class VirtualPage extends Page
|
||||
}
|
||||
|
||||
// Unpublished source
|
||||
if (!Versioned::get_versionnumber_by_stage('SilverStripe\\CMS\\Model\\SiteTree', 'Live', $this->CopyContentFromID)) {
|
||||
if (!Versioned::get_versionnumber_by_stage(
|
||||
'SilverStripe\\CMS\\Model\\SiteTree',
|
||||
'Live',
|
||||
$this->CopyContentFromID
|
||||
)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -201,42 +208,43 @@ class VirtualPage extends Page
|
||||
*/
|
||||
public function getCMSFields()
|
||||
{
|
||||
$fields = parent::getCMSFields();
|
||||
|
||||
$this->beforeUpdateCMSFields(function (FieldList $fields) {
|
||||
// Setup the linking to the original page.
|
||||
$copyContentFromField = new TreeDropdownField(
|
||||
"CopyContentFromID",
|
||||
$copyContentFromField = TreeDropdownField::create(
|
||||
'CopyContentFromID',
|
||||
_t('SilverStripe\\CMS\\Model\\VirtualPage.CHOOSE', "Linked Page"),
|
||||
"SilverStripe\\CMS\\Model\\SiteTree"
|
||||
);
|
||||
// filter doesn't let you select children of virtual pages as as source page
|
||||
//$copyContentFromField->setFilterFunction(function ($item) { return !($item instanceof VirtualPage); });
|
||||
|
||||
// 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));
|
||||
$fields->replaceField(
|
||||
$virtualField,
|
||||
$fields->dataFieldByName($virtualField)->transform($roTransformation)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$msgs = array();
|
||||
|
||||
$fields->addFieldToTab("Root.Main", $copyContentFromField, "Title");
|
||||
$fields->addFieldToTab('Root.Main', $copyContentFromField, 'Title');
|
||||
|
||||
// Create links back to the original object in the CMS
|
||||
if ($this->CopyContentFrom()->exists()) {
|
||||
$link = "<a class=\"cmsEditlink\" href=\"admin/pages/edit/show/$this->CopyContentFromID\">"
|
||||
. _t('SilverStripe\\CMS\\Model\\VirtualPage.EditLink', 'edit')
|
||||
. "</a>";
|
||||
$link = "<a class=\"cmsEditlink\" href=\"admin/pages/edit/show/$this->CopyContentFromID\">" . _t(
|
||||
'SilverStripe\\CMS\\Model\\VirtualPage.EditLink',
|
||||
'edit'
|
||||
) . "</a>";
|
||||
$msgs[] = _t(
|
||||
'SilverStripe\\CMS\\Model\\VirtualPage.HEADERWITHLINK',
|
||||
"This is a virtual page copying content from \"{title}\" ({link})",
|
||||
array(
|
||||
'title' => $this->CopyContentFrom()->obj('Title'),
|
||||
'link' => $link
|
||||
'link' => $link,
|
||||
)
|
||||
);
|
||||
} else {
|
||||
@ -246,8 +254,11 @@ class VirtualPage extends Page
|
||||
'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)
|
||||
if ($this->CopyContentFromID && !Versioned::get_versionnumber_by_stage(
|
||||
SiteTree::class,
|
||||
Versioned::LIVE,
|
||||
$this->CopyContentFromID
|
||||
)
|
||||
) {
|
||||
$msgs[] = _t(
|
||||
'SilverStripe\\CMS\\Model\\SiteTree.VIRTUALPAGEDRAFTWARNING',
|
||||
@ -255,16 +266,13 @@ class VirtualPage extends Page
|
||||
);
|
||||
}
|
||||
|
||||
$fields->addFieldToTab(
|
||||
"Root.Main",
|
||||
new LiteralField(
|
||||
$fields->addFieldToTab("Root.Main", new LiteralField(
|
||||
'VirtualPageMessage',
|
||||
'<div class="message notice">' . implode('. ', $msgs) . '.</div>'
|
||||
),
|
||||
'CopyContentFromID'
|
||||
);
|
||||
), 'CopyContentFromID');
|
||||
});
|
||||
|
||||
return $fields;
|
||||
return parent::getCMSFields();
|
||||
}
|
||||
|
||||
public function onBeforeWrite()
|
||||
|
Loading…
Reference in New Issue
Block a user