Skip to content

Commit

Permalink
Fixed wording and added extra links for Google Analytics report
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanboring committed Oct 8, 2024
1 parent 21656c6 commit 85a4dd5
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -182,4 +182,16 @@ private function getSummaryResults(EntityInterface $entity): ?array {
return $return;
}

/**
* {@inheritdoc}
*/
public function extraSummaryLinks(EntityInterface $entity): array {
return [
[
'title' => $this->t('View sitewide Google Analytics report'),
'url' => Url::fromRoute('view.google_analytics_summary.page_1'),
],
];
}

}
17 changes: 17 additions & 0 deletions modules/analyze_plugin_example/src/Plugin/Analyze/Example.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,4 +231,21 @@ private function getData(EntityInterface $entity): array {
];
}

/**
* {@inheritdoc}
*
* This method exists to be able to add extra links to the summary page. For
* instance, if you have a plugin that provides a full global report, you can
* add a link to that report here or if there is some external tool being
* used.
*/
public function extraSummaryLinks(EntityInterface $entity): array {
return [
'global_report' => [
'title' => $this->t('Global Report'),
'url' => Url::fromUri('https://example.com/global-report'),
],
];
}

}
11 changes: 11 additions & 0 deletions src/AnalyzeInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,15 @@ public function access(EntityInterface $entity): bool;
*/
public function fullReportUrlOverridden(EntityInterface $entity): bool;

/**
* If the plugin wants to expose extra summary links, it can do so here.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* An entity to create links against.
*
* @return array<mixed>
* An array of title and url pairs.
*/
public function extraSummaryLinks(EntityInterface $entity): array;

}
7 changes: 7 additions & 0 deletions src/AnalyzePluginBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,11 @@ public function access(EntityInterface $entity): bool {
return TRUE;
}

/**
* {@inheritdoc}
*/
public function extraSummaryLinks(EntityInterface $entity): array {
return [];
}

}
21 changes: 20 additions & 1 deletion src/Controller/AnalyzeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function analyze(?string $plugin = NULL, ?string $entity_type = NULL, boo
if (!$full_report && $url = $plugin->getFullReportUrl($entity)) {
$build[$id . '-link'] = [
'#type' => 'link',
'#title' => $this->t('View the full report'),
'#title' => $this->t('View full report of this page'),
'#url' => $url,
'#attributes' => [
'class' => [
Expand Down Expand Up @@ -114,6 +114,25 @@ public function analyze(?string $plugin = NULL, ?string $entity_type = NULL, boo

$weight++;
}
// If there are extra links for the summary, add them.
if (!$full_report && $links = $plugin->extraSummaryLinks($entity)) {
foreach ($links as $key => $link) {
$build[$id . '-extra-link-' . $key] = [
'#type' => 'link',
'#title' => $link['title'],
'#url' => $link['url'],
'#attributes' => [
'class' => [
'action-link',
Html::cleanCssIdentifier('view-' . $id . '-report'),
],
],
'#weight' => $weight,
];

$weight++;
}
}
}
elseif (!$full_report) {

Expand Down

0 comments on commit 85a4dd5

Please sign in to comment.