From df55aa8b9c01082aa03f194d3fa537f05fc62102 Mon Sep 17 00:00:00 2001
From: larowlan <larowlan@395439.no-reply.drupal.org>
Date: Thu, 22 Jul 2021 10:50:07 +1000
Subject: [PATCH] Issue #2159495 by acbramley, larowlan, carsonblack, Sam152:
 Add option to set scrolling = no

---
 config/schema/link_iframe_formatter.schema.yml        |  3 +++
 link_iframe_formatter.module                          | 10 +++++++++-
 .../Field/FieldFormatter/LinkIframeFormatter.php      | 11 ++++++++++-
 templates/link-iframe-formatter.html.twig             |  2 +-
 tests/src/Functional/LinkIframeFormatterTest.php      |  3 +++
 5 files changed, 26 insertions(+), 3 deletions(-)

diff --git a/config/schema/link_iframe_formatter.schema.yml b/config/schema/link_iframe_formatter.schema.yml
index 3f17cd0..b13f3f4 100644
--- a/config/schema/link_iframe_formatter.schema.yml
+++ b/config/schema/link_iframe_formatter.schema.yml
@@ -14,3 +14,6 @@ field.formatter.settings.link_iframe_formatter:
     original:
       type: boolean
       label: 'Show original link'
+    disable_scrolling:
+      type: string
+      label: 'Disable scrolling'
diff --git a/link_iframe_formatter.module b/link_iframe_formatter.module
index 4f4fcdf..c44a706 100644
--- a/link_iframe_formatter.module
+++ b/link_iframe_formatter.module
@@ -11,7 +11,15 @@
 function link_iframe_formatter_theme() {
   return [
     'link_iframe_formatter' => [
-      'variables' => ['url' => NULL, 'width' => NULL, 'height' => NULL, 'class' => NULL, 'original' => NULL, 'path' => NULL],
+      'variables' => [
+        'url' => NULL,
+        'width' => NULL,
+        'height' => NULL,
+        'class' => NULL,
+        'original' => NULL,
+        'path' => NULL,
+        'scrolling' => 'yes',
+      ],
       'template' => 'link-iframe-formatter',
     ],
   ];
diff --git a/src/Plugin/Field/FieldFormatter/LinkIframeFormatter.php b/src/Plugin/Field/FieldFormatter/LinkIframeFormatter.php
index c85c375..e889216 100644
--- a/src/Plugin/Field/FieldFormatter/LinkIframeFormatter.php
+++ b/src/Plugin/Field/FieldFormatter/LinkIframeFormatter.php
@@ -28,6 +28,7 @@ class LinkIframeFormatter extends LinkFormatter {
       'height' => 480,
       'class' => '',
       'original' => FALSE,
+      'disable_scrolling' => FALSE,
     ];
   }
 
@@ -50,6 +51,12 @@ class LinkIframeFormatter extends LinkFormatter {
       '#required' => TRUE,
     ];
 
+    $elements['disable_scrolling'] = [
+      '#title' => t('Disable Scrolling'),
+      '#type' => 'checkbox',
+      '#default_value' => $this->getSetting('disable_scrolling'),
+    ];
+
     $elements['class'] = [
       '#title' => $this->t('Class'),
       '#type' => 'textfield',
@@ -75,9 +82,10 @@ class LinkIframeFormatter extends LinkFormatter {
    */
   public function settingsSummary() {
     $summary = [];
-    $summary[] = $this->t('Width: @width, Height: @height, Class: @class, Original link is @original', [
+    $summary[] = $this->t('Width: @width, Height: @height, Scrolling: @scrolling, Class: @class, Original link is @original', [
       '@width' => $this->getSetting('width'),
       '@height' => $this->getSetting('height'),
+      '@scrolling' => $this->getSetting('disable_scrolling') ? 'no' : 'yes',
       '@class' => $this->getSetting('class') == "" ? 'None' : $this->getSetting('class'),
       '@original' => $this->getSetting('original') ? t('On') : t('Off'),
     ]);
@@ -100,6 +108,7 @@ class LinkIframeFormatter extends LinkFormatter {
         '#url' => $url,
         '#width' => $settings['width'],
         '#height' => $settings['height'],
+        '#scrolling' => $settings['disable_scrolling'] ? 'no' : 'yes',
         '#class' => $settings['class'],
         '#original' => $settings['original'],
         '#path' => $url,
diff --git a/templates/link-iframe-formatter.html.twig b/templates/link-iframe-formatter.html.twig
index 03788d3..fd6e4a4 100644
--- a/templates/link-iframe-formatter.html.twig
+++ b/templates/link-iframe-formatter.html.twig
@@ -1,5 +1,5 @@
 {% spaceless %}
-  <iframe width="{{ width }}" height="{{ height }}" src="{{ url }}" class="{{ class }}" frameborder="0" allowfullscreen></iframe>
+  <iframe width="{{ width }}" height="{{ height }}" src="{{ url }}" class="{{ class }}" frameborder="0" scrolling="{{ scrolling }}" allowfullscreen></iframe>
   {% if original %}
     <div class="link-iframe-formatter-original">{{ 'You may view the original link at:'|t }} <a
     href="{{ url }}">{{ url }}</a><div>
diff --git a/tests/src/Functional/LinkIframeFormatterTest.php b/tests/src/Functional/LinkIframeFormatterTest.php
index 00b0011..5e796ef 100644
--- a/tests/src/Functional/LinkIframeFormatterTest.php
+++ b/tests/src/Functional/LinkIframeFormatterTest.php
@@ -10,6 +10,8 @@ use Drupal\Tests\BrowserTestBase;
 
 /**
  * Defines a class for testing link iframe formatter.
+ *
+ * @group link_iframe_formatter
  */
 class LinkIframeFormatterTest extends BrowserTestBase {
 
@@ -86,6 +88,7 @@ class LinkIframeFormatterTest extends BrowserTestBase {
     $this->assertEquals(270, $iframe->getAttribute('height'));
     $this->assertEquals(350, $iframe->getAttribute('width'));
     $this->assertEquals('some-class', $iframe->getAttribute('class'));
+    $this->assertEquals('yes', $iframe->getAttribute('scrolling'));
     $link = $this->assertSession()->elementExists('named', ['link', $url]);
     $this->assertEquals($url, $link->getAttribute('href'));
     $this->assertSession()->pageTextContains('You may view the original link at');
-- 
GitLab