From 56f15b1c143d0c994780853e5c4fb9f3cd03de6d Mon Sep 17 00:00:00 2001 From: rdigitalg <51925115+rdigitalg@users.noreply.github.com> Date: Fri, 3 Jul 2020 04:04:54 +0300 Subject: [PATCH 1/3] FIX Try Catch for embeded media (#9424) * Try Catch for embeded media * added missing namespaces, translatable message INVALID_URL * generate tag only once * catch after closing bracket * space after comma * Update src/View/Shortcodes/EmbedShortcodeProvider.php * Linting Co-authored-by: ivan@digitalgarage.ro Co-authored-by: Steve Boyd Co-authored-by: Loz Calver --- .../Shortcodes/EmbedShortcodeProvider.php | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/View/Shortcodes/EmbedShortcodeProvider.php b/src/View/Shortcodes/EmbedShortcodeProvider.php index d3f4aebf5..ba7fabc4f 100644 --- a/src/View/Shortcodes/EmbedShortcodeProvider.php +++ b/src/View/Shortcodes/EmbedShortcodeProvider.php @@ -14,7 +14,9 @@ use SilverStripe\View\HTML; use SilverStripe\View\Parsers\ShortcodeHandler; use Embed\Adapters\Adapter; use Embed\Embed; +use Embed\Exceptions\InvalidUrlException; use SilverStripe\View\Parsers\ShortcodeParser; +use SilverStripe\Control\Director; /** * Provider for the [embed] shortcode tag used by the embedding service @@ -89,7 +91,24 @@ class EmbedShortcodeProvider implements ShortcodeHandler } // Process embed - $embed = $embed->getEmbed(); + try { + $embed = $embed->getEmbed(); + } catch (InvalidUrlException $e) { + $message = (Director::isDev()) + ? $e->getMessage() + : _t(__CLASS__ . '.INVALID_URL', 'There was a problem loading the media.'); + + $attr = [ + 'class' => 'ss-media-exception embed' + ]; + + $result = HTML::createTag( + 'div', + $attr, + HTML::createTag('p', [], $message) + ); + return $result; + } // Convert embed object into HTML if ($embed && $embed instanceof Adapter) { From 404f450ac395143eee6bedd131b1c80f5742f8bd Mon Sep 17 00:00:00 2001 From: Martin Heise Date: Thu, 16 Jul 2020 14:40:10 +0200 Subject: [PATCH 2/3] BUG Readonly version of GroupedDropdownField GroupedDropdownField was showing empty values in Readonly mode due to not correctly handling the hierarchical source array. Uses flattened source now in GroupedDropdownField->performReadonlyTransformation() --- src/Forms/GroupedDropdownField.php | 11 ++++++ tests/php/Forms/GroupedDropdownFieldTest.php | 35 ++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/src/Forms/GroupedDropdownField.php b/src/Forms/GroupedDropdownField.php index 2dfd1e974..feb758361 100644 --- a/src/Forms/GroupedDropdownField.php +++ b/src/Forms/GroupedDropdownField.php @@ -2,6 +2,7 @@ namespace SilverStripe\Forms; +use SilverStripe\ORM\ArrayLib; use SilverStripe\ORM\ArrayList; use SilverStripe\View\ArrayData; @@ -104,4 +105,14 @@ class GroupedDropdownField extends DropdownField ); return $values; } + + /** + * @return SingleLookupField + */ + public function performReadonlyTransformation() + { + $field = parent::performReadonlyTransformation(); + $field->setSource(ArrayLib::flatten($this->getSource())); + return $field; + } } diff --git a/tests/php/Forms/GroupedDropdownFieldTest.php b/tests/php/Forms/GroupedDropdownFieldTest.php index 47fb93fcc..fabb419b0 100644 --- a/tests/php/Forms/GroupedDropdownFieldTest.php +++ b/tests/php/Forms/GroupedDropdownFieldTest.php @@ -129,4 +129,39 @@ class GroupedDropdownFieldTest extends SapphireTest 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( + '/One<\/span>/', + (string)$field->performReadonlyTransformation()->Field() + ); + + // value on first level + $field->setValue("2"); + $this->assertRegExp( + '/Two<\/span>/', + (string)$field->performReadonlyTransformation()->Field() + ); + } } From f0936d4c1ec88670d20dd67f9d5ab020ee4438d9 Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Mon, 27 Jul 2020 18:04:03 +1200 Subject: [PATCH 3/3] FIX Set iframe dimension attributes specified in shortcode --- src/View/Shortcodes/EmbedShortcodeProvider.php | 11 +++++++++++ .../View/Shortcodes/EmbedShortcodeProviderTest.php | 6 +++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/View/Shortcodes/EmbedShortcodeProvider.php b/src/View/Shortcodes/EmbedShortcodeProvider.php index d3f4aebf5..720c84888 100644 --- a/src/View/Shortcodes/EmbedShortcodeProvider.php +++ b/src/View/Shortcodes/EmbedShortcodeProvider.php @@ -141,6 +141,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 = "/( +

A nice video

EOS ,