Skip to content
This repository was archived by the owner on Jun 22, 2020. It is now read-only.

Render author using a view mode specific template #162

Open
wants to merge 9 commits into
base: 8.x-2.x
Choose a base branch
from
Open
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
langcode: en
status: true
dependencies:
module:
- user
id: user.facebook_instant_articles_rss
label: 'Facebook Instant Articles: RSS'
targetEntityType: user
cache: true
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<a>{{ user.displayName }}</a>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we use a new viewmode for the user, shouldn't we then also render the full user?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is, that in the default configuration, the User entity doesn't have any name associated. Only a picture and "Member for" would be displayed.

23 changes: 23 additions & 0 deletions modules/thunder_article/modules/thunder_fia/thunder_fia.install
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

/**
* @file
* Install, update and uninstall functions for the thunder_fia module.
*/

/**
* Add FIA view mode for users.
*/
function thunder_fia_update_8001() {
\Drupal::service('module_installer')->install([
'config_update',
]);

/** @var Drupal\config_update\ConfigRevertInterface $configReverter */
$configUpdate = \Drupal::service('config_update.config_update');

if (empty($configUpdate->getFromActive('entity_view_mode', 'user.facebook_instant_articles_rss'))) {
$configUpdate->import('entity_view_mode', 'user.facebook_instant_articles_rss');
}

}
10 changes: 2 additions & 8 deletions modules/thunder_article/modules/thunder_fia/thunder_fia.module
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,8 @@ function thunder_fia_preprocess_views_view_row_fia(&$variables) {
}
}

// Change author name to "firstname lastname".
$owner = $node->getOwner();
if (isset($owner->first_name, $owner->last_name)) {
$name = $owner->first_name->value . ' ' . $owner->last_name->value;
if ($name = trim($name) && !empty($variables['options']['author'])) {
$variables['options']['author'] = ['#markup' => '<a>' . $name . '</a>'];
}
}
$render_controller = \Drupal::entityTypeManager()->getViewBuilder($node->getOwner()->getEntityTypeId());
$variables['options']['author'] = $render_controller->view($node->getOwner(), 'facebook_instant_articles_rss', NULL);
}
}

Expand Down