Ref #239. Add authors and date to paragraph title
This commit is contained in:
parent
c5ff2f2214
commit
3ddef4a97f
1 changed files with 20 additions and 0 deletions
|
@ -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');
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue