Skip to content

Commit

Permalink
USAGOV-2015-paragraph-url: Checks if an entity can provide a URL to b…
Browse files Browse the repository at this point in the history
…uild a link in the output.
  • Loading branch information
omerida committed Oct 15, 2024
1 parent 2bcb561 commit 5270aa7
Showing 1 changed file with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ function usa_orphaned_entities_form_alter(&$form, &$form_state, $form_id) {
$additional .= "<ul>" . PHP_EOL;

foreach ($reference_data['skip']['references'] as $reference_skip) {
$url = $reference_skip->toUrl();
$id = $reference_skip->id();
$type = $reference_skip->getEntityTypeId();
$title = $reference_skip->label();
Expand All @@ -89,10 +88,21 @@ function usa_orphaned_entities_form_alter(&$form, &$form_state, $form_id) {
$type = $reference_skip->getEntityTypeId() . ' / ' . $reference_skip->bundle();
break;
}
$additional .= sprintf(
'<li><a href="%s" target="_blank">%s: %s (%d)</a></li>' . PHP_EOL,
$url->toString(), $type, Html::escape($title), $id
);

// Some entities, like paragraphs, don't have a link template
// which makes call to toUrl() fail.
if ($reference_skip->hasLinkTemplate('canonical')) {
$additional .= sprintf(
'<li><a href="%s" target="_blank">%s: %s (%d)</a></li>' . PHP_EOL,
$reference_skip->toUrl()->toString(), $type, Html::escape($title), $id
);
}
else {
$additional .= sprintf(
'<li>%s: %s (%d)</li>' . PHP_EOL,
$type, Html::escape($title), $id
);
}
}

$additional .= "</ul></div>" . PHP_EOL;
Expand Down

0 comments on commit 5270aa7

Please sign in to comment.