mirror of
https://github.com/silverstripe/silverstripe-iframe
synced 2024-10-22 09:05:51 +00:00
FIX Update CMS fields now that they're being scaffolded (#95)
This commit is contained in:
parent
ea49b07a84
commit
6b5289ac3f
18
lang/en.yml
18
lang/en.yml
@ -10,12 +10,12 @@ en:
|
|||||||
SINGULARNAME: 'IFrame Page'
|
SINGULARNAME: 'IFrame Page'
|
||||||
TITLE_DESCRIPTION: 'Used by screen readers'
|
TITLE_DESCRIPTION: 'Used by screen readers'
|
||||||
VALIDATION_BANNEDURLSCHEME: 'This URL scheme is not allowed.'
|
VALIDATION_BANNEDURLSCHEME: 'This URL scheme is not allowed.'
|
||||||
db_AlternateContent: 'Alternate content'
|
db_AlternateContent: 'Alternate Content (appears when user has iframes disabled)'
|
||||||
db_AutoHeight: 'Auto height'
|
db_AutoHeight: 'Auto height (only works with same domain URLs)'
|
||||||
db_AutoWidth: 'Auto width'
|
db_AutoWidth: 'Auto width (100% of the available space)'
|
||||||
db_BottomContent: 'Bottom content'
|
db_BottomContent: 'Content (appears below iframe)'
|
||||||
db_FixedHeight: 'Fixed height'
|
db_FixedHeight: 'Fixed height (in pixels)'
|
||||||
db_FixedWidth: 'Fixed width'
|
db_FixedWidth: 'Fixed width (in pixels)'
|
||||||
db_ForceProtocol: 'Force protocol'
|
db_ForceProtocol: 'Force protocol?'
|
||||||
db_IFrameTitle: 'I frame title'
|
db_IFrameTitle: 'Description of contents (title)'
|
||||||
db_IFrameURL: 'I frame URL'
|
db_IFrameURL: 'Iframe URL'
|
||||||
|
@ -3,11 +3,9 @@
|
|||||||
namespace SilverStripe\IFrame;
|
namespace SilverStripe\IFrame;
|
||||||
|
|
||||||
use Page;
|
use Page;
|
||||||
use SilverStripe\Forms\TextField;
|
|
||||||
use SilverStripe\Forms\DropdownField;
|
use SilverStripe\Forms\DropdownField;
|
||||||
use SilverStripe\Forms\CheckboxField;
|
use SilverStripe\Forms\FieldList;
|
||||||
use SilverStripe\Forms\NumericField;
|
use SilverStripe\Forms\TextField;
|
||||||
use SilverStripe\Forms\HTMLEditor\HtmlEditorField;
|
|
||||||
use SilverStripe\ORM\FieldType\DBField;
|
use SilverStripe\ORM\FieldType\DBField;
|
||||||
use SilverStripe\ORM\ValidationException;
|
use SilverStripe\ORM\ValidationException;
|
||||||
use SilverStripe\ORM\ValidationResult;
|
use SilverStripe\ORM\ValidationResult;
|
||||||
@ -20,15 +18,15 @@ use SilverStripe\ORM\ValidationResult;
|
|||||||
class IFramePage extends Page
|
class IFramePage extends Page
|
||||||
{
|
{
|
||||||
private static $db = array(
|
private static $db = array(
|
||||||
|
'ForceProtocol' => 'Varchar',
|
||||||
'IFrameURL' => 'Text',
|
'IFrameURL' => 'Text',
|
||||||
'IFrameTitle' => 'Varchar',
|
'IFrameTitle' => 'Varchar',
|
||||||
'AutoHeight' => 'Boolean(1)',
|
'AutoHeight' => 'Boolean(1)',
|
||||||
'AutoWidth' => 'Boolean(1)',
|
'AutoWidth' => 'Boolean(1)',
|
||||||
'FixedHeight' => 'Int(500)',
|
'FixedHeight' => 'Int(500)',
|
||||||
'FixedWidth' => 'Int(0)',
|
'FixedWidth' => 'Int(0)',
|
||||||
'AlternateContent' => 'HTMLText',
|
|
||||||
'BottomContent' => 'HTMLText',
|
'BottomContent' => 'HTMLText',
|
||||||
'ForceProtocol' => 'Varchar',
|
'AlternateContent' => 'HTMLText',
|
||||||
);
|
);
|
||||||
|
|
||||||
private static $defaults = array(
|
private static $defaults = array(
|
||||||
@ -46,52 +44,40 @@ class IFramePage extends Page
|
|||||||
|
|
||||||
public function getCMSFields()
|
public function getCMSFields()
|
||||||
{
|
{
|
||||||
$fields = parent::getCMSFields();
|
$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'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
$fields->removeFieldFromTab('Root.Main', 'Content');
|
$contentField = $fields->dataFieldByName('Content');
|
||||||
$fields->addFieldsToTab('Root.Main', [
|
if ($contentField) {
|
||||||
$url = TextField::create('IFrameURL', 'Iframe URL'),
|
$fields->removeByName('Content');
|
||||||
TextField::create('IFrameTitle', 'Description of contents (title)')
|
$contentField->setTitle(_t(__CLASS__ . '.db_Content', 'Content (appears above iframe)'));
|
||||||
->setDescription(_t(__CLASS__ . '.TITLE_DESCRIPTION', 'Used by screen readers')),
|
$fields->addFieldToTab('Root.Main', $contentField, 'BottomContent');
|
||||||
]);
|
}
|
||||||
$url->setRightTitle(
|
$fields->dataFieldByName('BottomContent')?->addExtraClass('stacked');
|
||||||
DBField::create_field(
|
$fields->dataFieldByName('AlternateContent')?->addExtraClass('stacked');
|
||||||
'HTMLText',
|
});
|
||||||
'Can be absolute (<em>http://silverstripe.com</em>) or relative to this site (<em>about-us</em>).'
|
return parent::getCMSFields();
|
||||||
)
|
|
||||||
);
|
|
||||||
$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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user