Skip to content

Commit 48b97a4

Browse files
committed
Fixed embed validation error and limited types always being set to null
1 parent 4fc6607 commit 48b97a4

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

src/extensions/Embeddable.php

+6-12
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,6 @@ class Embeddable extends DataExtension
6060
'EmbedImage'
6161
];
6262

63-
/**
64-
* List the allowed included embed types. If null all are allowed.
65-
* @var array
66-
*/
67-
private static $allowed_embed_types = null;
68-
6963
/**
7064
* Defines tab to insert the embed fields into.
7165
* @var string
@@ -138,7 +132,7 @@ public function updateCMSFields(FieldList $fields)
138132
)
139133
);
140134

141-
if (Count($owner->AllowedEmbedTypes) > 1) {
135+
if (isset($owner->AllowedEmbedTypes) && Count($owner->AllowedEmbedTypes) > 1) {
142136
$fields->addFieldToTab(
143137
'Root.' . $tab,
144138
ReadonlyField::create(
@@ -214,7 +208,7 @@ public function onBeforeWrite()
214208
}
215209

216210
/**
217-
* @return array()
211+
* @return array()|null
218212
*/
219213
public function getAllowedEmbedTypes()
220214
{
@@ -229,17 +223,17 @@ public function validate(ValidationResult $validationResult)
229223
{
230224
$owner = $this->owner;
231225
$allowed_types = $owner->AllowedEmbedTypes;
232-
if ($sourceURL = $owner->SourceURL && isset($allowed_types)) {
226+
$sourceURL = $owner->EmbedSourceURL;
227+
if ($sourceURL && isset($allowed_types)) {
233228
$embed = Embed::create($sourceURL);
234-
if (!in_array($embed->getType(), $allowed_types)) {
229+
if (!in_array($embed->Type, $allowed_types)) {
235230
$string = implode(', ', $allowed_types);
236231
$string = (substr($string, -1) == ',') ? substr_replace($string, ' or', -1) : $string;
237-
$validationResult->error(
232+
$validationResult->addError(
238233
_t(__CLASS__ . '.ERRORNOTSTRING', "The embed content is not a $string")
239234
);
240235
}
241236
}
242-
243237
return $validationResult;
244238
}
245239

0 commit comments

Comments
 (0)