-
Notifications
You must be signed in to change notification settings - Fork 106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FIX Update CMS fields now that they're being scaffolded #589
Merged
emteknetnz
merged 1 commit into
silverstripe:4
from
creative-commoners:pulls/4/scaffold-sitetree
Aug 15, 2024
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,10 +8,8 @@ | |
use SilverStripe\Control\Controller; | ||
use SilverStripe\Core\Config\Config; | ||
use SilverStripe\Forms\DropdownField; | ||
use SilverStripe\Forms\FieldList; | ||
use SilverStripe\Forms\LiteralField; | ||
use SilverStripe\Forms\TextareaField; | ||
use SilverStripe\Forms\TextField; | ||
use SilverStripe\Forms\TreeDropdownField; | ||
use SilverStripe\ORM\ArrayList; | ||
use SilverStripe\ORM\DataObject; | ||
use SilverStripe\Subsites\Forms\SubsitesTreeDropdownField; | ||
|
@@ -21,139 +19,68 @@ | |
|
||
class SubsitesVirtualPage extends VirtualPage | ||
{ | ||
|
||
private static $table_name = 'SubsitesVirtualPage'; | ||
|
||
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 = [ | ||
'SubsiteID' | ||
]; | ||
|
||
public function getCMSFields() | ||
{ | ||
$fields = parent::getCMSFields(); | ||
|
||
$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 | ||
); | ||
$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])); | ||
|
||
$linkToContent = " | ||
<a class=\"cmsEditlink\" href=\"$editLink\">" . | ||
_t('SilverStripe\\CMS\\Model\\VirtualPage.EDITCONTENT', 'Click here to edit the content') . | ||
'</a>'; | ||
$fields->removeByName('VirtualPageContentLinkLabel'); | ||
$fields->addFieldToTab( | ||
'Root.Main', | ||
$linkToContentLabelField = LiteralField::create('VirtualPageContentLinkLabel', $linkToContent), | ||
'Title' | ||
DropdownField::create( | ||
'CopyContentFromID_SubsiteID', | ||
_t(__CLASS__ . '.SubsiteField', 'Subsite'), | ||
$subsites->map('ID', 'Title') | ||
)->addExtraClass('subsitestreedropdownfield-chooser no-change-track'), | ||
'CopyContentFromID' | ||
); | ||
} | ||
|
||
|
||
$fields->addFieldToTab( | ||
'Root.Main', | ||
TextField::create( | ||
'CustomMetaTitle', | ||
$this->fieldLabel('CustomMetaTitle') | ||
)->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; | ||
} | ||
|
||
public function fieldLabels($includerelations = true) | ||
{ | ||
$labels = parent::fieldLabels($includerelations); | ||
$labels['CustomMetaTitle'] = _t('SilverStripe\\Subsites\\Model\\Subsite.CustomMetaTitle', 'Title'); | ||
$labels['CustomMetaKeywords'] = _t( | ||
'SilverStripe\\Subsites\\Model\\Subsite.CustomMetaKeywords', | ||
'Keywords' | ||
); | ||
$labels['CustomMetaDescription'] = _t( | ||
'SilverStripe\\Subsites\\Model\\Subsite.CustomMetaDescription', | ||
'Description' | ||
); | ||
$labels['CustomExtraMeta'] = _t( | ||
'SilverStripe\\Subsites\\Model\\Subsite.CustomExtraMeta', | ||
'Custom Meta Tags' | ||
); | ||
|
||
return $labels; | ||
// Setup the linking to the original page. | ||
$pageSelectionField = SubsitesTreeDropdownField::create( | ||
'CopyContentFromID', | ||
_t('SilverStripe\\CMS\\Model\\VirtualPage.CHOOSE', 'Linked Page'), | ||
SiteTree::class, | ||
'ID', | ||
'MenuTitle' | ||
); | ||
Comment on lines
+52
to
+58
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This field is moved to the top which is right next to the subsite selector field and matches where it sits in the normal virtual page. |
||
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->addFieldToTab( | ||
'Root.Main', | ||
LiteralField::create('VirtualPageContentLinkLabel', $linkToContent), | ||
'Title' | ||
); | ||
} | ||
}); | ||
return parent::getCMSFields(); | ||
} | ||
|
||
public function getCopyContentFromID_SubsiteID() | ||
|
@@ -172,13 +99,6 @@ public function getVirtualFields() | |
unset($fields[$k]); | ||
} | ||
} | ||
|
||
foreach (SubsitesVirtualPage::$db as $field => $type) { | ||
if (in_array($field, $fields ?? [])) { | ||
unset($fields[array_search($field, $fields)]); | ||
} | ||
} | ||
|
||
return $fields; | ||
} | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved the relevant ones to
VirtualPage
(see silverstripe/silverstripe-cms#2983)Removed
CustomMetaTitle
andCustomMetaKeywords
because the fields they're intended to override were long-since removed fromSiteTree
.