Skip to content

Commit

Permalink
Fixed embed validation error and limited types always being set to null
Browse files Browse the repository at this point in the history
  • Loading branch information
gorriecoe committed Jul 10, 2018
1 parent 4fc6607 commit 48b97a4
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions src/extensions/Embeddable.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,6 @@ class Embeddable extends DataExtension
'EmbedImage'
];

/**
* List the allowed included embed types. If null all are allowed.
* @var array
*/
private static $allowed_embed_types = null;

/**
* Defines tab to insert the embed fields into.
* @var string
Expand Down Expand Up @@ -138,7 +132,7 @@ public function updateCMSFields(FieldList $fields)
)
);

if (Count($owner->AllowedEmbedTypes) > 1) {
if (isset($owner->AllowedEmbedTypes) && Count($owner->AllowedEmbedTypes) > 1) {
$fields->addFieldToTab(
'Root.' . $tab,
ReadonlyField::create(
Expand Down Expand Up @@ -214,7 +208,7 @@ public function onBeforeWrite()
}

/**
* @return array()
* @return array()|null
*/
public function getAllowedEmbedTypes()
{
Expand All @@ -229,17 +223,17 @@ public function validate(ValidationResult $validationResult)
{
$owner = $this->owner;
$allowed_types = $owner->AllowedEmbedTypes;
if ($sourceURL = $owner->SourceURL && isset($allowed_types)) {
$sourceURL = $owner->EmbedSourceURL;
if ($sourceURL && isset($allowed_types)) {
$embed = Embed::create($sourceURL);
if (!in_array($embed->getType(), $allowed_types)) {
if (!in_array($embed->Type, $allowed_types)) {
$string = implode(', ', $allowed_types);
$string = (substr($string, -1) == ',') ? substr_replace($string, ' or', -1) : $string;
$validationResult->error(
$validationResult->addError(
_t(__CLASS__ . '.ERRORNOTSTRING', "The embed content is not a $string")
);
}
}

return $validationResult;
}

Expand Down

0 comments on commit 48b97a4

Please sign in to comment.