-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #244 from openeuropa/EWPP-4547
EWPP-4547: Add settings form for Social share widget to allow rendering icons without labels.
- Loading branch information
Showing
9 changed files
with
192 additions
and
3 deletions.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
modules/oe_webtools_social_share/config/install/oe_webtools_social_share.settings.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 @@ | ||
icons: false |
8 changes: 8 additions & 0 deletions
8
modules/oe_webtools_social_share/config/schema/oe_webtools_social_share.schema.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,8 @@ | ||
oe_webtools_social_share.settings: | ||
type: config_object | ||
label: 'Webtools Social share settings' | ||
mapping: | ||
icons: | ||
type: boolean | ||
label: 'Icons' | ||
description: 'Whether the Social share block displays only icons without labels.' |
5 changes: 5 additions & 0 deletions
5
modules/oe_webtools_social_share/oe_webtools_social_share.links.menu.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,5 @@ | ||
oe_webtools_social_share.settings: | ||
title: 'Webtools Social share' | ||
description: 'Configure Webtools Social share block.' | ||
route_name: oe_webtools_social_share.settings | ||
parent: system.admin_config_system |
3 changes: 3 additions & 0 deletions
3
modules/oe_webtools_social_share/oe_webtools_social_share.permissions.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,3 @@ | ||
administer webtools social share block: | ||
title: 'Administer Webtools Social share block' | ||
restrict access: false |
7 changes: 7 additions & 0 deletions
7
modules/oe_webtools_social_share/oe_webtools_social_share.routing.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,7 @@ | ||
oe_webtools_social_share.settings: | ||
path: '/admin/config/system/oe_webtools_social_share' | ||
defaults: | ||
_form: 'Drupal\oe_webtools_social_share\Form\SocialShareSettingsForm' | ||
_title: 'Webtools Social share settings' | ||
requirements: | ||
_permission: 'administer webtools social share block' |
55 changes: 55 additions & 0 deletions
55
modules/oe_webtools_social_share/src/Form/SocialShareSettingsForm.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,55 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Drupal\oe_webtools_social_share\Form; | ||
|
||
use Drupal\Core\Form\ConfigFormBase; | ||
use Drupal\Core\Form\FormStateInterface; | ||
|
||
/** | ||
* Provides configuration form for the Social share webtools widget. | ||
*/ | ||
class SocialShareSettingsForm extends ConfigFormBase { | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getFormId(): string { | ||
return 'oe_webtools_social_share_settings'; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function getEditableConfigNames(): array { | ||
return ['oe_webtools_social_share.settings']; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function buildForm(array $form, FormStateInterface $form_state): array { | ||
$config = $this->config('oe_webtools_social_share.settings'); | ||
|
||
$form['icons'] = [ | ||
'#type' => 'checkbox', | ||
'#title' => $this->t('Display only icons'), | ||
'#description' => $this->t('Check this box if you would like to display only the icons without labels for the Social share block.'), | ||
'#default_value' => $config->get('icons'), | ||
]; | ||
|
||
return parent::buildForm($form, $form_state); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function submitForm(array &$form, FormStateInterface $form_state): void { | ||
$this->config('oe_webtools_social_share.settings') | ||
->set('icons', $form_state->getValue('icons')) | ||
->save(); | ||
parent::submitForm($form, $form_state); | ||
} | ||
|
||
} |
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
59 changes: 59 additions & 0 deletions
59
modules/oe_webtools_social_share/tests/Functional/SocialShareSettingsFormTest.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,59 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Drupal\Tests\oe_webtools_social_share\Functional; | ||
|
||
use Drupal\Tests\BrowserTestBase; | ||
|
||
/** | ||
* Tests the Social share widget settings form. | ||
*/ | ||
class SocialShareSettingsFormTest extends BrowserTestBase { | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected static $modules = [ | ||
'node', | ||
'language', | ||
'block', | ||
'oe_webtools_social_share', | ||
]; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected $defaultTheme = 'stark'; | ||
|
||
/** | ||
* Tests Social share form configuration. | ||
*/ | ||
public function testSocialShareForm(): void { | ||
// Assert user without permissions cannot access the settings form. | ||
$this->drupalLogin($this->createUser()); | ||
$this->drupalGet('/admin/config/system/oe_webtools_social_share'); | ||
$assert = $this->assertSession(); | ||
$assert->pageTextContains('Access denied'); | ||
$assert->pageTextContains('You are not authorized to access this page.'); | ||
|
||
// Create another user with access to the form. | ||
$this->drupalLogin($this->createUser(['administer webtools social share block'])); | ||
$this->drupalGet('/admin/config/system/oe_webtools_social_share'); | ||
$assert->pageTextContainsOnce('Webtools Social share settings'); | ||
// The block renders the icons labels, by default. | ||
$assert->checkboxNotChecked('Display only icons'); | ||
$assert->pageTextContainsOnce('Check this box if you would like to display only the icons without labels for the Social share block.'); | ||
$this->assertEquals(FALSE, $this->config('oe_webtools_social_share.settings')->get('icons')); | ||
|
||
// Enable the icons option. | ||
$this->getSession()->getPage()->checkField('Display only icons'); | ||
$this->getSession()->getPage()->pressButton('Save configuration'); | ||
$this->container->get('config.factory')->reset('oe_webtools_social_share.settings'); | ||
// Assert the values are saved. | ||
$assert->pageTextContainsOnce('The configuration options have been saved.'); | ||
$assert->checkboxChecked('Display only icons'); | ||
$this->assertEquals(TRUE, $this->config('oe_webtools_social_share.settings')->get('icons')); | ||
} | ||
|
||
} |
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