Skip to content

Commit

Permalink
Merge pull request #138 from localgovdrupal/1.x
Browse files Browse the repository at this point in the history
1.0.2 release
  • Loading branch information
finnlewis authored Oct 22, 2024
2 parents 01ff6e7 + 06e8478 commit a422e6b
Show file tree
Hide file tree
Showing 25 changed files with 85 additions and 18 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"drupal/entity_extra_field": "^2.1@RC",
"drupal/color_field": "^3.0",
"drupal/field_formatter_class":" ^1.5",
"drupal/paragraphs_table": "^1.6",
"drupal/paragraphs_table": "^1.23 || ^2.0",
"cweagans/composer-patches": "^1.6",
"drupal/charts": "^5.0",
"drupal/views_field_view": "^1.0@beta",
Expand Down
4 changes: 2 additions & 2 deletions config/install/views.view.localgov_election_results.yml
Original file line number Diff line number Diff line change
Expand Up @@ -958,7 +958,7 @@ display:
group_type: group
admin_label: ''
plugin_id: field
label: ''
label: Hold/Gain
exclude: false
alter:
alter_text: true
Expand Down Expand Up @@ -1188,7 +1188,7 @@ display:
click_sort_column: value
type: number_integer
settings:
thousand_separator: ''
thousand_separator: ','
prefix_suffix: true
group_column: value
group_columns: { }
Expand Down
7 changes: 7 additions & 0 deletions css/election-results.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
.localgov-election__content > * + * {
margin-top: 3rem;
padding-top: 3rem;
border-top: var(--table-border);
}


.county-summary__subheading {
padding: 1rem;
background-color: var(--color-grey);
Expand Down
3 changes: 2 additions & 1 deletion js/chartjs-override.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
colour = null;
});
chart_data.data.datasets[0].backgroundColor = data;
chart_data.options.scales.x.ticks.precision = 0;
};

Drupal.behaviors.charts_override = {
Expand All @@ -42,7 +43,7 @@
let data = e.detail;
const id = data.drupalChartDivId;
Drupal.localgov_elections.setChartColours(data, settings);
if (id === 'chart-election-results-via-parties-block-1') {
if (id === 'chart-election-results-via-parties-block-1' || 'chart-localgov-election-results-via-parties-block-1') {
data.options.scales.y.grid = { display: false};
data.options.scales.y.ticks.autoSkip = false;
}
Expand Down
1 change: 0 additions & 1 deletion localgov_elections.libraries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ election:
version: 1.x
css:
theme:
css/variables.css: { }
css/election-results.css: { }

electoral_candidates_view:
Expand Down
2 changes: 1 addition & 1 deletion localgov_elections.module
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ function localgov_elections_menu_local_tasks_alter(&$data, $route_name) {

// Add the "add area" button to the local tasks if user has permission.
$can_add_areas = Drupal::currentUser()->hasPermission('can fetch boundaries');
if ($can_add_areas && in_array($route_name, $appropriate_fetch_routes)) {
if ($can_add_areas && in_array($route_name, $appropriate_fetch_routes, TRUE)) {
$data['tabs'][0]['boundary_fetch'] = [
'#theme' => 'menu_local_task',
'#weight' => 100,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public function validateConfigurationForm(array &$form, FormStateInterface $form
// seen before. It needs to be in the dataset.
$constituencies = $this->cacheBackend->get(CacheKey::CONSTITUENCY_NAMES_KEY)?->data;
foreach ($values as $val) {
if (!in_array($val, $constituencies)) {
if (!in_array($val, $constituencies, TRUE)) {
$form_state->setErrorByName('constituencies', "$val does not seem to be a valid choice.");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public function testConstituencyLookupEndpoint(): void {

$this->assertIsArray($response);

$this->assertTrue(in_array(['label' => 'Edinburgh South West', 'value' => 'Edinburgh South West'], $response));
$this->assertTrue(in_array(['value' => 'Edinburgh South West', 'label' => 'Edinburgh South West'], $response, TRUE));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ default:
revision_translation_affected:
-
value: true
moderation_state:
-
value: published
path:
-
alias: /election/general-election-july-2024/henley-and-thame
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ default:
revision_translation_affected:
-
value: true
moderation_state:
-
value: published
path:
-
alias: /election/general-election-july-2024
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ default:
revision_translation_affected:
-
value: true
moderation_state:
-
value: published
path:
-
alias: /election/general-election-july-2024/bicester-and-woodstock
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ default:
revision_translation_affected:
-
value: true
moderation_state:
-
value: published
path:
-
alias: /election/general-election-july-2024/oxford-west-and-abingdon
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ default:
revision_translation_affected:
-
value: true
moderation_state:
-
value: published
path:
-
alias: /election/general-election-july-2024/banbury
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ default:
revision_translation_affected:
-
value: true
moderation_state:
-
value: published
path:
-
alias: /election/general-election-july-2024/oxford-east
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ default:
revision_translation_affected:
-
value: true
moderation_state:
-
value: published
path:
-
alias: /election/general-election-july-2024/witney
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ default:
revision_translation_affected:
-
value: true
moderation_state:
-
value: published
path:
-
alias: /election/general-election-july-2024/didcot-and-wantage
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

/**
* @file
* LocalGovDrupal elections demo module file.
*/

/**
* Implements hook_modules_installed().
*/
function localgov_elections_demo_content_modules_installed($modules, $is_syncing) {
if (!$is_syncing && in_array('default_content', $modules, TRUE)) {
// Regenerate all path aliases.
$nids = \Drupal::entityQuery('node')
->condition('type', ['localgov_area_vote', 'localgov_election'], 'IN')
->accessCheck(FALSE)
->execute();
$nodes = \Drupal::entityTypeManager()
->getStorage('node')
->loadMultiple($nids);
foreach ($nodes as $node) {
\Drupal::service('pathauto.generator')->updateEntityAlias($node, 'update');
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ protected function fetchBoundaryInformation($lad, $ids): array {
$matched_features = [];
if ($response->getStatusCode() == 200) {
foreach ($json_decoded['features'] as $feature) {
if (in_array($feature['properties']['WD23CD'], $ids)) {
if (in_array($feature['properties']['WD23CD'], $ids, TRUE)) {
$matched_features[] = $feature;
$num_matched++;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public function getFormId(): string {
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state, NodeInterface $node = NULL): array {
public function buildForm(array $form, FormStateInterface $form_state, ?NodeInterface $node = NULL): array {
if ($node->bundle() != "localgov_area_vote") {
$this->messenger()->addError("Can only post from area vote nodes");
return $form;
Expand Down Expand Up @@ -330,7 +330,7 @@ protected function getTokenizedMessage($form, FormStateInterface $form_state) {
public function submitForm(array &$form, FormStateInterface $form_state): void {
$keys = array_keys($form_state->get('original_data')['account']);
$accounts = array_filter($this->userManager->getAccounts('social_post_twitter'), function ($obj) use ($keys) {
return in_array($obj->id(), $keys);
return in_array($obj->id(), $keys, TRUE);
});

$message = $form_state->getValue('preview');
Expand Down
10 changes: 10 additions & 0 deletions src/Annotation/BoundaryProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,34 @@
/**
* Defines boundary_provider annotation object.
*
* @see plugin_api
*
* @Annotation
*/
class BoundaryProvider extends Plugin {

/**
* The plugin ID.
*
* @phpstan-ignore-next-line This is allowed in Drupal, but PHPStan complains even though this is valid
*/
public readonly string $id;

/**
* The human-readable name of the plugin.
*
* @ingroup plugin_translatable
*
* @phpstan-ignore-next-line This is allowed in Drupal, but PHPStan complains even though this is valid
*/
public readonly string $title;

/**
* The description of the plugin.
*
* @ingroup plugin_translatable
*
* @phpstan-ignore-next-line This is allowed in Drupal, but PHPStan complains even though this is valid
*/
public readonly string $description;

Expand All @@ -39,6 +47,8 @@ class BoundaryProvider extends Plugin {
* form at the moment.
*
* @returns array
*
* @phpstan-ignore-next-line This is allowed in Drupal, but PHPStan complains even though this is valid
*/
public array $form = [];

Expand Down
2 changes: 1 addition & 1 deletion src/Form/BoundaryFetchForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public function getFormId(): string {
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state, NodeInterface $node = NULL): array {
public function buildForm(array $form, FormStateInterface $form_state, ?NodeInterface $node = NULL): array {
// It doesn't make sense to allow non-elections
// using this form so deny any of the form.
// @todo would it make sense to redirect somewhere? Or throw an error?
Expand Down
3 changes: 2 additions & 1 deletion src/Plugin/Block/AnalysisBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public function build() {
}

// Display majority if we can.
if ($display_majority && isset($majority)) {
if ($display_majority && !is_null($majority)) {
$markup .= '<div class="results-analysis-grid__label results-analysis-grid__label--majority">Majority</div>';
$markup .= '<div class="results-analysis-grid__value results-analysis-grid__value--majority">' . $majority . '</div>';
}
Expand All @@ -118,6 +118,7 @@ public function build() {
$previous_year = $node->localgov_election_previous_year->value;
$previous_winning_party = $node->localgov_election_prev_winner->entity;
$previous_result = $node->localgov_election_prev_result->referencedEntity;
$previous_winner_abbr = '';
if (isset($previous_winning_party)) {
$previous_winner_abbr = $previous_winning_party->localgov_election_abbreviation->value;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Plugin/views/field/ElectionSeatsParty.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function render(ResultRow $values) {

// Find party of Ward/Area/Division winning candidate.
$winning_cand_id = $ward->get('localgov_election_winner')->target_id;
if (isset($winning_cand_id)) {
if (!is_null($winning_cand_id)) {
$winning_cand = Paragraph::load($winning_cand_id);
if (isset($winning_cand)) {
$winning_party = $winning_cand->get('localgov_election_party')->target_id;
Expand Down
6 changes: 3 additions & 3 deletions tests/src/Functional/ElectionAliasTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
namespace Drupal\Tests\localgov_elections\Functional;

use Drupal\Core\Url;
use Drupal\Tests\BrowserTestBase;
use Drupal\file\Entity\File;
use Drupal\node\NodeStorageInterface;
use Drupal\Tests\BrowserTestBase;

/**
* Tests alias functionality for Election nodes.
Expand Down Expand Up @@ -92,7 +92,7 @@ protected function setUp(): void {
]);
$file->save();

$this->area_vote = $this->nodeStorage->create([
$this->areaVote = $this->nodeStorage->create([
'title' => "An area",
'status' => TRUE,
'type' => "localgov_area_vote",
Expand All @@ -104,7 +104,7 @@ protected function setUp(): void {
'coordinates' => [1.234567, 2.345678],
]),
]);
$this->area_vote->save();
$this->areaVote->save();

// Map page.
$map_page_url = Url::fromRoute('view.localgov_election_electoral_map.page_1',
Expand Down
2 changes: 1 addition & 1 deletion tests/src/Functional/ElectionSummaryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

namespace Drupal\Tests\localgov_elections\Functional;

use Drupal\node\NodeInterface;
use Drupal\Tests\BrowserTestBase;
use Drupal\node\NodeInterface;

/**
* Tests results heading text on the summary page.
Expand Down

0 comments on commit a422e6b

Please sign in to comment.