Get a pretty good draft of our citation section
This commit is contained in:
parent
ec351cb728
commit
1ea4670410
1 changed files with 66 additions and 2 deletions
|
@ -26,8 +26,72 @@ function geo_citation_entity_extra_field_info() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implements hook_ENTITY_TYPE_view() for Drutopia articles.
|
* Implements hook_ENTITY_TYPE_view() for nodes.
|
||||||
*/
|
*/
|
||||||
function geo_citation_article_view(array &$build, \Drupal\Core\Entity\EntityInterface $entity, \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display, $view_mode) {
|
function geo_citation_node_view(array &$build, \Drupal\Core\Entity\EntityInterface $entity, \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display, $view_mode) {
|
||||||
|
// This will only exist for the Drutopia article content type but don't think we need to check first.
|
||||||
|
if ($display->getComponent('geo_citation')) {
|
||||||
|
$build['geo_citation'] = [
|
||||||
|
'#markup' => geo_citation_pseudo_field($entity),
|
||||||
|
'#theme' => 'geo_citation_field',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implements hook_theme().
|
||||||
|
*
|
||||||
|
* We intentionally choose to do the citation in one big lump, because our
|
||||||
|
* expectation for making this more flexible would be to plug into bibcite or
|
||||||
|
* other citation API, rather than making it easy to re-theme this custom data.
|
||||||
|
*
|
||||||
|
function geo_citation_theme($existing, $type, $theme, $path) {
|
||||||
|
return [
|
||||||
|
'geo_citation_field' => [
|
||||||
|
'variables' => [
|
||||||
|
'citation' => '',
|
||||||
|
]
|
||||||
|
]
|
||||||
|
]
|
||||||
|
}
|
||||||
|
* ...and it turns out giving theming capability to our pseudofield is optional.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Assemble and return our citation as already-marked-up HTML.
|
||||||
|
*/
|
||||||
|
function geo_citation_pseudo_field($entity) {
|
||||||
|
$markup = '';
|
||||||
|
$article_type = $entity->field_article_type->getValue();
|
||||||
|
// If it's not a GEO Original article, there's nothing for us to do.
|
||||||
|
if (!isset($article_type[0]) || $article_type[0]['target_id'] != '303') {
|
||||||
|
return $markup;
|
||||||
|
}
|
||||||
|
|
||||||
|
$authors = $entity->field_authors->getValue();
|
||||||
|
$date = $entity->field_publication_date->value;
|
||||||
|
$year = substr($date, 0, 4);
|
||||||
|
$title = $entity->title->value;
|
||||||
|
$subtitle = $entity->field_subtitle->value;
|
||||||
|
$url = $entity->toUrl()->setAbsolute()->toString();
|
||||||
|
|
||||||
|
$markup .= '<div class="geo-citation">';
|
||||||
|
|
||||||
|
$tooltip = t("When citing this article, please use the following format:")
|
||||||
|
$markup .= '<h4><abbr title="' . $tooltip . '">' . t("Citations") . '</abbr></h4>';
|
||||||
|
|
||||||
|
$markup .= '<p>';
|
||||||
|
$markup .= "$authors ($year).  $title";
|
||||||
|
if ($subtitle) {
|
||||||
|
$markup .= ":  $subtitle";
|
||||||
|
}
|
||||||
|
$markup .= ".  ";
|
||||||
|
$markup .= t("Grassroots Economic Organizing (GEO).");
|
||||||
|
$markup .= "  $url";
|
||||||
|
$markup .= '</p>';
|
||||||
|
|
||||||
|
$markup .= '</div>';
|
||||||
|
|
||||||
|
return $markup;
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue