Skip to content

Commit

Permalink
Merge pull request linnovate#101 from istolar/OI-26-comments
Browse files Browse the repository at this point in the history
OI 26,73 comments
  • Loading branch information
db-Matroskeen authored Jul 23, 2020
2 parents 47ccabe + dc4346f commit ed2d5cb
Show file tree
Hide file tree
Showing 13 changed files with 257 additions and 63 deletions.
2 changes: 1 addition & 1 deletion config/install/block.block.main_sites_logan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ settings:
id: 'block_content:3ed7eeba-0dcc-45a5-9ade-c53cacbc3c0e'
label: 'Main site slogan'
provider: block_content
label_display: visible
label_display: '0'
status: true
info: ''
view_mode: full
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
langcode: en
status: true
dependencies:
config:
- comment.type.comment
- core.entity_view_mode.comment.my_comments
- field.field.comment.comment.comment_body
- field.field.comment.comment.field_like
module:
- layout_builder
- layout_discovery
- text
third_party_settings:
layout_builder:
allow_custom: false
enabled: true
sections:
-
layout_id: layout_onecol
layout_settings:
label: ''
components:
0e788d62-3fc4-4e5f-bad4-82478de5be0e:
uuid: 0e788d62-3fc4-4e5f-bad4-82478de5be0e
region: content
configuration:
label_display: '0'
context_mapping:
entity: layout_builder.entity
id: 'field_block:comment:comment:comment_body'
formatter:
label: hidden
type: text_default
settings: { }
third_party_settings: { }
additional: { }
weight: 1
ce734f7b-401c-4fa0-921e-fea307f8ef82:
uuid: ce734f7b-401c-4fa0-921e-fea307f8ef82
region: content
configuration:
id: 'field_block:comment:comment:created'
label: Created
provider: layout_builder
label_display: '0'
formatter:
label: hidden
type: timestamp_ago
settings:
future_format: '@interval hence'
past_format: '@interval ago'
granularity: 2
third_party_settings: { }
context_mapping:
entity: layout_builder.entity
view_mode: view_mode
additional: { }
weight: 0
third_party_settings: { }
id: comment.comment.my_comments
targetEntityType: comment
bundle: comment
mode: my_comments
content:
comment_body:
label: hidden
type: text_default
weight: 0
region: content
settings: { }
third_party_settings: { }
hidden:
field_like: true
links: true
23 changes: 13 additions & 10 deletions config/install/core.entity_view_display.node.idea.teaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,34 +26,37 @@ content:
body:
label: hidden
type: text_summary_or_trimmed
weight: 101
weight: 1
settings:
trim_length: 600
third_party_settings: { }
region: content
content_moderation_control:
weight: -20
settings: { }
third_party_settings: { }
field_idea_phase:
type: entity_reference_label
weight: 2
region: content
label: above
settings:
link: true
third_party_settings: { }
flag_follow:
weight: 10
weight: 3
region: content
settings: { }
third_party_settings: { }
region: content
links:
weight: 100
weight: 0
region: content
settings: { }
third_party_settings: { }
region: content
hidden:
addtoany: true
content_moderation_control: true
field_attached_docs: true
field_category: true
field_challenge: true
field_comments: true
field_duplicate_of: true
field_idea_phase: true
field_idea_tags: true
field_images: true
field_like: true
Expand Down
9 changes: 9 additions & 0 deletions config/install/core.entity_view_mode.comment.my_comments.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
langcode: en
status: true
dependencies:
module:
- comment
id: comment.my_comments
label: 'My comments'
targetEntityType: comment
cache: true
5 changes: 5 additions & 0 deletions config/install/views.view.my_comments.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
langcode: en
status: true
dependencies:
config:
- core.entity_view_mode.comment.my_comments
module:
- comment
- node
Expand Down Expand Up @@ -53,6 +55,9 @@ display:
type: default
row:
type: 'entity:comment'
options:
relationship: none
view_mode: my_comments
relationships:
node:
id: node
Expand Down
13 changes: 0 additions & 13 deletions config/install/views.view.user_content.yml
Original file line number Diff line number Diff line change
Expand Up @@ -458,19 +458,6 @@ display:
entity_type: group_content
plugin_id: group_content_to_entity
filters:
status:
value: '1'
table: node_field_data
field: status
plugin_id: boolean
entity_type: node
entity_field: status
id: status
expose:
operator: ''
operator_limit_selection: false
operator_list: { }
group: 1
group_roles_target_id_1:
id: group_roles_target_id_1
table: group_content__group_roles
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,30 +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(),
]);

// 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'][] = [
'#type' => 'link',
'#title' => $content[0]['#markup'],
'#url' => $uri,
];
}

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

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

Expand Down
36 changes: 19 additions & 17 deletions modules/openideal_comment/src/OpenidealCommentViewBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,25 @@ public function buildComponents(array &$build, array $entities, array $displays,
* {@inheritdoc}
*/
protected function alterBuild(array &$build, EntityInterface $comment, EntityViewDisplayInterface $display, $view_mode) {
parent::alterBuild($build, $comment, $display, $view_mode);
// Change default drupal comments behaviour
// to wrap thread and "main" comment together.
if (empty($comment->in_preview)) {
// If comment has parent then nothing to do here.
if (!$comment->hasParentComment()) {
// Check if it's not the first comment.
$closing_div = isset($this->previousIntent) ? '</div>' : '';
// Open thread.
$build['#prefix'] .= $closing_div . '<div class="comments--thread card">';
}

// Need to keep in memory last intent.
$this->previousIntent = $build['#comment_indent'];

if (isset($build['#comment_section_end'])) {
$build['#suffix'] = isset($build['#suffix']) ? ($build['#suffix'] . '</div>') : '</div>';
if ($view_mode == 'default') {
parent::alterBuild($build, $comment, $display, $view_mode);
// Change default drupal comments behaviour
// to wrap thread and "main" comment together.
if (empty($comment->in_preview)) {
// If comment has parent then nothing to do here.
if (!$comment->hasParentComment()) {
// Check if it's not the first comment.
$closing_div = isset($this->previousIntent) ? '</div>' : '';
// Open thread.
$build['#prefix'] .= $closing_div . '<div class="comments--thread card">';
}

// Need to keep in memory last intent.
$this->previousIntent = $build['#comment_indent'];

if (isset($build['#comment_section_end'])) {
$build['#suffix'] = isset($build['#suffix']) ? ($build['#suffix'] . '</div>') : '</div>';
}
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion themes/openideal_theme/css/style.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion themes/openideal_theme/css/style.min.css

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions themes/openideal_theme/scss/components/_comments.scss
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@
}
}

.my-comments-single-comment {
padding: 15px;
margin-bottom: 8px;
}

.comment-comment-form .form-actions {
display: inline-flex;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
{#
/**
* @file
* Default theme implementation for comments.
*
* Available variables:
* - author: Comment author. Can be a link or plain text.
* - content: The content-related items for the comment display. Use
* {{ content }} to print them all, or print a subset such as
* {{ content.field_example }}. Use the following code to temporarily suppress
* the printing of a given child element:
* @code
* {{ content|without('field_example') }}
* @endcode
* - created: Formatted date and time for when the comment was created.
* Preprocess functions can reformat it by calling DateFormatter::format()
* with the desired parameters on the 'comment.created' variable.
* - changed: Formatted date and time for when the comment was last changed.
* Preprocess functions can reformat it by calling DateFormatter::format()
* with the desired parameters on the 'comment.changed' variable.
* - permalink: Comment permalink.
* - submitted: Submission information created from author and created
* during template_preprocess_comment().
* - user_picture: The comment author's profile picture.
* - status: Comment status. Possible values are:
* unpublished, published, or preview.
* - title: Comment title, linked to the comment.
* - attributes: HTML attributes for the containing element.
* The attributes.class may contain one or more of the following classes:
* - comment: The current template type; for instance, 'theming hook'.
* - by-anonymous: Comment by an unregistered user.
* - by-{entity-type}-author: Comment by the author of the parent entity,
* eg. by-node-author.
* - preview: When previewing a new or edited comment.
* The following applies only to viewers who are registered users:
* - unpublished: An unpublished comment visible only to administrators.
* - title_prefix: Additional output populated by modules, intended to be
* displayed in front of the main title tag that appears in the template.
* - title_suffix: Additional output populated by modules, intended to be
* displayed after the main title tag that appears in the template.
* - content_attributes: List of classes for the styling of the comment content.
* - title_attributes: Same as attributes, except applied to the main title
* tag that appears in the template.
* - threaded: A flag indicating whether the comments are threaded or not.
*
* These variables are provided to give context about the parent comment (if
* any):
* - parent_comment: Full parent comment entity (if any).
* - parent_author: Equivalent to author for the parent comment.
* - parent_created: Equivalent to created for the parent comment.
* - parent_changed: Equivalent to changed for the parent comment.
* - parent_title: Equivalent to title for the parent comment.
* - parent_permalink: Equivalent to permalink for the parent comment.
* - parent: A text string of parent comment submission information created from
* 'parent_author' and 'parent_created' during template_preprocess_comment().
* This information is presented to help screen readers follow lengthy
* discussion threads. You can hide this from sighted users using the class
* visually-hidden.
*
* These two variables are provided for context:
* - comment: Full comment object.
* - entity: Entity the comments are attached to.
*
* @see template_preprocess_comment()
*
* @ingroup themeable
*/
#}

<article{{ attributes.addClass('js-comment', 'single-comment card my-comments-single-comment') }}>
<div class="single-comment--inner">

{#
Hide the "new" indicator by default, let a piece of JavaScript ask the
server which comments are new for the user. Rendering the final "new"
indicator here would break the render cache.
#}
<mark class="hidden" data-comment-timestamp="{{ new_indicator_timestamp }}"></mark>

<footer>
{{ user_picture }}

{#
Indicate the semantic relationship between parent and child comments for
accessibility. The list is difficult to navigate in a screen reader
without this information.
#}

{% if parent %}
<p class="visually-hidden">{{ parent }}</p>
{% endif %}

</footer>

<div{{ content_attributes }}>
{{ content }}
</div>
</div>
</article>

0 comments on commit ed2d5cb

Please sign in to comment.