-
Notifications
You must be signed in to change notification settings - Fork 17
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 #95
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,11 +3,9 @@ | |
namespace SilverStripe\IFrame; | ||
|
||
use Page; | ||
use SilverStripe\Forms\TextField; | ||
use SilverStripe\Forms\DropdownField; | ||
use SilverStripe\Forms\CheckboxField; | ||
use SilverStripe\Forms\NumericField; | ||
use SilverStripe\Forms\HTMLEditor\HtmlEditorField; | ||
use SilverStripe\Forms\FieldList; | ||
use SilverStripe\Forms\TextField; | ||
use SilverStripe\ORM\FieldType\DBField; | ||
use SilverStripe\ORM\ValidationException; | ||
use SilverStripe\ORM\ValidationResult; | ||
|
@@ -20,15 +18,15 @@ | |
class IFramePage extends Page | ||
{ | ||
private static $db = array( | ||
'ForceProtocol' => 'Varchar', | ||
'IFrameURL' => 'Text', | ||
'IFrameTitle' => 'Varchar', | ||
'AutoHeight' => 'Boolean(1)', | ||
'AutoWidth' => 'Boolean(1)', | ||
'FixedHeight' => 'Int(500)', | ||
'FixedWidth' => 'Int(0)', | ||
'AlternateContent' => 'HTMLText', | ||
'BottomContent' => 'HTMLText', | ||
'ForceProtocol' => 'Varchar', | ||
'AlternateContent' => 'HTMLText', | ||
); | ||
|
||
private static $defaults = array( | ||
|
@@ -46,52 +44,40 @@ class IFramePage extends Page | |
|
||
public function getCMSFields() | ||
{ | ||
$fields = parent::getCMSFields(); | ||
|
||
$fields->removeFieldFromTab('Root.Main', 'Content'); | ||
$fields->addFieldsToTab('Root.Main', [ | ||
$url = TextField::create('IFrameURL', 'Iframe URL'), | ||
TextField::create('IFrameTitle', 'Description of contents (title)') | ||
->setDescription(_t(__CLASS__ . '.TITLE_DESCRIPTION', 'Used by screen readers')), | ||
]); | ||
$url->setRightTitle( | ||
DBField::create_field( | ||
'HTMLText', | ||
'Can be absolute (<em>http://silverstripe.com</em>) or relative to this site (<em>about-us</em>).' | ||
) | ||
); | ||
$fields->addFieldToTab( | ||
'Root.Main', | ||
DropdownField::create('ForceProtocol', 'Force protocol?') | ||
->setSource(array('http://' => 'http://', 'https://' => 'https://')) | ||
->setEmptyString('') | ||
->setDescription( | ||
'Avoids mixed content warnings when iframe content is just available under a specific protocol' | ||
), | ||
'Metadata' | ||
); | ||
$fields->addFieldsToTab('Root.Main', [ | ||
CheckboxField::create('AutoHeight', 'Auto height (only works with same domain URLs)'), | ||
CheckboxField::create('AutoWidth', 'Auto width (100% of the available space)'), | ||
NumericField::create('FixedHeight', 'Fixed height (in pixels)'), | ||
NumericField::create('FixedWidth', 'Fixed width (in pixels)'), | ||
HtmlEditorField::create('Content', 'Content (appears above iframe)'), | ||
HtmlEditorField::create('BottomContent', 'Content (appears below iframe)'), | ||
HtmlEditorField::create('AlternateContent', 'Alternate Content (appears when user has iframes disabled)') | ||
]); | ||
|
||
// Move the Metadata field to last position, but make a check for it's | ||
// existence first. | ||
// | ||
// See https://github.com/silverstripe-labs/silverstripe-iframe/issues/18 | ||
$mainTab = $fields->findOrMakeTab('Root.Main'); | ||
$mainTabFields = $mainTab->FieldList(); | ||
$metaDataField = $mainTabFields->fieldByName('Metadata'); | ||
if ($metaDataField) { | ||
$mainTabFields->removeByName('Metadata'); | ||
$mainTabFields->push($metaDataField); | ||
} | ||
return $fields; | ||
$this->beforeUpdateCMSFields(function (FieldList $fields) { | ||
$fields->replaceField( | ||
'IFrameURL', | ||
TextField::create('IFrameURL', $this->fieldLabel('IFrameURL')) | ||
->setRightTitle( | ||
DBField::create_field( | ||
'HTMLText', | ||
'Can be absolute (<em>http://silverstripe.com</em>) ' | ||
. 'or relative to this site (<em>about-us</em>).' | ||
) | ||
) | ||
); | ||
$fields->dataFieldByName('IFrameTitle') | ||
->setDescription(_t(__CLASS__ . '.TITLE_DESCRIPTION', 'Used by screen readers')); | ||
$fields->replaceField( | ||
'ForceProtocol', | ||
DropdownField::create('ForceProtocol', $this->fieldLabel('ForceProtocol')) | ||
->setSource(array('http://' => 'http://', 'https://' => 'https://')) | ||
->setEmptyString('') | ||
->setDescription( | ||
'Avoids mixed content warnings when iframe content is just available under a specific protocol' | ||
) | ||
); | ||
|
||
$contentField = $fields->dataFieldByName('Content'); | ||
if ($contentField) { | ||
$fields->removeByName('Content'); | ||
$contentField->setTitle(_t(__CLASS__ . '.db_Content', 'Content (appears above iframe)')); | ||
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.
|
||
$fields->addFieldToTab('Root.Main', $contentField, 'BottomContent'); | ||
} | ||
$fields->dataFieldByName('BottomContent')?->addExtraClass('stacked'); | ||
$fields->dataFieldByName('AlternateContent')?->addExtraClass('stacked'); | ||
Comment on lines
+77
to
+78
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. Intentionally made these wider, because it was silly how much space was being wasted |
||
}); | ||
return parent::getCMSFields(); | ||
} | ||
|
||
/** | ||
|
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.
See silverstripe/silverstripe-cms#2983 (comment) about translation strings.