diff --git a/CHANGELOG.md b/CHANGELOG.md index c8b183c..77f46cf 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # oEmbed Changelog +## 1.3.6 - 2020-10-28 + +### Added +- Added new render option called `attributes` to allow custom attributes to bet added to iframe element, this resolves issue ([#51](https://github.com/wrav/oembed/issues/51)). + ## 1.3.5 - 2020-10-28 ### Updated diff --git a/README.md b/README.md index a2363f5..feaab71 100755 --- a/README.md +++ b/README.md @@ -51,6 +51,10 @@ Updating the embed URL, such as autoplay, rel, mute paramaters. This allows for mute: 0, loop: 1, autopause: 1, + }, + attributes: { + title: 'Main title', + 'data-title': 'Some other title', } }) }} @@ -64,6 +68,17 @@ Updating the width & height attributes on the iframe can be done using the follo }) }} +or + + {{ + entry.oembed_field.render({ + attributes: { + width: 640, + height: 480, + } + }) + }} + You can access additional media details using the examples below. entry.field.media.title diff --git a/composer.json b/composer.json index 7bfde72..710c883 100755 --- a/composer.json +++ b/composer.json @@ -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.5", + "version": "1.3.6", "keywords": [ "craft", "cms", diff --git a/src/services/OembedService.php b/src/services/OembedService.php index ec9cb4f..e8aaa9b 100755 --- a/src/services/OembedService.php +++ b/src/services/OembedService.php @@ -119,6 +119,12 @@ public function __call(string $name , array $arguments ) $src = preg_replace('/\?(.*)$/i', '?rel='. (!!$options['rel'] ? '1' : '0') .'&${1}', $src); } + if(!empty($options['attributes'])) { + foreach((array)$options['attributes'] as $key => $value) { + $iframe->setAttribute($key, $value); + } + } + $iframe->setAttribute('src', $src); $media->code = $dom->saveXML($iframe, LIBXML_NOEMPTYTAG); } catch (\Exception $exception) {