From 770ea6324d3d0445c25e4f20caa511f824ef8780 Mon Sep 17 00:00:00 2001 From: Hugh Messenger Date: Wed, 6 Dec 2023 12:49:31 -0600 Subject: [PATCH] Added aria-label to iframe for all services (#21) * Added aria-label to iframe for all services * Put back missing allowfullscreen --- .../views/services/dailymotion.blade.php | 13 +++---- resources/views/services/googlemaps.blade.php | 11 +++--- resources/views/services/miro.blade.php | 8 ++++- resources/views/services/slideshare.blade.php | 8 ++++- resources/views/services/vimeo.blade.php | 8 ++++- resources/views/services/youtube.blade.php | 13 +++---- src/ServiceBase.php | 36 +++++++++++++++---- src/ServiceContract.php | 1 + src/ViewComponents/EmbedViewComponent.php | 5 ++- tests/ServiceBaseTest.php | 6 ++++ tests/Services/DailymotionTest.php | 1 + tests/Services/GoogleMapsTest.php | 1 + tests/Services/MiroTest.php | 1 + tests/Services/SlideshareTest.php | 1 + tests/Services/VimeoTest.php | 1 + tests/Services/YouTubeTest.php | 1 + 16 files changed, 87 insertions(+), 28 deletions(-) diff --git a/resources/views/services/dailymotion.blade.php b/resources/views/services/dailymotion.blade.php index 6cb57b3..5ceee19 100644 --- a/resources/views/services/dailymotion.blade.php +++ b/resources/views/services/dailymotion.blade.php @@ -1,8 +1,9 @@ - + diff --git a/resources/views/services/googlemaps.blade.php b/resources/views/services/googlemaps.blade.php index eb572d0..a7e4b9d 100644 --- a/resources/views/services/googlemaps.blade.php +++ b/resources/views/services/googlemaps.blade.php @@ -1,9 +1,10 @@ diff --git a/resources/views/services/miro.blade.php b/resources/views/services/miro.blade.php index 9e5627a..643b611 100644 --- a/resources/views/services/miro.blade.php +++ b/resources/views/services/miro.blade.php @@ -1,3 +1,9 @@ - + diff --git a/resources/views/services/slideshare.blade.php b/resources/views/services/slideshare.blade.php index 9e5627a..eb02097 100644 --- a/resources/views/services/slideshare.blade.php +++ b/resources/views/services/slideshare.blade.php @@ -1,3 +1,9 @@ - + diff --git a/resources/views/services/vimeo.blade.php b/resources/views/services/vimeo.blade.php index 20c6a53..d100124 100644 --- a/resources/views/services/vimeo.blade.php +++ b/resources/views/services/vimeo.blade.php @@ -1,3 +1,9 @@ - + diff --git a/resources/views/services/youtube.blade.php b/resources/views/services/youtube.blade.php index c2f3e83..d40428d 100644 --- a/resources/views/services/youtube.blade.php +++ b/resources/views/services/youtube.blade.php @@ -1,8 +1,9 @@ - + diff --git a/src/ServiceBase.php b/src/ServiceBase.php index 2ea9a94..747700b 100644 --- a/src/ServiceBase.php +++ b/src/ServiceBase.php @@ -2,17 +2,20 @@ namespace BenSampo\Embed; -use Illuminate\Support\Str; -use Illuminate\Contracts\View\View; +use BenSampo\Embed\ValueObjects\Ratio; use BenSampo\Embed\ValueObjects\Url; +use Illuminate\Contracts\View\View; use Illuminate\Support\Facades\Cache; -use BenSampo\Embed\ValueObjects\Ratio; +use Illuminate\Support\Str; abstract class ServiceBase implements ServiceContract { protected Url $url; + protected ?Ratio $aspectRatio; + protected ?string $label; + public function __construct(Url $url) { $this->url = $url; @@ -22,15 +25,16 @@ abstract public static function detect(Url $url): bool; public function cacheAndRender(): string { - return Cache::rememberForever($this->cacheKey(), function() { + return Cache::rememberForever($this->cacheKey(), function () { return $this->view()->render(); }); } - + public function view(): View { return view($this->fullyQualifiedViewName(), array_merge($this->viewData(), [ 'aspectRatio' => $this->aspectRatio(), + 'label' => $this->label(), ])); } @@ -41,6 +45,13 @@ public function setAspectRatio(?Ratio $aspectRatio): ServiceContract return $this; } + public function setLabel(?string $label): ServiceContract + { + $this->label = $label ?? $this->defaultLabel(); + + return $this; + } + protected function viewName(): string { return $this->guessViewName(); @@ -51,11 +62,21 @@ protected function aspectRatio(): Ratio return $this->aspectRatio ?? $this->defaultAspectRatio(); } + protected function label(): string + { + return $this->label ?? $this->defaultLabel(); + } + protected function defaultAspectRatio(): Ratio { return new Ratio('16:9'); } + protected function defaultLabel(): string + { + return __('An embedded video'); + } + private function fullyQualifiedViewName(): string { return 'embed::services.' . $this->viewName(); @@ -74,9 +95,10 @@ protected function guessViewName(): string protected function cacheKey(): string { $serviceName = class_basename(static::class); - $url = (string) $this->url; + $url = (string) $this->url; + $label = $this->label(); $aspectRatio = $this->aspectRatio()->width . ':' . $this->aspectRatio()->height; - return $serviceName . '_' . $url . '_' . $aspectRatio; + return $serviceName . '_' . $url . '_' . $aspectRatio . '_' . $label; } } diff --git a/src/ServiceContract.php b/src/ServiceContract.php index 39cbb95..cc5240e 100644 --- a/src/ServiceContract.php +++ b/src/ServiceContract.php @@ -12,4 +12,5 @@ public static function detect(Url $url): bool; public function view(): View; public function cacheAndRender(): string; public function setAspectRatio(?Ratio $aspectRatio): ServiceContract; + public function setLabel(?string $label): ServiceContract; } \ No newline at end of file diff --git a/src/ViewComponents/EmbedViewComponent.php b/src/ViewComponents/EmbedViewComponent.php index 2448663..de31fff 100644 --- a/src/ViewComponents/EmbedViewComponent.php +++ b/src/ViewComponents/EmbedViewComponent.php @@ -14,11 +14,13 @@ class EmbedViewComponent extends Component protected ServiceContract $service; protected Url $url; protected ?Ratio $aspectRatio; + protected ?string $label; - public function __construct(string $url, string $aspectRatio = null) + public function __construct(string $url, string $aspectRatio = null, string $label = null) { $this->url = new Url($url); $this->aspectRatio = $aspectRatio ? new Ratio($aspectRatio) : null; + $this->label = $label; } public function render(): string @@ -31,6 +33,7 @@ public function render(): string return $this->service ->setAspectRatio($this->aspectRatio) + ->setLabel($this->label) ->cacheAndRender(); } } diff --git a/tests/ServiceBaseTest.php b/tests/ServiceBaseTest.php index 21b76f9..a114dcb 100644 --- a/tests/ServiceBaseTest.php +++ b/tests/ServiceBaseTest.php @@ -44,4 +44,10 @@ public function test_it_can_set_the_aspect_ratio() $ratio = new Ratio('4:3'); $this->assertEquals($ratio, $this->dummyService1->setAspectRatio($ratio)->view()->getData()['aspectRatio']); } + + public function test_it_can_set_a_label() + { + $label = 'A different aria label'; + $this->assertEquals($label, $this->dummyService1->setLabel($label)->view()->getData()['label']); + } } diff --git a/tests/Services/DailymotionTest.php b/tests/Services/DailymotionTest.php index 8f2cab1..ffc96da 100644 --- a/tests/Services/DailymotionTest.php +++ b/tests/Services/DailymotionTest.php @@ -21,6 +21,7 @@ protected function expectedViewData(): array { return [ 'videoId' => 'xg4y8d', + 'label' => 'An embedded video', ]; } diff --git a/tests/Services/GoogleMapsTest.php b/tests/Services/GoogleMapsTest.php index a3677b6..fbf6a31 100644 --- a/tests/Services/GoogleMapsTest.php +++ b/tests/Services/GoogleMapsTest.php @@ -21,6 +21,7 @@ protected function expectedViewData(): array { return [ 'iframeUrl' => 'https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d2483.6803818653148!2d-0.12720032263547887!3d51.50073251118933!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x487604c38c8cd1d9%3A0xb78f2474b9a45aa9!2sBig%20Ben!5e0!3m2!1sen!2suk!4v1683805199103!5m2!1sen!2suk', + 'label' => 'An embedded video', ]; } diff --git a/tests/Services/MiroTest.php b/tests/Services/MiroTest.php index cebd26f..e83fa0a 100644 --- a/tests/Services/MiroTest.php +++ b/tests/Services/MiroTest.php @@ -38,6 +38,7 @@ protected function expectedViewData(): array { return [ 'iframeUrl' => 'https://miro.com/app/embed/o9J_kquX_s8=/?autoplay=yep', + 'label' => 'An embedded video', ]; } diff --git a/tests/Services/SlideshareTest.php b/tests/Services/SlideshareTest.php index f1f8299..e2b54a4 100644 --- a/tests/Services/SlideshareTest.php +++ b/tests/Services/SlideshareTest.php @@ -21,6 +21,7 @@ protected function expectedViewData(): array { return [ 'iframeUrl' => 'https://www.slideshare.net/slideshow/embed_code/key/6PCWPGFw9SwsAY', + 'label' => 'An embedded video', ]; } diff --git a/tests/Services/VimeoTest.php b/tests/Services/VimeoTest.php index 08d164a..35c4b91 100644 --- a/tests/Services/VimeoTest.php +++ b/tests/Services/VimeoTest.php @@ -21,6 +21,7 @@ protected function expectedViewData(): array { return [ 'videoId' => '148751763', + 'label' => 'An embedded video', ]; } diff --git a/tests/Services/YouTubeTest.php b/tests/Services/YouTubeTest.php index 262b880..45855d8 100644 --- a/tests/Services/YouTubeTest.php +++ b/tests/Services/YouTubeTest.php @@ -21,6 +21,7 @@ protected function expectedViewData(): array { return [ 'videoId' => 'dQw4w9WgXcQ', + 'label' => 'An embedded video', ]; }