Skip to content

Release 2.3.6 #156

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

Merged
merged 8 commits into from
Aug 13, 2024
206 changes: 6 additions & 200 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,205 +7,11 @@ on:
pull_request:
branches:
- '2.x'

env:
LOCALGOV_DRUPAL_PROJECT: localgovdrupal/localgov_subsites
LOCALGOV_DRUPAL_PROJECT_PATH: web/modules/contrib/localgov_subsites
workflow_dispatch:

jobs:

build:
name: Install LocalGov Drupal
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
include:
- localgov-version: '2.x'
drupal-version: '~9.4'
php-version: '8.1'
- localgov-version: '3.x'
drupal-version: '~10.0'
php-version: '8.1'

steps:

- name: Save git branch and git repo names to env if this is not a pull request
if: github.event_name != 'pull_request'
run: |
echo "GIT_BASE=${GITHUB_REF#refs/heads/}" >> $GITHUB_ENV
echo "GIT_BRANCH=${GITHUB_REF#refs/heads/}" >> $GITHUB_ENV
echo "HEAD_USER=localgovdrupal" >> $GITHUB_ENV

- name: Save git branch and git repo names to env if this is a pull request
if: github.event_name == 'pull_request'
run: |
echo "GIT_BASE=${GITHUB_BASE_REF}" >> $GITHUB_ENV
echo "GIT_BRANCH=${GITHUB_HEAD_REF}" >> $GITHUB_ENV
export HEAD="${{ github.event.pull_request.head.label }}"
echo "HEAD_USER=${HEAD%%:*}" >> $GITHUB_ENV

- name: Set composer branch reference for version branches
if: endsWith(github.ref, '.x')
run: echo "COMPOSER_REF=${GIT_BRANCH}-dev" >> $GITHUB_ENV

- name: Set composer branch reference for non-version branches
if: endsWith(github.ref, '.x') == false
run: echo "COMPOSER_REF=dev-${GIT_BRANCH}" >> $GITHUB_ENV

- name: Get the latest tagged release for branch version
run: |
LATEST_RELEASE=$(curl -H "Accept: application/vnd.github.v3+json" https://api.github.com/repos/${GITHUB_REPOSITORY}/git/matching-refs/tags/${GIT_BASE%'.x'} | grep -Po '(?<=refs/tags/)[^"]+' | tail -1)
if [ -z $LATEST_RELEASE ]; then LATEST_RELEASE=1; fi
echo "LATEST_RELEASE=${LATEST_RELEASE}" >> $GITHUB_ENV

- name: Cached workspace
uses: actions/cache@v2
with:
path: ./html
key: localgov-build-${{ matrix.localgov-version }}-${{ matrix.drupal-version }}-${{ matrix.php-version }}-${{ github.run_id }}-${{ secrets.CACHE_VERSION }}

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}

- name: Clone drupal_container
uses: actions/checkout@v2
with:
repository: localgovdrupal/drupal-container
ref: php${{ matrix.php-version }}

- name: Create LocalGov Drupal project
run: |
composer create-project --stability dev --no-install localgovdrupal/localgov-project ./html "${{ matrix.localgov-version }}"
composer --working-dir=./html require --no-install localgovdrupal/localgov:${{ matrix.localgov-version }}-dev
composer --working-dir=./html require --no-install drupal/core-recommended:${{ matrix.drupal-version }} drupal/core-composer-scaffold:${{ matrix.drupal-version }} drupal/core-project-message:${{ matrix.drupal-version }} drupal/core-dev:${{ matrix.drupal-version }}
composer --working-dir=./html install

- name: Obtain the test target using Composer
if: env.HEAD_USER == 'localgovdrupal'
run: |
composer --working-dir=html config repositories.1 vcs [email protected]:${LOCALGOV_DRUPAL_PROJECT}.git
composer global config github-oauth.github.com ${{ github.token }}
composer --working-dir=./html require --with-all-dependencies ${LOCALGOV_DRUPAL_PROJECT}:"${COMPOSER_REF} as ${LATEST_RELEASE}"

- name: Obtain the test target using Git
if: env.HEAD_USER != 'localgovdrupal'
uses: actions/checkout@v2
with:
path: ${{ env.LOCALGOV_DRUPAL_PROJECT_PATH }}

phpcs:
name: Coding standards checks
needs: build
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
include:
- localgov-version: '2.x'
drupal-version: '~9.4'
php-version: '8.1'
- localgov-version: '3.x'
drupal-version: '~10.0'
php-version: '8.1'

steps:

- name: Cached workspace
uses: actions/cache@v2
with:
path: ./html
key: localgov-build-${{ matrix.localgov-version }}-${{ matrix.drupal-version }}-${{ matrix.php-version }}-${{ github.run_id }}-${{ secrets.CACHE_VERSION }}
restore-keys: |
localgov-build-${{ matrix.localgov-version }}-${{ matrix.drupal-version }}-${{ matrix.php-version }}-

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}

- name: Run coding standards checks
run: |
cd html
./bin/phpcs -p ${LOCALGOV_DRUPAL_PROJECT_PATH}

phpstan:
name: Deprecated code checks
needs: build
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
include:
- localgov-version: '2.x'
drupal-version: '~9.4'
php-version: '8.1'
- localgov-version: '3.x'
drupal-version: '~10.0'
php-version: '8.1'

steps:

- name: Cached workspace
uses: actions/cache@v2
with:
path: ./html
key: localgov-build-${{ matrix.localgov-version }}-${{ matrix.drupal-version }}-${{ matrix.php-version }}-${{ github.run_id }}-${{ secrets.CACHE_VERSION }}
restore-keys: |
localgov-build-${{ matrix.localgov-version }}-${{ matrix.drupal-version }}-${{ matrix.php-version }}-

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}

- name: Run deprecated code checks
run: |
cd html
./bin/phpstan analyse -c ./phpstan.neon ${LOCALGOV_DRUPAL_PROJECT_PATH}
phpunit:
name: PHPUnit tests
needs: build
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
include:
- localgov-version: '2.x'
drupal-version: '~9.4'
php-version: '8.1'
- localgov-version: '3.x'
drupal-version: '~10.0'
php-version: '8.1'

steps:

- name: Clone Drupal container
uses: actions/checkout@v2
with:
repository: localgovdrupal/drupal-container
ref: php${{ matrix.php-version }}

- name: Cached workspace
uses: actions/cache@v2
with:
path: ./html
key: localgov-build-${{ matrix.localgov-version }}-${{ matrix.drupal-version }}-${{ matrix.php-version }}-${{ github.run_id }}-${{ secrets.CACHE_VERSION }}
restore-keys: |
localgov-build-${{ matrix.localgov-version }}-${{ matrix.drupal-version }}-${{ matrix.php-version }}-

- name: Start Docker environment
run: docker-compose -f docker-compose.yml up -d

- name: Run PHPUnit tests
run: |
mkdir -p ./html/web/sites/simpletest && chmod 777 ./html/web/sites/simpletest
sed -i "s#http://localgov.lndo.site#http://drupal#" ./html/phpunit.xml.dist
docker exec -t drupal bash -c 'chown docker:docker -R /var/www/html'
docker exec -u docker -t drupal bash -c "cd /var/www/html && ./bin/paratest --processes=4 /var/www/html/${{ env.LOCALGOV_DRUPAL_PROJECT_PATH }}"
tests:
uses: localgovdrupal/localgov_shared_workflows/.github/workflows/[email protected]
with:
project: 'localgovdrupal/localgov_subsites'
project_path: 'web/modules/contrib/localgov_subsites'
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ content:
type: layout_paragraphs
region: content
localgov_subsites_parent:
weight: -3
weight: -6
settings:
match_operator: CONTAINS
match_limit: 10
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ id: node.localgov_subsites_page.localgov_subsites_parent
field_name: localgov_subsites_parent
entity_type: node
bundle: localgov_subsites_page
label: Parent
label: 'Subsite parent page'
description: ''
required: true
translatable: false
Expand All @@ -25,6 +25,7 @@ settings:
localgov_subsites_page: localgov_subsites_page
sort:
field: _none
direction: ASC
auto_create: false
auto_create_bundle: localgov_subsites_overview
weight_min: -50
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
langcode: en
status: true
dependencies:
config:
- field.storage.node.localgov_services_parent
- node.type.localgov_subsites_overview
- node.type.localgov_services_landing
- node.type.localgov_services_sublanding
id: node.localgov_subsites_overview.localgov_services_parent
field_name: localgov_services_parent
entity_type: node
bundle: localgov_subsites_overview
label: 'Service parent page'
description: ''
required: false
translatable: true
default_value: { }
default_value_callback: ''
settings:
handler: localgov_services
handler_settings:
target_bundles:
localgov_services_landing: localgov_services_landing
localgov_services_sublanding: localgov_services_sublanding
field_type: entity_reference
13 changes: 13 additions & 0 deletions localgov_subsites.install
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,19 @@
* LocalGov Subsites install file.
*/

/**
* Implements hook_install().
*/
function localgov_subsites_install($is_syncing) {
if ($is_syncing) {
return;
}

if (\Drupal::moduleHandler()->moduleExists('localgov_services_navigation')) {
localgov_subsites_optional_fields_settings();
}
}

/**
* Clear caches after moving subsites paragraphs to localgov_paragraphs.
*/
Expand Down
42 changes: 41 additions & 1 deletion localgov_subsites.module
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* LocalGov Subsites module file.
*/

use Drupal\Core\Entity\Display\EntityFormDisplayInterface;
use Drupal\localgov_roles\RolesHelper;
use Drupal\localgov_subsites\Subsite;
use Drupal\node\NodeInterface;
Expand Down Expand Up @@ -132,7 +133,7 @@ function localgov_subsites_preprocess_page(&$variables) {
if (in_array($node->bundle(), [
'localgov_subsites_overview',
'localgov_subsites_page',
])) {
], TRUE)) {
$subsite = \Drupal::service('class_resolver')
->getInstanceFromDefinition(Subsite::class)
->getSubsite($node);
Expand All @@ -142,3 +143,42 @@ function localgov_subsites_preprocess_page(&$variables) {
}
}
}

/**
* Set form settings for optional services fields on installation.
*/
function localgov_subsites_optional_fields_settings() {

$form_displays = \Drupal::entityTypeManager()
->getStorage('entity_form_display')
->loadByProperties([
'targetEntityType' => 'node',
'bundle' => 'localgov_subsites_overview',
]);
if ($form_displays) {
foreach ($form_displays as $form_display) {
assert($form_display instanceof EntityFormDisplayInterface);
if (!$form_display->getComponent('localgov_services_parent')) {
$form_display->setComponent('localgov_services_parent', [
'type' => 'entity_reference_autocomplete',
'region' => 'content',
'settings' => [
'match_operator' => 'CONTAINS',
'size' => '60',
'placeholder' => '',
'match_limit' => 10,
],
'weight' => -1,
])->save();
if (
($field_groups = $form_display->getThirdPartySettings('field_group')) &&
($group = $field_groups['group_description'] ?? FALSE)
) {
$group['children'][] = 'localgov_services_parent';
$form_display->setThirdPartySetting('field_group', 'group_description', $group)
->save();
}
}
}
}
}
40 changes: 39 additions & 1 deletion src/Plugin/Block/SubsitesHierarchyTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ protected function getRootId(EntityInterface $entity): ?int {
in_array($entity->bundle(), [
'localgov_subsites_overview',
'localgov_subsites_page',
])
], TRUE)
&& !is_null($entity->id())
) {
if ($root_node = $this->getNestedSetStorage('localgov_subsites')->findRoot($this->getNestedSetNodeKeyFactory()->fromEntity($entity))) {
return $root_node->getId();
Expand All @@ -123,4 +124,41 @@ protected function getRootId(EntityInterface $entity): ?int {
return NULL;
}

/**
* Get flattened list of nodes in subsite hierarchy.
*
* This does not do any access checks so unpublished nodes may be returned. If
* this becomes a requirement then it should be extended to include this.
*
* @param \Drupal\node\NodeInterface $node
* Any entity in the hierarchy.
*
* @return array
* Flattened list of nodes in subsite hierarchy.
*/
public function getFlattenedSubsiteHierarchy(NodeInterface $node): array {
$nodes = [];

$storage = $this->getNestedSetStorage('localgov_subsites');
$node_key = $this->getNestedSetNodeKeyFactory()->fromEntity($node);
if ($ancestors = $storage->findAncestors($node_key)) {
$tree = $storage->findDescendants($ancestors[0]->getNodeKey());
array_unshift($tree, $ancestors[0]);
$mapper = \Drupal::service('entity_hierarchy.entity_tree_node_mapper');
$ancestor_entities = $mapper->loadEntitiesForTreeNodesWithoutAccessChecks('node', $tree);
foreach ($ancestor_entities as $ancestor_entity) {
if (!$ancestor_entities->contains($ancestor_entity)) {
// Doesn't exist or is access hidden.
continue;
}
$entity = $ancestor_entities->offsetGet($ancestor_entity);
if ($entity instanceof NodeInterface) {
$nodes[] = $entity;
}
}
}

return $nodes;
}

}
Loading
Loading