Skip to content

Commit

Permalink
UPDATE Silverstripe 5 compatibility (#23)
Browse files Browse the repository at this point in the history
* UPDATE Silverstripe 5 requirement

* UPDATE implement Embed module in place of EmbedObject

* UPDATE composer requirements

* UPDATE remove assertion for legacy object

* UPDATE only test against PHP 8.1
  • Loading branch information
muskie9 committed Oct 19, 2023
1 parent 283e674 commit fcca8ee
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 29 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ jobs:
fail-fast: false
matrix:
php-version:
- "7.4"
- "8.0"
- "8.1"

steps:
Expand Down
14 changes: 10 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,19 @@
"type": "silverstripe-vendormodule",
"license": "BSD-3-Clause",
"require": {
"dnadesign/silverstripe-elemental": "^4.8",
"dynamic/silverstripe-linkable": "^1.0"
"dnadesign/silverstripe-elemental": "^5.0",
"dnadesign/silverstripe-embed": "dev-master",
"gorriecoe/silverstripe-htmltag": "dev-master as 1.1.0"
},
"require-dev": {
"silverstripe/recipe-testing": "^2",
"squizlabs/php_codesniffer": "^3.0"
"silverstripe/recipe-testing": "^3"
},
"repositories": [
{
"type": "vcs",
"url": "git@github.com:dnadesign/silverstripe-htmltag.git"
}
],
"config": {
"allow-plugins": {
"composer/installers": true,
Expand Down
38 changes: 27 additions & 11 deletions src/Elements/ElementOembed.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,49 @@
namespace Dynamic\Elements\Oembed\Elements;

use DNADesign\Elemental\Models\BaseElement;
use gorriecoe\Embed\Extensions\Embeddable;
use Sheadawson\Linkable\Forms\EmbeddedObjectField;
use Sheadawson\Linkable\Models\EmbeddedObject;
use SilverStripe\Forms\FieldList;
use SilverStripe\ORM\FieldType\DBField;

class ElementOembed extends BaseElement
{
/**
* @var string
*/
/**
* @var string
*/
private static $icon = 'font-icon-block-media';

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

/**
* @var array
* @var string[]
*/
private static $has_one = [
'EmbeddedObject' => EmbeddedObject::class,
private static $extensions = [
Embeddable::class,
];

/**
* @var string[]
*/
private static $cascade_duplicates = [
'EmbeddedObject',
private static $allowed_embed_types = [
'video',
];

/**
* @var string
*/
private static $embed_tab = 'Main';

/**
* Set to false to prevent an in-line edit form from showing in an elemental area. Instead the element will be
* clickable and a GridFieldDetailForm will be used.
Expand All @@ -43,18 +55,22 @@ class ElementOembed extends BaseElement
*/
private static $inline_editable = false;

/**
* @param $includerelations
* @return array
*/
public function fieldLabels($includerelations = true)
{
$labels = parent::fieldLabels($includerelations);
$labels['EmbeddedObject'] = _t(__CLASS__ . '.EmbeddedObjectLabel', 'Content from oEmbed URL');
//$labels['EmbeddedObject'] = _t(__CLASS__ . '.EmbeddedObjectLabel', 'Content from oEmbed URL');

return $labels;
}

/**
* @return FieldList
*/
public function getCMSFields()
/*public function getCMSFields()
{
$fields = parent::getCMSFields();
Expand All @@ -64,16 +80,16 @@ public function getCMSFields()
);
return $fields;
}
}//*/

/**
* @return DBHTMLText
*/
public function getSummary()
{
if ($this->EmbeddedObject()->ID) {
/*if ($this->EmbeddedObject()->ID) {
return DBField::create_field('HTMLText', $this->EmbeddedObject->Title)->Summary(20);
}
}//*/

return DBField::create_field('HTMLText', '<p>External Content</p>')->Summary(20);
}
Expand All @@ -93,6 +109,6 @@ protected function provideBlockSchema()
*/
public function getType()
{
return _t(__CLASS__.'.BlockType', 'Media');
return _t(__CLASS__ . '.BlockType', 'Media');
}
}
20 changes: 9 additions & 11 deletions templates/Dynamic/Elements/Oembed/Elements/ElementOembed.ss
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
<% if $Title && $ShowTitle %><h2 class="element__title">$Title</h2><% end_if %>

<% if $EmbeddedObject %>
<div class="row element__oembed__object">
<div class="col-md-12 card">
<div class="embed-responsive embed-responsive-16by9">
$EmbeddedObject
</div>
<div class="card-body">
<% if $EmbeddedObject.Title %><h3 class="card-title">$EmbeddedObject.Title</h3><% end_if %>
<% if $EmbeddedObject.Description %><p class="card-text">$EmbeddedObject.Description</p><% end_if %>
</div>
<div class="row element__oembed__object">
<div class="col-md-12 card">
<div class="embed-responsive embed-responsive-16by9">
$Embed
</div>
<div class="card-body">
<% if $EmbedTitle %><h3 class="card-title">$EmbedTitle</h3><% end_if %>
<% if $EmbedDescription %><p class="card-text">$EmbedDescription</p><% end_if %>
</div>
</div>
<% end_if %>
</div>
1 change: 0 additions & 1 deletion tests/Elements/ElementOembedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public function testGetCMSFields()
$object = $this->objFromFixture(ElementOembed::class, 'one');
$fields = $object->getCMSFields();
$this->assertInstanceOf(FieldList::class, $fields);
$this->assertNotNull($fields->dataFieldByName('EmbeddedObject'));
}

/**
Expand Down

0 comments on commit fcca8ee

Please sign in to comment.