Skip to content

Commit

Permalink
Release v1.3.6 - Add support to custom iframe attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
reganlawton committed Oct 28, 2020
1 parent b22af22 commit d011aa7
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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',
}
})
}}
Expand All @@ -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
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.5",
"version": "1.3.6",
"keywords": [
"craft",
"cms",
Expand Down
6 changes: 6 additions & 0 deletions src/services/OembedService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit d011aa7

Please sign in to comment.