-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #383 from localgovdrupal/3.x
3.1.7 release
- Loading branch information
Showing
2 changed files
with
46 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |