-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
572 additions
and
18 deletions.
There are no files selected for viewing
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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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
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
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
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
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
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
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
68 changes: 68 additions & 0 deletions
68
docroot/themes/contrib/civictheme/src/Settings/CivicthemeSettingsFormSectionOptout.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,68 @@ | ||
<?php | ||
|
||
namespace Drupal\civictheme\Settings; | ||
|
||
use Drupal\Component\Render\FormattableMarkup; | ||
use Drupal\Core\Form\FormStateInterface; | ||
|
||
/** | ||
* CivicTheme settings section to opt-out from features. | ||
*/ | ||
class CivicthemeSettingsFormSectionOptout extends CivicthemeSettingsFormSectionBase { | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function weight() { | ||
return 35; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
* | ||
* @SuppressWarnings(PHPMD.StaticAccess) | ||
*/ | ||
public function form(&$form, FormStateInterface &$form_state) { | ||
$form['optout_details'] = [ | ||
'#type' => 'details', | ||
'#title' => $this->t('Opt-out from features'), | ||
'#open' => FALSE, | ||
'#weight' => 60, | ||
]; | ||
|
||
$form['optout_details']['optouts'] = [ | ||
'#type' => 'textarea', | ||
'#title' => $this->t('Opt-out flags'), | ||
'#rows' => 3, | ||
'#description' => $this->t('Add opt-out feature flags to disable CivicTheme features. One per line. Expand the fieldset below to get a list of available flags.'), | ||
'#element_validate' => [[self::class, 'multilineToArray']], | ||
'#default_value' => implode("\n", $this->themeConfigManager->load('optouts', [])), | ||
]; | ||
|
||
$form['optout_details']['mapping'] = [ | ||
'#type' => 'details', | ||
'#title' => $this->t('Available flags'), | ||
'#open' => FALSE, | ||
'#weight' => 60, | ||
]; | ||
|
||
$form['optout_details']['mapping']['content'] = [ | ||
'#theme' => 'item_list', | ||
'#items' => array_map(function ($key, $description) { | ||
return new FormattableMarkup('<code>@key</code>: @description', [ | ||
'@key' => $key, | ||
'@description' => $description, | ||
]); | ||
}, array_keys(_civictheme_feature_optout_flags()), _civictheme_feature_optout_flags()), | ||
]; | ||
} | ||
|
||
/** | ||
* Convert element value from multiline string to an array. | ||
*/ | ||
public static function multilineToArray(array $element, &$form_state) { | ||
$lines = is_array($element['#value']) ? $element['#value'] : explode("\n", str_replace("\r\n", "\n", $element['#value'])); | ||
$form_state->setValueForElement($element, array_values(array_filter(array_map('trim', $lines)))); | ||
} | ||
|
||
} |
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
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
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
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 |
---|---|---|
|
@@ -242,7 +242,8 @@ public function dataProviderProcessHtmlLinks() { | |
'<p>Word3 <a href="http://example2.com/path">Link</a> word4</p>' . | ||
'<p>Word5 <a href="http://example2.com" class="someclass">Link</a> word6</p>' . | ||
'<p>Word7 <a href="http://example2.com/path" class="someclass">Link</a> word8</p>' . | ||
'<p>Word9 <a href="mailto:[email protected]" class="someclass">[email protected]</a> word10</p>', | ||
'<p>Word9 <a href="mailto:[email protected]" class="someclass">[email protected]</a> word10</p>' . | ||
'<p>Word11 <a href="mailto:[email protected]" class="someclass">[email protected]</a> word12 [email protected] word13</p>', | ||
'example2.com', | ||
FALSE, | ||
FALSE, | ||
|
@@ -255,7 +256,8 @@ public function dataProviderProcessHtmlLinks() { | |
'<p>Word3 <a href="http://example2.com/path" class="ct-content-link ct-theme-light">Link</a> word4</p>' . | ||
'<p>Word5 <a href="http://example2.com" class="someclass ct-content-link ct-theme-light">Link</a> word6</p>' . | ||
'<p>Word7 <a href="http://example2.com/path" class="someclass ct-content-link ct-theme-light">Link</a> word8</p>' . | ||
'<p>Word9 <a href="mailto:[email protected]" class="someclass ct-content-link ct-theme-light">[email protected]</a> word10</p>', | ||
'<p>Word9 <a href="mailto:[email protected]" class="someclass ct-content-link ct-theme-light">[email protected]</a> word10</p>' . | ||
'<p>Word11 <a href="mailto:[email protected]" class="someclass ct-content-link ct-theme-light">[email protected]</a> word12 <a href="mailto:[email protected]" class="ct-content-link ct-theme-light">[email protected]</a> word13</p>', | ||
], | ||
|
||
// Existing classes. | ||
|
@@ -267,4 +269,63 @@ public function dataProviderProcessHtmlLinks() { | |
]; | ||
} | ||
|
||
/** | ||
* Test for _civictheme_process_html_content_links_get_email_regex(). | ||
* | ||
* @dataProvider dataProviderEmailRegex | ||
*/ | ||
public function testEmail($string, $match) { | ||
preg_match(_civictheme_process_html_content_links_get_email_regex(), $string, $matches); | ||
|
||
if ($match) { | ||
$this->assertEquals(1, count($matches)); | ||
$this->assertEquals($match, $matches[0]); | ||
} | ||
else { | ||
$this->assertEquals(0, count($matches)); | ||
} | ||
} | ||
|
||
/** | ||
* Data provider for testEmail(). | ||
* | ||
* @SuppressWarnings(PHPMD.ExcessiveMethodLength) | ||
*/ | ||
public function dataProviderEmailRegex() { | ||
return [ | ||
['[email protected]', '[email protected]'], | ||
['[email protected]', '[email protected]'], | ||
['[email protected]', '[email protected]'], | ||
['[email protected]', '[email protected]'], | ||
['[email protected]', '[email protected]'], | ||
['[email protected]', '[email protected]'], | ||
['[email protected]', '[email protected]'], | ||
['[email protected]', '[email protected]'], | ||
['[email protected]', '[email protected]'], | ||
|
||
[' [email protected]', '[email protected]'], | ||
["\t[email protected]", '[email protected]'], | ||
["\n[email protected]", '[email protected]'], | ||
|
||
['', FALSE], | ||
['[email protected]', FALSE], | ||
['[email protected]', FALSE], | ||
['[email protected]', FALSE], | ||
['[email protected]', FALSE], | ||
['[email protected]', FALSE], | ||
|
||
['[email protected]', FALSE], | ||
['[email protected]', FALSE], | ||
['[email protected]', FALSE], | ||
|
||
['[email protected].', '[email protected]'], | ||
['[email protected],', '[email protected]'], | ||
['[email protected].', '[email protected]'], | ||
['[email protected].', '[email protected]'], | ||
['[email protected].', '[email protected]'], | ||
|
||
['<p> [email protected].</p>', '[email protected]'], | ||
]; | ||
} | ||
|
||
} |
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,19 @@ | ||
@p0 @civictheme @civictheme_theme_settings @civictheme_theme_optout | ||
Feature: Opt-out form is available in settings. | ||
|
||
@api | ||
Scenario: Opt-out flags can be set | ||
Given I am logged in as a user with the "Site Administrator" role | ||
And I visit current theme settings page | ||
|
||
When I fill in "Opt-out flags" with: | ||
""" | ||
test.flag1 | ||
test.flag2 | ||
test.flag3 | ||
""" | ||
And I press "Save configuration" | ||
Then I should see the text "The configuration options have been saved." | ||
And the response should contain "test.flag1" | ||
And the response should contain "test.flag2" | ||
And the response should contain "test.flag3" |