Skip to content

Commit

Permalink
Merge branch 'release/1.7.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexSkrypnyk committed Apr 14, 2024
2 parents 6784176 + 6e1eb64 commit c4ed948
Show file tree
Hide file tree
Showing 16 changed files with 138 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ Feature: Promo fields
And should see an "[name='field_c_n_components[0][subform][field_c_p_vertical_spacing]']" element
And should see an "[name='field_c_n_components[0][subform][field_c_p_vertical_spacing]'].required" element
And should not see an "[name='field_c_n_components[0][subform][field_c_p_vertical_spacing]'][disabled]" element

And I should see an "[name='field_c_n_components[0][subform][field_c_p_background][value]']" element
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Feature: Promo render
| [TEST] Page Promo test 2 | 1 |

@api
Scenario: CivicTheme page content type page can be viewed by anonymous with Promo light with vertical spacing
Scenario: CivicTheme page content type page can be viewed by anonymous with Promo light with vertical spacing without background
Given I am an anonymous user
And "field_c_n_components" in "civictheme_page" "node" with "title" of "[TEST] Page Promo test 1" has "civictheme_promo" paragraph:
| field_c_p_title | [TEST] Promo title |
Expand All @@ -22,6 +22,7 @@ Feature: Promo render
And I should see an ".ct-promo" element
And I should see an ".ct-promo.ct-theme-light" element
And I should see an ".ct-promo.ct-vertical-spacing--both" element
And I should not see an ".ct-promo--with-background" element
And I should see the text "[TEST] Promo title"
And I should see the text "[TEST] Content text"
And I should see an ".ct-promo__title" element
Expand All @@ -30,21 +31,23 @@ Feature: Promo render
And the response should contain "https://example.com/link1"

@api
Scenario: CivicTheme page content type page can be viewed by anonymous with promo dark without vertical space
Scenario: CivicTheme page content type page can be viewed by anonymous with promo dark without vertical space with background
Given I am an anonymous user
And "field_c_n_components" in "civictheme_page" "node" with "title" of "[TEST] Page Promo test 2" has "civictheme_promo" paragraph:
| field_c_p_title | [TEST] Promo title |
| field_c_p_theme | dark |
| field_c_p_content:value | [TEST] Content text |
| field_c_p_content:format | civictheme_rich_text |
| field_c_p_vertical_spacing | 0 |
| field_c_p_background | 1 |
| field_c_p_link | 0: [TEST] link 2 - 1: https://example.com/link2 |

When I visit "civictheme_page" "[TEST] Page Promo test 2"
And I should see an ".ct-promo" element
And I should not see an ".ct-promo.ct-theme-light" element
And I should see an ".ct-promo.ct-theme-dark" element
And I should not see an ".ct-promo.ct-vertical-spacing--both" element
And I should see an ".ct-promo--with-background" element
And I should see the text "[TEST] Promo title"
And I should see the text "[TEST] Content text"
And I should see an ".ct-promo__title" element
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,21 @@ function _cs_generated_content_create_node_civictheme_page__variations__componen
'theme' => $helper::civicthemeThemeDark(),
],

[
'type' => 'promo',
'title' => 'Light, BG, ' . $helper::staticSentence(3),
'link' => $helper::staticLinkFieldValue(),
'theme' => $helper::civicthemeThemeLight(),
'background' => TRUE,
],
[
'type' => 'promo',
'title' => 'Dark, BG, ' . $helper::staticSentence(3),
'link' => $helper::staticLinkFieldValue(),
'theme' => $helper::civicthemeThemeDark(),
'background' => TRUE,
],

[
'type' => 'promo',
'title' => 'Light, Content, Vertical spacing, ' . $helper::staticSentence(3),
Expand Down
1 change: 1 addition & 0 deletions web/themes/contrib/civictheme/civictheme.info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@ config_devel:
- field.field.paragraph.civictheme_next_step.field_c_p_theme
- field.field.paragraph.civictheme_next_step.field_c_p_title
- field.field.paragraph.civictheme_next_step.field_c_p_vertical_spacing
- field.field.paragraph.civictheme_promo.field_c_p_background
- field.field.paragraph.civictheme_promo.field_c_p_content
- field.field.paragraph.civictheme_promo.field_c_p_link
- field.field.paragraph.civictheme_promo.field_c_p_theme
Expand Down
46 changes: 46 additions & 0 deletions web/themes/contrib/civictheme/civictheme.post_update.php
Original file line number Diff line number Diff line change
Expand Up @@ -532,3 +532,49 @@ static function (CivicthemeUpdateHelper $helper) use ($old_field_configs): Trans
},
);
}

/**
* Add Background field to Promo Component.
*/
function civictheme_post_update_add_background_promo_component(array &$sandbox): ?string {
$new_field_configs = [
'field.field.paragraph.civictheme_promo.field_c_p_background' => 'field_config',
];

$new_form_display_config = [
'civictheme_promo' => [
'field_c_p_background' => [
'type' => 'boolean_checkbox',
'weight' => 6,
'region' => 'content',
'settings' => [
'display_label' => TRUE,
],
'third_party_settings' => [],
],
],
];

return \Drupal::classResolver(CivicthemeUpdateHelper::class)->update(
$sandbox,
'paragraph',
['civictheme_promo'],
// Start callback.
static function (CivicthemeUpdateHelper $helper) use ($new_field_configs): void {
$config_path = \Drupal::service('extension.list.theme')->getPath('civictheme') . '/config/install';
$helper->createConfigs($new_field_configs, $config_path);
},
// Process callback.
static function (CivicthemeUpdateHelper $helper): void {
// Noop.
},
// Finished callback.
static function (CivicthemeUpdateHelper $helper) use ($new_form_display_config): TranslatableMarkup {
foreach ($new_form_display_config as $bundle => $config) {
$helper->updateFormDisplayConfig('paragraph', $bundle, $config);
}

return new TranslatableMarkup("Added Background field to Promo Component.\n");
}
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ langcode: en
status: true
dependencies:
config:
- field.field.paragraph.civictheme_promo.field_c_p_background
- field.field.paragraph.civictheme_promo.field_c_p_content
- field.field.paragraph.civictheme_promo.field_c_p_link
- field.field.paragraph.civictheme_promo.field_c_p_theme
Expand All @@ -16,6 +17,13 @@ targetEntityType: paragraph
bundle: civictheme_promo
mode: default
content:
field_c_p_background:
type: boolean_checkbox
weight: 6
region: content
settings:
display_label: true
third_party_settings: { }
field_c_p_content:
type: text_textarea
weight: 2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ langcode: en
status: true
dependencies:
config:
- field.field.paragraph.civictheme_promo.field_c_p_background
- field.field.paragraph.civictheme_promo.field_c_p_content
- field.field.paragraph.civictheme_promo.field_c_p_link
- field.field.paragraph.civictheme_promo.field_c_p_theme
Expand All @@ -17,6 +18,16 @@ targetEntityType: paragraph
bundle: civictheme_promo
mode: default
content:
field_c_p_background:
type: boolean
label: above
settings:
format: default
format_custom_false: ''
format_custom_true: ''
third_party_settings: { }
weight: 5
region: content
field_c_p_content:
type: text_default
label: above
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
langcode: en
status: true
dependencies:
config:
- field.storage.paragraph.field_c_p_background
- paragraphs.paragraphs_type.civictheme_promo
id: paragraph.civictheme_promo.field_c_p_background
field_name: field_c_p_background
entity_type: paragraph
bundle: civictheme_promo
label: Background
description: 'Apply a themed background color and provide horizontal spacing to the component'
required: false
translatable: false
default_value:
-
value: 0
default_value_callback: ''
settings:
on_label: 'On'
off_label: 'Off'
field_type: boolean
1 change: 1 addition & 0 deletions web/themes/contrib/civictheme/includes/promo.inc
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ function civictheme_preprocess_paragraph__civictheme_promo(array &$variables): v
_civictheme_preprocess_paragraph__paragraph_field__link($variables);
_civictheme_preprocess_paragraph__paragraph_field__theme($variables);
_civictheme_preprocess_paragraph__paragraph_field__vertical_spacing($variables);
_civictheme_preprocess_paragraph__paragraph_field__background($variables);
}
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ protected function saveMatrixToConfig(): static {
* @SuppressWarnings(MissingImport)
*/
protected static function validateMatrixStructure(array $matrix): void {
if (!is_array($matrix) || count($matrix) != 2) {
if (count($matrix) != 2) {
throw new \Exception(sprintf('Invalid color matrix structure: should be an array with exactly 2 elements keyed by "%s" and "%s"', self::COLOR_TYPE_BRAND, self::COLOR_TYPE_PALETTE));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Drupal\civictheme;

use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\Core\File\FileSystem;
use Drupal\Core\File\FileSystemInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

Expand Down Expand Up @@ -34,10 +33,10 @@ final class CivicthemeStylesheetGenerator implements ContainerInjectionInterface
/**
* Constructor.
*
* @param \Drupal\Core\File\FileSystem $fileSystem
* @param \Drupal\Core\File\FileSystemInterface $fileSystem
* File system discovery service.
*/
public function __construct(protected FileSystem $fileSystem) {
public function __construct(protected FileSystemInterface $fileSystem) {
$this->setStylesheetUriSuffix('default');
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public static function keywordToHex($value) {
* The origin color.
* @param string|array $mixer
* The color to mix with.
* @param int $range
* @param string|int $range
* Range to apply the mixer color with. From 0 to 100.
*
* @return string
Expand All @@ -66,7 +66,13 @@ public static function keywordToHex($value) {
*
* @SuppressWarnings(MissingImport)
*/
public static function mix(string|array $color, string|array $mixer, int $range): string {
public static function mix(string|array $color, string|array $mixer, string|int $range): string {
if (!is_numeric($range)) {
throw new \Exception(sprintf('Numeric value is expected for range, but %s provided.', $range));
}

$range = (int) $range;

$color = static::hexToRgb($color);
$mixer = static::hexToRgb($mixer);
$range = max(0, min($range, 100));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use Drupal\Core\Config\ConfigManager;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\Core\Extension\ThemeExtensionList;
use Drupal\Core\File\FileSystem;
use Drupal\Core\File\FileSystemInterface;
use Drupal\Core\File\FileUrlGenerator;
use Drupal\Core\Form\FormStateInterface;
Expand Down Expand Up @@ -38,7 +37,7 @@ abstract class CivicthemeSettingsFormSectionBase implements ContainerInjectionIn
* Theme manager service.
* @param \Drupal\Core\Extension\ThemeExtensionList $themeExtensionList
* Theme extension list service.
* @param \Drupal\Core\File\FileSystem $fileSystem
* @param \Drupal\Core\File\FileSystemInterface $fileSystem
* File system service.
* @param \Drupal\Core\File\FileUrlGenerator $fileUrlgenerator
* File URL generator.
Expand All @@ -51,7 +50,7 @@ abstract class CivicthemeSettingsFormSectionBase implements ContainerInjectionIn
* @param \Drupal\Core\Image\ImageFactory $imageFactory
* The image factory.
*/
public function __construct(protected ThemeManager $themeManager, protected ThemeExtensionList $themeExtensionList, protected FileSystem $fileSystem, protected FileUrlGenerator $fileUrlgenerator, protected Messenger $messenger, protected ConfigManager $configManager, protected CivicthemeConfigManager $themeConfigManager, protected ImageFactory $imageFactory) {
public function __construct(protected ThemeManager $themeManager, protected ThemeExtensionList $themeExtensionList, protected FileSystemInterface $fileSystem, protected FileUrlGenerator $fileUrlgenerator, protected Messenger $messenger, protected ConfigManager $configManager, protected CivicthemeConfigManager $themeConfigManager, protected ImageFactory $imageFactory) {
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ public function testUpdates(): void {
$this->assertSession()->pageTextContains('Processed: 0');
$this->assertSession()->pageTextContains('Processed: 0');
$this->assertSession()->pageTextContains('Updated: 0');

$this->assertSession()->pageTextContains('Update add_background_promo_component');
$this->assertSession()->pageTextContains("Added Background field to Promo Component.");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ public function testUpdates(): void {
$this->assertSession()->pageTextContains('Processed: 93');
$this->assertSession()->pageTextContains('Updated: 2');
$this->assertSession()->pageTextContains('Skipped: 91');

$this->assertSession()->pageTextContains('Update add_background_promo_component');
$this->assertSession()->pageTextContains("Added Background field to Promo Component.");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,12 @@ public function dataProviderNormalizeHex(): array {
* @dataProvider dataProviderMix
* @SuppressWarnings(PHPMD.StaticAccess)
*/
public function testMix(string $color, string $mixer, int $range, string $expected): void {
public function testMix(string $color, string $mixer, string|int $range, string $expected, string|null $expected_exception_message = NULL): void {
if ($expected_exception_message) {
$this->expectException(\Exception::class);
$this->expectExceptionMessage($expected_exception_message);
}

$actual = CivicthemeColorUtility::mix($color, $mixer, $range);
$this->assertEquals($expected, $actual);
}
Expand All @@ -59,6 +64,8 @@ public function dataProviderMix(): array {
['#00698f', '#000', 10, '#005e80'],
['#00698f', '#000', 0, '#00698f'],
['#e6e9eb', '#fff', 80, '#fafafb'],
['#e6e9eb', '#fff', '80', '#fafafb'],
['#00698f', '#000', 'alpha', '#005e80', 'Numeric value is expected for range, but alpha provided.'],
];
}

Expand Down

0 comments on commit c4ed948

Please sign in to comment.