Skip to content

Commit

Permalink
OI-26: Fixed layout builder bug.
Browse files Browse the repository at this point in the history
  • Loading branch information
nvelychenko committed Jul 23, 2020
1 parent a81962c commit dc4346f
Showing 1 changed file with 26 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,34 +51,37 @@ public function onComponentBuild(SectionComponentBuildRenderArrayEvent $event) {
$build = $event->getBuild();
$content = $build['content'];
$comment = $content['#object'];
// Change the default permalink of comment title.
$commented_entity = $comment->getCommentedEntity();
$uri = $commented_entity->toUrl();
// If in the layout_builder nothing to do here.
if (!$comment->isNew()) {
// Change the default permalink of comment title.
$commented_entity = $comment->getCommentedEntity();
$uri = $commented_entity->toUrl();

// Set attributes for permalink.
$attributes = $uri->getOption('attributes') ?: [];
$attributes += ['class' => ['permalink'], 'rel' => 'bookmark'];
$uri->setOptions([
'attributes' => $attributes,
'fragment' => 'comment-' . $comment->id(),
]);
// Set attributes for permalink.
$attributes = $uri->getOption('attributes') ?: [];
$attributes += ['class' => ['permalink'], 'rel' => 'bookmark'];
$uri->setOptions([
'attributes' => $attributes,
'fragment' => 'comment-' . $comment->id(),
]);

// Don't need to show author in My comments.
if ($view_mode_check = $event->getContexts()['view_mode']->getContextValue() != 'my_comments') {
// Render author.
$author = $this->entityTypeManager->getViewBuilder('user')->view($comment->getOwner(), 'author');
$build['content'][0] = $author;
// Don't need to show author in My comments.
if ($view_mode_check = $event->getContexts()['view_mode']->getContextValue() != 'my_comments') {
// Render author.
$author = $this->entityTypeManager->getViewBuilder('user')->view($comment->getOwner(), 'author');
$build['content'][0] = $author;

}
}

// Render link.
$build['content'][$view_mode_check ? 1 : 0] = [
'#type' => 'link',
'#title' => $content[0]['#markup'],
'#url' => $uri,
];
// Render link.
$build['content'][$view_mode_check ? 1 : 0] = [
'#type' => 'link',
'#title' => $content[0]['#markup'],
'#url' => $uri,
];

$event->setBuild($build);
$event->setBuild($build);
}
}
}

Expand Down

0 comments on commit dc4346f

Please sign in to comment.