Skip to content

Commit

Permalink
Merge pull request #383 from localgovdrupal/3.x
Browse files Browse the repository at this point in the history
3.1.7 release
  • Loading branch information
finnlewis authored Jun 18, 2024
2 parents 8859776 + 26f61ad commit b49dc72
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"drupal/pathauto": "^1.6",
"drupal/search_api": "^1.29",
"drupal/search_api_autocomplete": "^1.3",
"drupal/search_api_location": "1.x-dev",
"drupal/search_api_location": "1.x-dev#cf3e546770099b1f136c020ade79a650d4178ad6",
"localgovdrupal/localgov_core": "^2.12",
"localgovdrupal/localgov_geo": "^2.0"
},
Expand Down
45 changes: 45 additions & 0 deletions src/Plugin/PreviewLinkAutopopulate/DirectoryChannel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

namespace Drupal\localgov_directories\Plugin\PreviewLinkAutopopulate;

use Drupal\node\NodeInterface;
use Drupal\preview_link\PreviewLinkAutopopulatePluginBase;

/**
* Auto-populate directory preview links.
*
* @PreviewLinkAutopopulate(
* id = "localgov_directories",
* label = @Translation("Add all the pages for this directory channel"),
* description = @Translation("Add all directory nodes for this channel to preview link."),
* supported_entities = {
* "node" = {
* "localgov_directory",
* }
* },
* )
*/
class DirectoryChannel extends PreviewLinkAutopopulatePluginBase {

/**
* {@inheritdoc}
*/
public function getPreviewEntities(): array {
$nodes = [];
$channel = $this->getEntity();

// Find all directory pages.
$pages = $this->entityTypeManager->getStorage('node')
->loadByProperties([
'localgov_directory_channels' => $channel->id(),
]);
foreach ($pages as $page) {
if ($page instanceof NodeInterface && $page->access('view')) {
$nodes[] = $page;
}
}

return $nodes;
}

}

0 comments on commit b49dc72

Please sign in to comment.