New answers tagged

0

Create Template Preprocess Comment in your Theme file function template_preprocess_comment(&$variables) { $comment = $variables['elements']['#comment']; $account = $comment->getOwner(); $variables['user_picture'] = file_create_url($account->user_picture->entity->getFileUri()); }


2

You can do it using hook_preprocess_HOOK The following hooks should be placed in YOURTHEME.theme file: Remove comment links from node for Anonymous user: /** * Implements hook_preprocess_HOOK(). */ function YOURTHEME_preprocess_links__node(&$variables) { if (\Drupal::currentUser()->isAnonymous()) { unset($variables['links']['...


1

Twig's date extension does exactly what you ask: {{ created | time_diff }} However, this extension isn't in Drupal by default, assuming you're using Composer you need to add this extension to your project by running: composer require twig/extensions


1

I'm going to assume here that field_last_name is a field you added yourself to the account fields. I tested using just the user name, and got it to work fine using the following relationships (starting from a Node): From the node to all comments: was called "Comments of the node using field: comment" here And then from the comment to the author: just called ...


0

use this to create the field in your custum module: $fields['comments'] = BaseFieldDefinition::create('comment') ->setLabel(t('comment')) ->setDescription(t('Add new comment')) ->setSettings( array( 'default_mode'=> 1, 'per_page'=>50, 'anonymous'=> 0, 'form_location'=>1, ...


0

So the node in question had a field field_comments, from which I was trying to access the comments. I found a different way of doing that - I created a MYMODULE_preprocess_template function, loaded all comments of the node in that function, created a variable "comments", where I stored the comment data I needed and passed it on to the twig template. Here's ...


1

You must add a file to your template called field--comment.html.twig Use the following code. {# /** * @file * Theme override for comment fields. * * Available variables: * - attributes: HTML attributes for the containing element. * - label_hidden: Whether to show the field label or not. * - title_attributes: HTML attributes for the title. * - ...


Top 50 recent answers are included