Skip to content

Commit be4b5a4

Browse files
committed
Merge branch 'release/1.8.1'
2 parents 2e3c62e + 29575b7 commit be4b5a4

File tree

10 files changed

+318
-94
lines changed

10 files changed

+318
-94
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
> For support, see [Getting help](https://docs.civictheme.io/getting-help) documentation
2929
3030
> [!IMPORTANT]
31-
> For Drupal theme installation instructions into your site, see https://docs.civictheme.io/development/drupal-theme
31+
> For Drupal theme installation instructions, see https://docs.civictheme.io/development/drupal-theme
3232
3333
## Monorepo documentation
3434

tests/behat/features/paragraph.civictheme_automated_list.render.feature

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -238,9 +238,11 @@ Feature: Automated list render
238238
@api @testmode
239239
Scenario: Automated list, different view from listing type field
240240
Given "civictheme_page" content:
241-
| title | created | status | moderation_state |
242-
| [TEST] Page 16 | [relative:-5 days] | 1 | published |
243-
| [TEST] Page 17 | [relative:-5 days] | 1 | published |
241+
| title | created | status | moderation_state | field_c_n_vertical_spacing |
242+
| [TEST] Page 16 | [relative:-5 days] | 1 | published | both |
243+
| [TEST] Page 17 | [relative:-5 days] | 1 | published | both |
244+
| [TEST] Page 18 | [relative:-5 days] | 1 | published | top |
245+
| [TEST] Page 19 | [relative:-5 days] | 1 | published | top |
244246

245247
And "field_c_n_components" in "civictheme_page" "node" with "title" of "Test page with Automated list content" has "civictheme_automated_list" paragraph:
246248
| field_c_p_title | [TEST] Automated list title |
@@ -260,7 +262,9 @@ Feature: Automated list render
260262
And I should see an ".ct-list__filters" element
261263

262264
# Add a Test view as a list type.
263-
# This view only shows items older than 2 days and has a Title filter exposed.
265+
# This view only shows items older than 2 days, having a 'top' vertical
266+
# spacing (to assert the adjustems via preprocess hook) and has a Title
267+
# filter exposed.
264268
When I am logged in as a user with the "Administrator" role
265269
And I go to "admin/structure/paragraphs_type/civictheme_automated_list/fields/paragraph.civictheme_automated_list.field_c_p_list_type"
266270
And I fill in the following:
@@ -277,7 +281,8 @@ Feature: Automated list render
277281
And I press "Save"
278282

279283
And I should see 2 ".ct-promo-card" elements
280-
And I should see 2 ".ct-promo-card.ct-theme-light" elements
284+
# Preprocess hook overrides the 'item_theme' to be 'dark'.
285+
And I should see 2 ".ct-promo-card.ct-theme-dark" elements
281286
And I should not see an ".ct-list__pagination" element
282287

283288
And I should see an ".ct-list__filters" element

tests/phpunit/CivicthemeCreateSubthemeScriptUnitTest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ public function testLocation(string $civictheme_dir, string $newtheme_rel_dir, s
130130
$this->assertFileExists($expected_new_theme_dir_full . '.stylelintrc.json');
131131
$this->assertFileExists($expected_new_theme_dir_full . $newtheme_name . '.info.yml');
132132
$this->assertFileExists($expected_new_theme_dir_full . $newtheme_name . '.libraries.yml');
133-
$this->assertFileExists($expected_new_theme_dir_full . $newtheme_name . '.theme');
134133
$this->assertFileExists($expected_new_theme_dir_full . 'gulpfile.js');
135134
$this->assertFileExists($expected_new_theme_dir_full . 'composer.json');
136135
$this->assertFileExists($expected_new_theme_dir_full . 'package.json');
@@ -246,7 +245,6 @@ public function testExamplesRemoval(): void {
246245
$this->assertFileExists($expected_new_theme_dir_full . '.stylelintrc.json');
247246
$this->assertFileExists($expected_new_theme_dir_full . $newtheme_name . '.info.yml');
248247
$this->assertFileExists($expected_new_theme_dir_full . $newtheme_name . '.libraries.yml');
249-
$this->assertFileExists($expected_new_theme_dir_full . $newtheme_name . '.theme');
250248
$this->assertFileExists($expected_new_theme_dir_full . 'gulpfile.js');
251249
$this->assertFileExists($expected_new_theme_dir_full . 'package.json');
252250
$this->assertFileExists($expected_new_theme_dir_full . 'README.md');

web/modules/custom/civictheme_dev/civictheme_dev.module

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77

88
declare(strict_types=1);
99

10+
use Drupal\civictheme\CivicthemeConstants;
1011
use Drupal\civictheme\CivicthemeVersionManager;
1112
use Drupal\Core\Site\Settings;
13+
use Drupal\views\ViewExecutable;
1214

1315
require_once __DIR__ . '/styleguide.inc';
1416

@@ -48,3 +50,44 @@ function civictheme_dev_styleguide_alter(array &$items): void {
4850
_civictheme_dev_styleguide__form_test__checkboxes($items);
4951
_civictheme_dev_styleguide__form_test__radios($items);
5052
}
53+
54+
/**
55+
* Implements hook_civictheme_automated_list_view_info_alter().
56+
*/
57+
function civictheme_dev_civictheme_automated_list_view_info_alter(array &$info, array $settings): void {
58+
if ($settings['content_type'] == 'civictheme_event') {
59+
// Use a different view and display for 'civictheme_event' content type.
60+
$info['view_name'] = 'civictheme_automated_list_examples';
61+
$info['display_name'] = 'page_multiple_filters';
62+
}
63+
}
64+
65+
/**
66+
* Implements hook_civictheme_automated_list_view_alter().
67+
*/
68+
function civictheme_dev_civictheme_automated_list_view_alter(ViewExecutable $view): void {
69+
if ($view->id() === 'civictheme_automated_list_test') {
70+
if (!property_exists($view, 'component_settings') || $view->component_settings === NULL) {
71+
return;
72+
}
73+
74+
$view->component_settings['theme'] = CivicthemeConstants::THEME_LIGHT;
75+
$view->component_settings['item_theme'] = CivicthemeConstants::THEME_DARK;
76+
77+
// Example of setting view arguments based on the expected contextual
78+
// filters of this specific view.
79+
$view_args = [];
80+
// First view argument - content types.
81+
$view_args[] = $view->component_settings['content_type'] ?? 'all';
82+
// Second view argument - Topics.
83+
$view_args[] = empty($view->component_settings['topics']) ? 'all' : implode('+', array_keys($view->component_settings['topics']));
84+
// Third view argument - Site Sections.
85+
$view_args[] = empty($view->component_settings['site_sections']) ? 'all' : implode('+', array_keys($view->component_settings['site_sections']));
86+
// Fourth view argument - Content ID value.
87+
$view_args[] = 'all';
88+
// Fifth view argument - Vertical Spacing value (used as an example).
89+
$view_args[] = CivicthemeConstants::VERTICAL_SPACING_TOP;
90+
91+
$view->setArguments($view_args);
92+
}
93+
}

web/modules/custom/civictheme_dev/config/install/views.view.civictheme_automated_list_test.yml

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ dependencies:
77
- taxonomy.vocabulary.civictheme_topics
88
module:
99
- node
10+
- options
1011
- taxonomy
1112
- user
1213
id: civictheme_automated_list_test
@@ -300,6 +301,45 @@ display:
300301
validate_options: { }
301302
break_phrase: false
302303
not: true
304+
field_c_n_vertical_spacing_value:
305+
id: field_c_n_vertical_spacing_value
306+
table: node__field_c_n_vertical_spacing
307+
field: field_c_n_vertical_spacing_value
308+
relationship: none
309+
group_type: group
310+
admin_label: ''
311+
plugin_id: string_list_field
312+
default_action: ignore
313+
exception:
314+
value: all
315+
title_enable: false
316+
title: All
317+
title_enable: false
318+
title: ''
319+
default_argument_type: fixed
320+
default_argument_options:
321+
argument: ''
322+
summary_options:
323+
base_path: ''
324+
count: true
325+
override: false
326+
items_per_page: 25
327+
summary:
328+
sort_order: asc
329+
number_of_records: 0
330+
format: default_summary
331+
human: false
332+
specify_validation: false
333+
validate:
334+
type: none
335+
fail: 'not found'
336+
validate_options: { }
337+
glossary: false
338+
limit: 0
339+
case: none
340+
path_case: none
341+
transform_dash: false
342+
break_phrase: false
303343
filters:
304344
status:
305345
id: status
@@ -572,7 +612,6 @@ display:
572612
- 'languages:language_interface'
573613
- url
574614
- url.query_args
575-
- user
576615
- 'user.node_grants:view'
577616
- user.permissions
578617
tags: { }
@@ -595,7 +634,6 @@ display:
595634
- 'languages:language_interface'
596635
- url
597636
- url.query_args
598-
- user
599637
- 'user.node_grants:view'
600638
- user.permissions
601639
tags: { }

web/themes/contrib/civictheme/README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@ The Drupal theme provides full integration and ships with the UI Kit.
1717

1818
## Installation
1919

20-
```bash
21-
composer require drupal/civictheme
22-
```
20+
> [!IMPORTANT]
21+
> For Drupal theme installation instructions, see https://docs.civictheme.io/development/drupal-theme
2322
2423
Enable CivicTheme theme to use it as-is - CivicTheme UI kit is
2524
already included as a set of compiled assets.

web/themes/contrib/civictheme/civictheme.api.php

Lines changed: 68 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,23 @@
1212
use Drupal\views\ViewExecutable;
1313

1414
/**
15-
* Alter the view info used in the Automated list component.
15+
* Alter the info about the view used in the Automated list component.
16+
*
17+
* This hook allows to alter which view and display are used to power the
18+
* Automated list component based on the settings provided.
19+
* The settings are extracted from the fields provided by the CivicTheme within
20+
* the Automated list paragraph entity.
21+
* Note that for any custom fields added to the Automated list paragraph entity,
22+
* the settings would need to be extracted from those fields using
23+
* $settings['paragraph']->get('field_name')->getString() or similar methods as
24+
* CivicTheme cannot predict the field names used in the custom implementation.
1625
*
1726
* @param array $info
1827
* View info array to alter passed by reference. Keys are:
1928
* - view_name: (string) A view machine name.
2029
* - display_name: (string) A view display machine name.
2130
* @param array $settings
22-
* The Automated list component settings passed by reference with the
31+
* The Automated list component settings with the
2332
* following keys:
2433
* - title: (string) List title.
2534
* - type: (string) List type (view name that powers Automated list).
@@ -33,8 +42,9 @@
3342
* - topics: (array) Array of Topic entities.
3443
* - site_sections: (array) Array of Site section entities.
3544
* - cache_tags: (array) Array of the cache tags.
45+
* - paragraph: (Paragraph) The paragraph entity.
3646
*/
37-
function hook_civictheme_automated_list_view_info_alter(array &$info, array &$settings): void {
47+
function hook_civictheme_automated_list_view_info_alter(array &$info, array $settings): void {
3848
// Change the view name and block based on the conditions set in the
3949
// Automated list settings.
4050
if ($settings['content_type'] == 'event') {
@@ -49,48 +59,65 @@ function hook_civictheme_automated_list_view_info_alter(array &$info, array &$se
4959
}
5060

5161
/**
52-
* Alter the CivicTheme view preprocess settings.
62+
* Alter the view used in the Automated list component before rendering.
5363
*
54-
* @param array $variables
55-
* Array of preprocess variables of the Automated list view.
64+
* The view instance already has settings applied from the default fields
65+
* provided by the CivicTheme within the Automated list paragraph entity.
66+
* Any additional settings can be extracted from the fields provided by the
67+
* Automated list paragraph entity using $view->component_settings['paragraph'].
68+
*
69+
* @param \Drupal\views\ViewExecutable $view
70+
* The view object to alter.
5671
*/
57-
function hook_civictheme_automated_list_preprocess_view_alter(array &$variables, ViewExecutable &$view): void {
58-
if ($view->id() == 'civictheme_view_examples') {
59-
$variables['theme'] = CivicthemeConstants::THEME_DARK;
60-
$variables['with_background'] = TRUE;
61-
$variables['vertical_spacing'] = 'both';
72+
function hook_civictheme_automated_list_view_alter(ViewExecutable $view): void {
73+
// Example of altering the view theme, item theme and arguments.
74+
if ($view->id() === 'custom_view_id') {
75+
$view->component_settings['theme'] = CivicthemeConstants::THEME_LIGHT;
76+
$view->component_settings['item_theme'] = CivicthemeConstants::THEME_DARK;
77+
78+
// Example of setting view arguments based on the expected contextual
79+
// filters of this specific view.
80+
// In thi example, the view has 3 contextual filters.
81+
$view_args = [];
82+
// First view argument - content types. Read from settings.
83+
$view_args[] = $view->component_settings['content_type'] ?? 'all';
84+
// Second view argument - Content ID value. Use `all` to skip it.
85+
$view_args[] = 'all';
86+
// Third view argument - Vertical Spacing value. Use a constant value.
87+
$view_args[] = CivicthemeConstants::VERTICAL_SPACING_TOP;
88+
// Set the arguments to the view.
89+
$view->setArguments($view_args);
6290
}
91+
}
6392

64-
/**
65-
* Allow to suppress page regions for pages with Layout Builder enabled.
66-
*
67-
* @param array $variables
68-
* Array of variables passed to the page template.
69-
* @param array $context
70-
* Array of context data.
71-
* - node: The node object.
72-
* - layout_builder_settings_per_view_mode: An array of the layout builder
73-
* settings keyed by view mode.
74-
*
75-
* @SuppressWarnings(PHPMD.StaticAccess)
76-
*/
77-
function hook_civictheme_layout_suppress_page_regions_alter(array &$variables, array $context): void {
78-
/** @var \Drupal\node\NodeInterface $node */
79-
$node = $variables['node'];
80-
if ($node->bundle() == 'civictheme_page' && $context['layout_builder_settings_per_view_mode']['full']['enabled']) {
81-
$variables['page']['sidebar_top_left'] = [];
82-
$variables['page']['sidebar_bottom_left'] = [];
83-
$variables['page']['sidebar_top_right'] = [];
84-
$variables['page']['sidebar_bottom_right'] = [];
93+
/**
94+
* Allow to suppress page regions for pages with Layout Builder enabled.
95+
*
96+
* @param array $variables
97+
* Array of variables passed to the page template.
98+
* @param array $context
99+
* Array of context data.
100+
* - node: The node object.
101+
* - layout_builder_settings_per_view_mode: An array of the layout builder
102+
* settings keyed by view mode.
103+
*
104+
* @SuppressWarnings(PHPMD.StaticAccess)
105+
*/
106+
function hook_civictheme_layout_suppress_page_regions_alter(array &$variables, array $context): void {
107+
/** @var \Drupal\node\NodeInterface $node */
108+
$node = $variables['node'];
109+
if ($node->bundle() == 'civictheme_page' && $context['layout_builder_settings_per_view_mode']['full']['enabled']) {
110+
$variables['page']['sidebar_top_left'] = [];
111+
$variables['page']['sidebar_bottom_left'] = [];
112+
$variables['page']['sidebar_top_right'] = [];
113+
$variables['page']['sidebar_bottom_right'] = [];
85114

86-
// Do not forget to merge the cache contexts.
87-
$variables['#cache']['contexts'] = Cache::mergeContexts(
88-
$variables['#cache']['contexts'] ?? [],
89-
[
90-
'user.roles:authenticated',
91-
]
92-
);
93-
}
115+
// Do not forget to merge the cache contexts.
116+
$variables['#cache']['contexts'] = Cache::mergeContexts(
117+
$variables['#cache']['contexts'] ?? [],
118+
[
119+
'user.roles:authenticated',
120+
]
121+
);
94122
}
95-
96123
}

0 commit comments

Comments
 (0)