Ref #239. Add authors and date to paragraph title

This commit is contained in:
Louis Elkner-Alfaro 2023-07-03 13:43:37 -07:00
parent c5ff2f2214
commit 3ddef4a97f

View file

@ -3,6 +3,7 @@
use Drupal\block\Entity\Block;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Url;
use Drupal\node\Entity\Node;
/**
* Implements hook_preprocess_node() for NODE document templates.
@ -121,3 +122,22 @@ function agarica_languague_switch_link() {
return $links_render_array;
}
/**
* Implements hook_preprocess_HOOK() for node templates.
*/
function agarica_preprocess_field__field_title(&$variables) {
$parentEntity = $variables['element']['#object']->getParentEntity();
if ($parentEntity instanceof EntityInterface && $parentEntity->getEntityTypeId() === 'node') {
if ($parentEntity->get('field_authors')) {
$field_authors = $parentEntity->get('field_authors');
$authors = '';
$date = $parentEntity->getCreatedTime();
foreach ($field_authors as $author) {
$authors .= Node::load($author->getValue()['target_id'])->label() . ', ';
}
$variables['authors'] = $authors;
$variables['date'] = \Drupal::service('date.formatter')->format($date, 'custom', 'Y F j');
}
}
}