mirror of
https://github.com/silverstripe/silverstripe-subsites
synced 2024-10-22 09:05:55 +00:00
FIX Update CMS fields now that they're being scaffolded (#589)
This commit is contained in:
parent
ff1b8dd52b
commit
3a6f722125
@ -53,6 +53,15 @@ class SiteTreeSubsites extends DataExtension
|
|||||||
'CrossSubsiteLinkTracking' => ['FieldName' => 'Varchar']
|
'CrossSubsiteLinkTracking' => ['FieldName' => 'Varchar']
|
||||||
];
|
];
|
||||||
|
|
||||||
|
private static array $scaffold_cms_fields_settings = [
|
||||||
|
'ignoreFields' => [
|
||||||
|
'Subsite',
|
||||||
|
],
|
||||||
|
'ignoreRelations' => [
|
||||||
|
'CrossSubsiteLinkTracking',
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
public function isMainSite()
|
public function isMainSite()
|
||||||
{
|
{
|
||||||
return $this->owner->SubsiteID == 0;
|
return $this->owner->SubsiteID == 0;
|
||||||
|
@ -8,10 +8,8 @@ use SilverStripe\CMS\Model\VirtualPage;
|
|||||||
use SilverStripe\Control\Controller;
|
use SilverStripe\Control\Controller;
|
||||||
use SilverStripe\Core\Config\Config;
|
use SilverStripe\Core\Config\Config;
|
||||||
use SilverStripe\Forms\DropdownField;
|
use SilverStripe\Forms\DropdownField;
|
||||||
|
use SilverStripe\Forms\FieldList;
|
||||||
use SilverStripe\Forms\LiteralField;
|
use SilverStripe\Forms\LiteralField;
|
||||||
use SilverStripe\Forms\TextareaField;
|
|
||||||
use SilverStripe\Forms\TextField;
|
|
||||||
use SilverStripe\Forms\TreeDropdownField;
|
|
||||||
use SilverStripe\ORM\ArrayList;
|
use SilverStripe\ORM\ArrayList;
|
||||||
use SilverStripe\ORM\DataObject;
|
use SilverStripe\ORM\DataObject;
|
||||||
use SilverStripe\Subsites\Forms\SubsitesTreeDropdownField;
|
use SilverStripe\Subsites\Forms\SubsitesTreeDropdownField;
|
||||||
@ -21,139 +19,68 @@ use SilverStripe\View\ArrayData;
|
|||||||
|
|
||||||
class SubsitesVirtualPage extends VirtualPage
|
class SubsitesVirtualPage extends VirtualPage
|
||||||
{
|
{
|
||||||
|
|
||||||
private static $table_name = 'SubsitesVirtualPage';
|
private static $table_name = 'SubsitesVirtualPage';
|
||||||
|
|
||||||
private static $description = 'Displays the content of a page on another subsite';
|
private static $description = 'Displays the content of a page on another subsite';
|
||||||
|
|
||||||
private static $db = [
|
|
||||||
'CustomMetaTitle' => 'Varchar(255)',
|
|
||||||
'CustomMetaKeywords' => 'Varchar(255)',
|
|
||||||
'CustomMetaDescription' => 'Text',
|
|
||||||
'CustomExtraMeta' => 'HTMLText'
|
|
||||||
];
|
|
||||||
|
|
||||||
private static $non_virtual_fields = [
|
private static $non_virtual_fields = [
|
||||||
'SubsiteID'
|
'SubsiteID'
|
||||||
];
|
];
|
||||||
|
|
||||||
public function getCMSFields()
|
public function getCMSFields()
|
||||||
{
|
{
|
||||||
$fields = parent::getCMSFields();
|
$this->beforeUpdateCMSFields(function (FieldList $fields) {
|
||||||
|
$subsites = DataObject::get(Subsite::class);
|
||||||
|
if (!$subsites) {
|
||||||
|
$subsites = ArrayList::create();
|
||||||
|
} else {
|
||||||
|
$subsites = ArrayList::create($subsites->toArray());
|
||||||
|
}
|
||||||
|
$subsites->push(ArrayData::create(['Title' => 'Main site', 'ID' => 0]));
|
||||||
|
|
||||||
$subsites = DataObject::get(Subsite::class);
|
|
||||||
if (!$subsites) {
|
|
||||||
$subsites = new ArrayList();
|
|
||||||
} else {
|
|
||||||
$subsites = ArrayList::create($subsites->toArray());
|
|
||||||
}
|
|
||||||
|
|
||||||
$subsites->push(new ArrayData(['Title' => 'Main site', 'ID' => 0]));
|
|
||||||
|
|
||||||
$fields->addFieldToTab(
|
|
||||||
'Root.Main',
|
|
||||||
DropdownField::create(
|
|
||||||
'CopyContentFromID_SubsiteID',
|
|
||||||
_t(__CLASS__ . '.SubsiteField', 'Subsite'),
|
|
||||||
$subsites->map('ID', 'Title')
|
|
||||||
)->addExtraClass('subsitestreedropdownfield-chooser no-change-track'),
|
|
||||||
'CopyContentFromID'
|
|
||||||
);
|
|
||||||
|
|
||||||
// Setup the linking to the original page.
|
|
||||||
$pageSelectionField = SubsitesTreeDropdownField::create(
|
|
||||||
'CopyContentFromID',
|
|
||||||
_t('SilverStripe\\CMS\\Model\\VirtualPage.CHOOSE', 'Linked Page'),
|
|
||||||
SiteTree::class,
|
|
||||||
'ID',
|
|
||||||
'MenuTitle'
|
|
||||||
);
|
|
||||||
|
|
||||||
$fields->addFieldToTab(
|
|
||||||
'Root.Main',
|
|
||||||
TreeDropdownField::create('CopyContentFromID', 'Linked Page', SiteTree::class)
|
|
||||||
);
|
|
||||||
|
|
||||||
if (Controller::has_curr() && Controller::curr()->getRequest()) {
|
|
||||||
$subsiteID = (int) Controller::curr()->getRequest()->requestVar('CopyContentFromID_SubsiteID');
|
|
||||||
$pageSelectionField->setSubsiteID($subsiteID);
|
|
||||||
}
|
|
||||||
$fields->replaceField('CopyContentFromID', $pageSelectionField);
|
|
||||||
|
|
||||||
// Create links back to the original object in the CMS
|
|
||||||
if ($this->CopyContentFromID) {
|
|
||||||
$editLink = Controller::join_links(
|
|
||||||
CMSPageEditController::singleton()->Link('show'),
|
|
||||||
$this->CopyContentFromID
|
|
||||||
);
|
|
||||||
|
|
||||||
$linkToContent = "
|
|
||||||
<a class=\"cmsEditlink\" href=\"$editLink\">" .
|
|
||||||
_t('SilverStripe\\CMS\\Model\\VirtualPage.EDITCONTENT', 'Click here to edit the content') .
|
|
||||||
'</a>';
|
|
||||||
$fields->removeByName('VirtualPageContentLinkLabel');
|
|
||||||
$fields->addFieldToTab(
|
$fields->addFieldToTab(
|
||||||
'Root.Main',
|
'Root.Main',
|
||||||
$linkToContentLabelField = LiteralField::create('VirtualPageContentLinkLabel', $linkToContent),
|
DropdownField::create(
|
||||||
'Title'
|
'CopyContentFromID_SubsiteID',
|
||||||
|
_t(__CLASS__ . '.SubsiteField', 'Subsite'),
|
||||||
|
$subsites->map('ID', 'Title')
|
||||||
|
)->addExtraClass('subsitestreedropdownfield-chooser no-change-track'),
|
||||||
|
'CopyContentFromID'
|
||||||
);
|
);
|
||||||
}
|
|
||||||
|
|
||||||
|
// Setup the linking to the original page.
|
||||||
|
$pageSelectionField = SubsitesTreeDropdownField::create(
|
||||||
|
'CopyContentFromID',
|
||||||
|
_t('SilverStripe\\CMS\\Model\\VirtualPage.CHOOSE', 'Linked Page'),
|
||||||
|
SiteTree::class,
|
||||||
|
'ID',
|
||||||
|
'MenuTitle'
|
||||||
|
);
|
||||||
|
if (Controller::has_curr() && Controller::curr()->getRequest()) {
|
||||||
|
$subsiteID = (int) Controller::curr()->getRequest()->requestVar('CopyContentFromID_SubsiteID');
|
||||||
|
$pageSelectionField->setSubsiteID($subsiteID);
|
||||||
|
}
|
||||||
|
$fields->replaceField('CopyContentFromID', $pageSelectionField);
|
||||||
|
|
||||||
$fields->addFieldToTab(
|
// Create links back to the original object in the CMS
|
||||||
'Root.Main',
|
if ($this->CopyContentFromID) {
|
||||||
TextField::create(
|
$editLink = Controller::join_links(
|
||||||
'CustomMetaTitle',
|
CMSPageEditController::singleton()->Link('show'),
|
||||||
$this->fieldLabel('CustomMetaTitle')
|
$this->CopyContentFromID
|
||||||
)->setDescription(_t(__CLASS__ . '.OverrideNote', 'Overrides inherited value from the source')),
|
);
|
||||||
'MetaTitle'
|
|
||||||
);
|
|
||||||
$fields->addFieldToTab(
|
|
||||||
'Root.Main',
|
|
||||||
TextareaField::create(
|
|
||||||
'CustomMetaKeywords',
|
|
||||||
$this->fieldLabel('CustomMetaKeywords')
|
|
||||||
)->setDescription(_t(__CLASS__ . '.OverrideNote', 'Overrides inherited value from the source')),
|
|
||||||
'MetaKeywords'
|
|
||||||
);
|
|
||||||
$fields->addFieldToTab(
|
|
||||||
'Root.Main',
|
|
||||||
TextareaField::create(
|
|
||||||
'CustomMetaDescription',
|
|
||||||
$this->fieldLabel('CustomMetaDescription')
|
|
||||||
)->setDescription(_t(__CLASS__ . '.OverrideNote', 'Overrides inherited value from the source')),
|
|
||||||
'MetaDescription'
|
|
||||||
);
|
|
||||||
$fields->addFieldToTab(
|
|
||||||
'Root.Main',
|
|
||||||
TextField::create(
|
|
||||||
'CustomExtraMeta',
|
|
||||||
$this->fieldLabel('CustomExtraMeta')
|
|
||||||
)->setDescription(_t(__CLASS__ . '.OverrideNote', 'Overrides inherited value from the source')),
|
|
||||||
'ExtraMeta'
|
|
||||||
);
|
|
||||||
|
|
||||||
return $fields;
|
$linkToContent = "
|
||||||
}
|
<a class=\"cmsEditlink\" href=\"$editLink\">" .
|
||||||
|
_t('SilverStripe\\CMS\\Model\\VirtualPage.EDITCONTENT', 'Click here to edit the content') .
|
||||||
public function fieldLabels($includerelations = true)
|
'</a>';
|
||||||
{
|
$fields->addFieldToTab(
|
||||||
$labels = parent::fieldLabels($includerelations);
|
'Root.Main',
|
||||||
$labels['CustomMetaTitle'] = _t('SilverStripe\\Subsites\\Model\\Subsite.CustomMetaTitle', 'Title');
|
LiteralField::create('VirtualPageContentLinkLabel', $linkToContent),
|
||||||
$labels['CustomMetaKeywords'] = _t(
|
'Title'
|
||||||
'SilverStripe\\Subsites\\Model\\Subsite.CustomMetaKeywords',
|
);
|
||||||
'Keywords'
|
}
|
||||||
);
|
});
|
||||||
$labels['CustomMetaDescription'] = _t(
|
return parent::getCMSFields();
|
||||||
'SilverStripe\\Subsites\\Model\\Subsite.CustomMetaDescription',
|
|
||||||
'Description'
|
|
||||||
);
|
|
||||||
$labels['CustomExtraMeta'] = _t(
|
|
||||||
'SilverStripe\\Subsites\\Model\\Subsite.CustomExtraMeta',
|
|
||||||
'Custom Meta Tags'
|
|
||||||
);
|
|
||||||
|
|
||||||
return $labels;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getCopyContentFromID_SubsiteID()
|
public function getCopyContentFromID_SubsiteID()
|
||||||
@ -172,13 +99,6 @@ class SubsitesVirtualPage extends VirtualPage
|
|||||||
unset($fields[$k]);
|
unset($fields[$k]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (SubsitesVirtualPage::$db as $field => $type) {
|
|
||||||
if (in_array($field, $fields ?? [])) {
|
|
||||||
unset($fields[array_search($field, $fields)]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $fields;
|
return $fields;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user