-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
OPENEUROPA-1747: Add social sharing block. #46
Merged
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e2d87dd
OPENEUROPA-1747: Add social sharing block.
imanoleguskiza ab9a6c1
OPENEUROPA-1747: Add test.
imanoleguskiza 5d1e8eb
OPENEUROPA-1474: Address QA remarks.
imanoleguskiza f8d7322
OPENUROPA-1747: Add smartloader js to block.
imanoleguskiza 2ff1bcd
OPENEUROPA-1747: Merge variables.
imanoleguskiza File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
modules/oe_webtools_social_share/oe_webtools_social_share.info.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
name: OpenEuropa Webtools Social Share | ||
description: Provide social sharing functionality for a site. | ||
package: OpenEuropa Webtools | ||
type: module | ||
version: 1.0 | ||
core: 8.x |
15 changes: 15 additions & 0 deletions
15
modules/oe_webtools_social_share/oe_webtools_social_share.module
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
/** | ||
* @file | ||
* OpenEuropa Webtools Social Share module. | ||
*/ | ||
|
||
declare(strict_types = 1); | ||
|
||
/** | ||
* Implements hook_page_attachments(). | ||
*/ | ||
function oe_webtools_social_share_attachments(array &$attachments) { | ||
$attachments['#attached']['library'][] = 'oe_webtools/drupal.webtools-smartloader'; | ||
} |
47 changes: 47 additions & 0 deletions
47
modules/oe_webtools_social_share/src/Plugin/Block/SocialShareBlock.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
declare(strict_types = 1); | ||
|
||
namespace Drupal\oe_webtools_social_share\Plugin\Block; | ||
|
||
use Drupal\Core\Block\BlockBase; | ||
|
||
/** | ||
* Provides a 'Social Share' Block. | ||
* | ||
* @Block( | ||
* id = "social_share", | ||
* admin_label = @Translation("Social Share"), | ||
* category = @Translation("Webtools"), | ||
* ) | ||
*/ | ||
class SocialShareBlock extends BlockBase { | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function build() { | ||
$social_share_json = [ | ||
'service' => 'share', | ||
'popup' => FALSE, | ||
'selection' => TRUE, | ||
'to' => [ | ||
'more', | ||
'twitter', | ||
'facebook', | ||
'linkedin', | ||
'e-mail', | ||
], | ||
'stats' => TRUE, | ||
]; | ||
return [ | ||
'script' => [ | ||
'#type' => 'html_tag', | ||
'#tag' => 'script', | ||
'#value' => json_encode($social_share_json), | ||
'#attributes' => ['type' => 'application/json'], | ||
], | ||
]; | ||
} | ||
|
||
} |
54 changes: 54 additions & 0 deletions
54
modules/oe_webtools_social_share/tests/Kernel/SocialShareBlockTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
declare(strict_types = 1); | ||
|
||
namespace Drupal\Tests\oe_webtools\Kernel; | ||
|
||
use Drupal\KernelTests\KernelTestBase; | ||
use Symfony\Component\DomCrawler\Crawler; | ||
|
||
/** | ||
* Tests the Social Share widget provided by oe_webtools. | ||
*/ | ||
class SocialShareBlockTest extends KernelTestBase { | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected static $modules = [ | ||
'system', | ||
'user', | ||
'oe_webtools_social_share', | ||
]; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function setUp() { | ||
parent::setUp(); | ||
$this->installEntitySchema('user'); | ||
$this->installSchema('system', 'sequences'); | ||
$this->installConfig(['system']); | ||
} | ||
|
||
/** | ||
* Test social share block rendering. | ||
*/ | ||
public function testSocialShareBlockRendering(): void { | ||
// Setup and render social share block. | ||
$config = [ | ||
'id' => 'social_share', | ||
'label' => 'OpenEuropa social share', | ||
'provider' => 'oe_webtools_social_share', | ||
'label_display' => '0', | ||
]; | ||
$plugin = $this->container->get('plugin.manager.block')->createInstance('social_share', $config); | ||
$render = $plugin->build(); | ||
$html = (string) $this->container->get('renderer')->renderRoot($render); | ||
$crawler = new Crawler($html); | ||
// Make sure that social share block is present. | ||
$actual = $crawler->filter('script'); | ||
$this->assertEquals('{"service":"share","popup":false,"selection":true,"to":["more","twitter","facebook","linkedin","e-mail"],"stats":true}', $actual->text()); | ||
brummbar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -24,6 +24,7 @@ drupal: | |||||
- "./vendor/bin/drush en oe_webtools oe_webtools_laco_service -y" | ||||||
- "./vendor/bin/drush en oe_webtools oe_webtools_laco_widget -y" | ||||||
- "./vendor/bin/drush en oe_webtools oe_webtools_cookie_consent -y" | ||||||
- "./vendor/bin/drush en oe_webtools oe_webtools_social_share -y" | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
It should be fixed in all lines except the first 😄 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indeed. Let's put all our modules in one line |
||||||
- "./vendor/bin/drush en language -y" | ||||||
- "./vendor/bin/drush cr" | ||||||
settings: | ||||||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's move this to the block render array itself, so that it is included only when the block is rendered.