Merge branch '4.6' into 4

This commit is contained in:
Steve Boyd 2020-07-29 11:38:49 +12:00
commit 8287fad24d
4 changed files with 60 additions and 3 deletions

View File

@ -2,6 +2,7 @@
namespace SilverStripe\Forms; namespace SilverStripe\Forms;
use SilverStripe\ORM\ArrayLib;
use SilverStripe\ORM\ArrayList; use SilverStripe\ORM\ArrayList;
use SilverStripe\View\ArrayData; use SilverStripe\View\ArrayData;
@ -104,4 +105,14 @@ class GroupedDropdownField extends DropdownField
); );
return $values; return $values;
} }
/**
* @return SingleLookupField
*/
public function performReadonlyTransformation()
{
$field = parent::performReadonlyTransformation();
$field->setSource(ArrayLib::flatten($this->getSource()));
return $field;
}
} }

View File

@ -160,6 +160,17 @@ class EmbedShortcodeProvider implements ShortcodeHandler
$arguments['style'] = 'width: ' . intval($arguments['width']) . 'px;'; $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 = [ $data = [
'Arguments' => $arguments, 'Arguments' => $arguments,
'Attributes' => static::buildAttributeListFromArguments($arguments, ['width', 'height', 'url', 'caption']), 'Attributes' => static::buildAttributeListFromArguments($arguments, ['width', 'height', 'url', 'caption']),

View File

@ -129,4 +129,39 @@ class GroupedDropdownFieldTest extends SapphireTest
preg_replace('/\s+/', ' ', (string)$field->Field()) preg_replace('/\s+/', ' ', (string)$field->Field())
); );
} }
/**
* Test that readonly version of GroupedDropdownField displays all values
*/
public function testReadonlyValue()
{
$field = GroupedDropdownField::create(
'Test',
'Testing',
[
"1" => "One",
"Group One" => [
"2" => "Two",
"3" => "Three"
],
"Group Two" => [
"4" => "Four"
],
]
);
// value on first level
$field->setValue("1");
$this->assertRegExp(
'/<span class="readonly" id="Test">One<\/span><input type="hidden" name="Test" value="1" \/>/',
(string)$field->performReadonlyTransformation()->Field()
);
// value on first level
$field->setValue("2");
$this->assertRegExp(
'/<span class="readonly" id="Test">Two<\/span><input type="hidden" name="Test" value="2" \/>/',
(string)$field->performReadonlyTransformation()->Field()
);
}
} }

View File

@ -37,8 +37,8 @@ class EmbedShortcodeProviderTest extends SapphireTest
[ [
'url' => static::$test_youtube, 'url' => static::$test_youtube,
'caption' => 'A nice video', 'caption' => 'A nice video',
'width' => 480, 'width' => 777,
'height' => 360, 'height' => 437,
], ],
[ [
'version' => '1.0', 'version' => '1.0',
@ -58,7 +58,7 @@ class EmbedShortcodeProviderTest extends SapphireTest
); );
$this->assertEqualIgnoringWhitespace( $this->assertEqualIgnoringWhitespace(
<<<EOS <<<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> <p class="caption">A nice video</p></div>
EOS EOS
, ,