Skip to content

Commit

Permalink
Release v1.3.7 - Updates to OembedModel / GraphQL bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
reganlawton committed Jun 15, 2021
1 parent 55ad53d commit cefd5c2
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 22 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# oEmbed Changelog

## 1.3.7 - 2020-06-15

### Updated
- Updates to OembedModel / GraphQL bugfixes, this resolves issues [#74](https://github.com/wrav/oembed/issues/74) and PR [#75](https://github.com/wrav/oembed/issues/75). Thank you to @joshuabaker, @denisyilmaz and anyone else I missed.
- Clean up bugfixes changes

## 1.3.6 - 2020-10-28

### Added
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "wrav/oembed",
"description": "A simple plugin to extract media information from websites, like youtube videos, twitter statuses or blog articles.",
"type": "craft-plugin",
"version": "1.3.6",
"version": "1.3.7",
"keywords": [
"craft",
"cms",
Expand Down
34 changes: 14 additions & 20 deletions src/fields/OembedField.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,6 @@ class OembedField extends Field
*/
public $url = '';

/**
* @var array
*/
public $oembed = [];

/**
* @var mixed|null
*/
Expand Down Expand Up @@ -115,36 +110,35 @@ public function normalizeValue($value, ElementInterface $element = null)
{
// If null, don’t proceed
if ($value === null) {
return null;
return new OembedModel(null);
}

// If an instance of `OembedModel` and URL is set, return it
if ($value instanceof OembedModel && $value->url) {
return $this->value = $value;
if (UrlHelper::isFullUrl($value->url)) {
return $this->value = $value->url;
} else {
// If we get here, something’s gone wrong
return new OembedModel(null);
}
}

// If JSON object string, decode it and use that as the value
if (Json::isJsonObject($value)) {
$value = Json::decode($value); // Returns an array
}
$value = Json::decodeIfJson($value); // Returns an array

// If array with `url` attribute, that’s our url so update the value
if (is_array($value)) {
// Run `getValue` to avoid https://github.com/wrav/oembed/issues/74
while(is_array($value)) {
$value = ArrayHelper::getValue($value, 'url');
}

// Run `getValue` twice to avoid https://github.com/wrav/oembed/issues/74
if (is_array($value)) {
$value = ArrayHelper::getValue($value, 'url');
}

// If URL string, return an instance of `OembedModel`
// If URL stri ng, return an instance of `OembedModel`
if (is_string($value) && UrlHelper::isFullUrl($value)) {
return $this->value = new OembedModel($value);
}

// If we get here, something’s gone wrong
return null;
return new OembedModel(null);
}

/**
Expand Down
8 changes: 7 additions & 1 deletion src/models/OembedModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class OembedModel extends Model
/**
* @var mixed
*/
public $oembed = null;
private $oembed = null;

/**
* OembedModel constructor.
Expand Down Expand Up @@ -106,6 +106,12 @@ public function getUrl()
{
$value = $this->url;

if (is_string($value) && $decValue = Json::decodeIfJson($value, true)) {
if (isset($decValue['url'])) {
return new OembedModel($decValue['url'] ?? null);
}
}

if (is_string($value)) {
$decValue = json_decode($value, true);
if($decValue) {
Expand Down

0 comments on commit cefd5c2

Please sign in to comment.