mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Merge pull request #9615 from creative-commoners/pulls/4.6/embed-iframe-dimensions
FIX Set iframe dimension attributes specified in shortcode
This commit is contained in:
commit
52d38a8b4a
@ -160,6 +160,17 @@ class EmbedShortcodeProvider implements ShortcodeHandler
|
||||
$arguments['style'] = 'width: ' . intval($arguments['width']) . 'px;';
|
||||
}
|
||||
|
||||
// override iframe dimension attributes provided by webservice with ones specified in shortcode arguments
|
||||
foreach (['width', 'height'] as $attr) {
|
||||
if (!($value = $arguments[$attr] ?? false)) {
|
||||
continue;
|
||||
}
|
||||
foreach (['"', "'"] as $quote) {
|
||||
$rx = "/(<iframe .*?)$attr=$quote([0-9]+)$quote([^>]+>)/";
|
||||
$content = preg_replace($rx, "$1{$attr}={$quote}{$value}{$quote}$3", $content);
|
||||
}
|
||||
}
|
||||
|
||||
$data = [
|
||||
'Arguments' => $arguments,
|
||||
'Attributes' => static::buildAttributeListFromArguments($arguments, ['width', 'height', 'url', 'caption']),
|
||||
|
@ -37,8 +37,8 @@ class EmbedShortcodeProviderTest extends SapphireTest
|
||||
[
|
||||
'url' => static::$test_youtube,
|
||||
'caption' => 'A nice video',
|
||||
'width' => 480,
|
||||
'height' => 360,
|
||||
'width' => 777,
|
||||
'height' => 437,
|
||||
],
|
||||
[
|
||||
'version' => '1.0',
|
||||
@ -58,7 +58,7 @@ class EmbedShortcodeProviderTest extends SapphireTest
|
||||
);
|
||||
$this->assertEqualIgnoringWhitespace(
|
||||
<<<EOS
|
||||
<div style="width: 480px;"><iframe width="480" height="270" src="https://www.youtube.com/embed/dM15HfUYwF0?feature=oembed" frameborder="0" allowfullscreen></iframe>
|
||||
<div style="width: 777px;"><iframe width="777" height="437" src="https://www.youtube.com/embed/dM15HfUYwF0?feature=oembed" frameborder="0" allowfullscreen></iframe>
|
||||
<p class="caption">A nice video</p></div>
|
||||
EOS
|
||||
,
|
||||
|
Loading…
Reference in New Issue
Block a user