Skip to content

Commit

Permalink
Merge pull request #4 from nswdpc/ss410
Browse files Browse the repository at this point in the history
Update minimum required versions
  • Loading branch information
JamesDPC authored Dec 5, 2022
2 parents 5a1282f + d1e4348 commit e6ef6fb
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 34 deletions.
22 changes: 12 additions & 10 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
/tests export-ignore
/docs export-ignore
/client/src export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/.php_cs.dist
/.phpcs.xml.dist
/.phpunit.xml.dist
/.waratah export-ignore
/README.md export-ignore
/tests export-ignore
/docs export-ignore
/client/src export-ignore
/.editorconfig export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/.php-cs-fixer.dist.php export-ignore
/phpunit.xml.dist export-ignore
/.waratah export-ignore
/code-of-conduct.md export-ignore
/CONTRIBUTING.md export-ignore
/README.md export-ignore
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/client/node_modules
/vendor/
.DS_Store
/.php-cs-cache
/.php-cs-fixer.cache
4 changes: 2 additions & 2 deletions .php_cs.dist → .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
$finder = PhpCsFixer\Finder::create()
->in(__DIR__);

return PhpCsFixer\Config::create()
->setRules([
$config = new PhpCsFixer\Config();
return $config->setRules([
'@PSR2' => true,
'array_indentation' => true,
'array_syntax' => ['syntax' => 'short'],
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
}
],
"require": {
"dnadesign/silverstripe-elemental": "^4.3.0",
"dnadesign/silverstripe-elemental": "^4.9.0",
"codem/silverstripe-html5-inputs": "^0.1",
"gorriecoe/silverstripe-link": "^1.0.0"
"gorriecoe/silverstripe-link": "^1.0"
},
"require-dev": {
"phpunit/phpunit": "^5.7",
"phpunit/phpunit": "^9.5",
"squizlabs/php_codesniffer": "^3.0"
},
"extra": {
Expand Down
11 changes: 0 additions & 11 deletions phpcs.xml.dist

This file was deleted.

76 changes: 71 additions & 5 deletions src/Models/Elements/ElementIframe.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,52 @@
use SilverStripe\Security\Permission;
use SilverStripe\View\Requirements;
use SilverStripe\View\ViewableData;

/**
* ElementIframe class
* Iframe content block
*
* @author Mark Taylor <[email protected]>
* @author James Ellis <[email protected]>
* @author Mark Taylor
* @author James Ellis
*/
class ElementIframe extends BaseElement implements PermissionProvider {

/**
* @var string
*/
private static $table_name = 'ElementIframe';

/**
* @var string
*/
private static $icon = 'font-icon-code';

/**
* @var string
*/
private static $singular_name = 'Iframe';

/**
* @var string
*/
private static $plural_name = 'Iframes';

/**
* @var array
*/
private static $default_allow_attributes = [
'fullscreen'
];

/**
* @var array
*/
private static $has_one = [
'URL' => Link::class,
];

/**
* @var array
*/
private static $db = [
'IsLazy' => 'Boolean',
'IsFullWidth' => 'Boolean',
Expand All @@ -48,6 +71,9 @@ class ElementIframe extends BaseElement implements PermissionProvider {
'AlternateContent' => 'Text'
];

/**
* @var array
*/
private static $defaults = [
'IsLazy' => 1,
'IsFullWidth' => 1,
Expand All @@ -56,23 +82,42 @@ class ElementIframe extends BaseElement implements PermissionProvider {
'Height' => '400',
];

/**
* @var string
*/
private static $title = 'Iframe';

/**
* @var string
*/
private static $description = 'Display content in an HTML iframe tag';

/**
* @var array
*/
private static $responsive_options = [
'16x9' => '16x9',
'4x3' => '4x3'
];

/**
* @var string
*/
private static $default_height = '400';

/**
* @var string
*/
private static $load_polyfill = true;

/**
* @var bool
*/
private static $resizer_log = false;

/**
* @inheritdoc
*/
public function getType()
{
return _t(__CLASS__ . '.BlockType', 'Iframe');
Expand Down Expand Up @@ -180,25 +225,40 @@ public function providePermissions()
];
}

/**
* @inheritdoc
*/
public function canEdit($member = null)
{
return Permission::checkMember($member, 'ELEMENT_IFRAME_EDIT');
}

/**
* @inheritdoc
*/
public function canDelete($member = null)
{
return Permission::checkMember($member, 'ELEMENT_IFRAME_DELETE');
}

/**
* @inheritdoc
*/
public function canCreate($member = null, $context = [])
{
return Permission::checkMember($member, 'ELEMENT_IFRAME_EDIT');
}

/**
* @inheritdoc
*/
public function getResponsiveOptions() {
return $this->config()->get('responsive_options') ?: [];
}

/**
* @inheritdoc
*/
public function onBeforeWrite()
{
parent::onBeforeWrite();
Expand Down Expand Up @@ -275,15 +335,18 @@ public function getIframeHeight() {
/**
* Return the width or 100% if not set
*/
public function getIframeWidth() {
public function getIframeWidth() : string {
$width = $this->getField('Width');
if(!$width || $this->IsFullWidth || $this->IsResponsive) {
$width = "100%";
}
return $width;
}

protected function getDefaultHeight() {
/**
* Return the default height or a set height of 400 if not set
*/
protected function getDefaultHeight() : string {
$height = $this->config()->get('default_height');
if(!$height) {
$height = '400';
Expand All @@ -309,6 +372,9 @@ public function getURLAsString() : string {
return $url;
}

/**
* @inheritdoc
*/
public function getCMSFields() {
$fields = parent::getCMSFields();

Expand Down
4 changes: 2 additions & 2 deletions tests/IframeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class IframeTest extends SapphireTest
/**
* @inheritdoc
*/
public function setUp() {
public function setUp() : void {
parent::setUp();
Config::inst()->update(
ElementIframe::class,
Expand Down Expand Up @@ -66,7 +66,7 @@ public function setUp() {
/**
* @inheritdoc
*/
public function tearDown()
public function tearDown() : void
{
parent::tearDown();
TestAssetStore::reset();
Expand Down

0 comments on commit e6ef6fb

Please sign in to comment.