diff --git a/config/schema/link_iframe_formatter.schema.yml b/config/schema/link_iframe_formatter.schema.yml index 3f17cd0f0f4203e2b772acdfdfb8af7384c47e02..b13f3f4de100484b860350b95cac9b364a5594c6 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 4f4fcdffaccd83fa471950d5931190b36dff2089..c44a7062aa66dc624ff60bd5f566bd7f945bf3d6 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 c85c3752daef08aa08fba5036686a9bf9a737719..e8892168d555401aa977ba0ba7937e7a6c06de74 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 03788d3583f17203367224b5c4f1fe779145fa26..fd6e4a4a26b1cee7506b49749655c248ec24d055 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 00b001179f41c940cdbca68955852d0b9130a019..5e796ef92573f585ee528cac3547aa6a676672de 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');