PanelizerUser.php in Panelizer 8.5
File
src/Plugin/PanelizerEntity/PanelizerUser.php
View source
<?php
namespace Drupal\panelizer\Plugin\PanelizerEntity;
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\panelizer\Plugin\PanelizerEntityBase;
use Drupal\panels\Plugin\DisplayVariant\PanelsDisplayVariant;
use Drupal\Core\Render\Element;
class PanelizerUser extends PanelizerEntityBase {
public function getDefaultDisplay(EntityViewDisplayInterface $display, $bundle, $view_mode) {
$panels_display = parent::getDefaultDisplay($display, $bundle, $view_mode)
->setPageTitle('[user:name]');
foreach ($panels_display
->getRegionAssignments() as $region => $blocks) {
foreach ($blocks as $block_id => $block) {
if ($block
->getPluginId() == 'entity_field:user:name') {
$panels_display
->removeBlock($block_id);
}
}
}
if ($display
->getComponent('member_for')) {
}
return $panels_display;
}
public function alterBuild(array &$build, EntityInterface $entity, PanelsDisplayVariant $panels_display, $view_mode) {
parent::alterBuild($build, $entity, $panels_display, $view_mode);
if ($entity
->id()) {
$build['#contextual_links']['user'] = [
'route_parameters' => [
'user' => $entity
->id(),
],
'metadata' => [
'changed' => $entity
->getChangedTime(),
],
];
}
if (user_picture_enabled() && !empty($build['content']['content'])) {
foreach (Element::children($build['content']['content']) as $key) {
if (isset($build['content']['content'][$key]['content']['field'])) {
foreach (Element::children($build['content']['content'][$key]['content']['field']) as $field_key) {
if ($build['content']['content'][$key]['content']['field']['#field_name'] == 'user_picture') {
if (empty($build['content']['content'][$key]['content']['field'][$field_key]['#item_attributes'])) {
$build['content']['content'][$key]['content']['field'][$field_key]['#item_attributes'] = [
'alt' => \Drupal::translation()
->translate('Profile picture for user @username', [
'@username' => $entity
->getUsername(),
]),
];
}
}
}
}
}
}
}
}