0

I want to have a page/block the last/ recent comments the logged in user has posted.

I made it in D7, but I can't seems to make it happen in D8. I googled, found article but mostly for D7 or less.

Until now I created a view of comment, made the relationship to "Comment:content" and a contextual filter on "Comment: Author" ( "When the filter value is NOT available", selected "Provide Default Value" and selected "User ID from Logged in User"). I also have a filter for the specific content type I need. But I keep on having my "NO RESULTS BEHAVIOR" showing, even though the dummy user I am checking with had comments.

EDIT:

uuid: aa49a3ff-3284-4361-9dac-c026d7f73016
langcode: en
status: true
dependencies:
  config:
    - comment.type.comment_node_locations
    - field.storage.comment.comment_body
    - field.storage.comment.field_review
    - user.role.administrator
    - user.role.authenticated
  module:
    - comment
    - node
    - starrating
    - text
    - user
    - views_infinite_scroll
id: recent_review_user_s_profile
label: 'Recent Review - User''s Profile'
module: views
description: ''
tag: ''
base_table: comment_field_data
base_field: cid
core: 8.x
display:
  default:
    display_plugin: default
    id: default
    display_title: Master
    position: 0
    display_options:
      access:
        type: role
        options:
          role:
            authenticated: authenticated
            administrator: administrator
      cache:
        type: tag
        options: {  }
      query:
        type: views_query
        options:
          disable_sql_rewrite: false
          distinct: false
          replica: false
          query_comment: ''
          query_tags: {  }
      exposed_form:
        type: basic
        options:
          submit_button: Apply
          reset_button: false
          reset_button_label: Reset
          exposed_sorts_label: 'Sort by'
          expose_sort_order: true
          sort_asc_label: Asc
          sort_desc_label: Desc
      pager:
        type: none
        options:
          items_per_page: null
          offset: 0
      style:
        type: default
      row:
        type: fields
      relationships:
        uid:
          id: uid
          table: comment_field_data
          field: uid
          relationship: none
          group_type: group
          admin_label: author
          required: true
          entity_type: comment
          entity_field: uid
          plugin_id: standard
        node:
          id: node
          table: comment_field_data
          field: node
          relationship: none
          group_type: group
          admin_label: 'Comment: Content'
          required: false
          entity_type: comment
          plugin_id: standard
      fields:
        title:
          id: title
          table: node_field_data
          field: title
          relationship: node
          group_type: group
          admin_label: ''
          label: ''
          exclude: false
          alter:
            alter_text: false
            text: ''
            make_link: false
            path: ''
            absolute: false
            external: false
            replace_spaces: false
            path_case: none
            trim_whitespace: false
            alt: ''
            rel: ''
            link_class: ''
            prefix: ''
            suffix: ''
            target: ''
            nl2br: false
            max_length: 0
            word_boundary: true
            ellipsis: true
            more_link: false
            more_link_text: ''
            more_link_path: ''
            strip_tags: false
            trim: false
            preserve_tags: ''
            html: false
          element_type: ''
          element_class: ''
          element_label_type: ''
          element_label_class: ''
          element_label_colon: false
          element_wrapper_type: ''
          element_wrapper_class: ''
          element_default_classes: true
          empty: ''
          hide_empty: false
          empty_zero: false
          hide_alter_empty: true
          click_sort_column: value
          type: string
          settings:
            link_to_entity: true
          group_column: value
          group_columns: {  }
          group_rows: true
          delta_limit: 0
          delta_offset: 0
          delta_reversed: false
          delta_first_last: false
          multi_type: separator
          separator: ', '
          field_api_classes: false
          entity_type: node
          entity_field: title
          plugin_id: field
        subject:
          id: subject
          table: comment_field_data
          field: subject
          relationship: none
          group_type: group
          admin_label: ''
          label: ''
          exclude: false
          alter:
            alter_text: false
            text: ''
            make_link: false
            path: ''
            absolute: false
            external: false
            replace_spaces: false
            path_case: none
            trim_whitespace: false
            alt: ''
            rel: ''
            link_class: ''
            prefix: ''
            suffix: ''
            target: ''
            nl2br: false
            max_length: 0
            word_boundary: false
            ellipsis: false
            more_link: false
            more_link_text: ''
            more_link_path: ''
            strip_tags: false
            trim: false
            preserve_tags: ''
            html: false
          element_type: ''
          element_class: ''
          element_label_type: ''
          element_label_class: ''
          element_label_colon: false
          element_wrapper_type: ''
          element_wrapper_class: ''
          element_default_classes: true
          empty: ''
          hide_empty: false
          empty_zero: false
          hide_alter_empty: true
          click_sort_column: value
          type: comment_permalink
          settings:
            link_to_entity: true
          group_column: value
          group_columns: {  }
          group_rows: true
          delta_limit: 0
          delta_offset: 0
          delta_reversed: false
          delta_first_last: false
          multi_type: separator
          separator: ', '
          field_api_classes: false
          entity_type: comment
          entity_field: subject
          plugin_id: field
        field_review:
          id: field_review
          table: comment__field_review
          field: field_review
          relationship: none
          group_type: group
          admin_label: ''
          label: ''
          exclude: false
          alter:
            alter_text: false
            text: ''
            make_link: false
            path: ''
            absolute: false
            external: false
            replace_spaces: false
            path_case: none
            trim_whitespace: false
            alt: ''
            rel: ''
            link_class: ''
            prefix: ''
            suffix: ''
            target: ''
            nl2br: false
            max_length: 0
            word_boundary: true
            ellipsis: true
            more_link: false
            more_link_text: ''
            more_link_path: ''
            strip_tags: false
            trim: false
            preserve_tags: ''
            html: false
          element_type: ''
          element_class: ''
          element_label_type: ''
          element_label_class: ''
          element_label_colon: false
          element_wrapper_type: ''
          element_wrapper_class: ''
          element_default_classes: true
          empty: ''
          hide_empty: false
          empty_zero: false
          hide_alter_empty: true
          click_sort_column: value
          type: starrating
          settings:
            fill_blank: 0
            icon_type: star
            icon_color: '1'
          group_column: value
          group_columns: {  }
          group_rows: true
          delta_limit: 0
          delta_offset: 0
          delta_reversed: false
          delta_first_last: false
          multi_type: separator
          separator: ', '
          field_api_classes: false
          plugin_id: field
        comment_body:
          id: comment_body
          table: comment__comment_body
          field: comment_body
          relationship: none
          group_type: group
          admin_label: ''
          label: ''
          exclude: false
          alter:
            alter_text: false
            text: ''
            make_link: false
            path: ''
            absolute: false
            external: false
            replace_spaces: false
            path_case: none
            trim_whitespace: false
            alt: ''
            rel: ''
            link_class: ''
            prefix: ''
            suffix: ''
            target: ''
            nl2br: false
            max_length: 0
            word_boundary: true
            ellipsis: true
            more_link: false
            more_link_text: ''
            more_link_path: ''
            strip_tags: false
            trim: false
            preserve_tags: ''
            html: false
          element_type: ''
          element_class: ''
          element_label_type: ''
          element_label_class: ''
          element_label_colon: false
          element_wrapper_type: ''
          element_wrapper_class: ''
          element_default_classes: true
          empty: ''
          hide_empty: false
          empty_zero: false
          hide_alter_empty: true
          click_sort_column: value
          type: text_default
          settings: {  }
          group_column: value
          group_columns: {  }
          group_rows: true
          delta_limit: 0
          delta_offset: 0
          delta_reversed: false
          delta_first_last: false
          multi_type: separator
          separator: ', '
          field_api_classes: false
          plugin_id: field
        view_node:
          id: view_node
          table: node
          field: view_node
          relationship: node
          group_type: group
          admin_label: ''
          label: ''
          exclude: false
          alter:
            alter_text: false
            text: ''
            make_link: false
            path: ''
            absolute: false
            external: false
            replace_spaces: false
            path_case: none
            trim_whitespace: false
            alt: ''
            rel: ''
            link_class: ''
            prefix: ''
            suffix: ''
            target: ''
            nl2br: true
            max_length: 0
            word_boundary: true
            ellipsis: true
            more_link: false
            more_link_text: ''
            more_link_path: ''
            strip_tags: false
            trim: false
            preserve_tags: ''
            html: false
          element_type: ''
          element_class: ''
          element_label_type: ''
          element_label_class: ''
          element_label_colon: false
          element_wrapper_type: ''
          element_wrapper_class: ''
          element_default_classes: true
          empty: ''
          hide_empty: false
          empty_zero: false
          hide_alter_empty: true
          text: 'Read more'
          output_url_as_text: false
          absolute: true
          entity_type: node
          plugin_id: entity_link
      filters:
        status:
          value: '1'
          table: comment_field_data
          field: status
          plugin_id: boolean
          entity_type: comment
          entity_field: status
          id: status
          expose:
            operator: ''
          group: 1
        status_node:
          value: '1'
          table: node_field_data
          field: status
          plugin_id: boolean
          relationship: node
          entity_type: node
          entity_field: status
          id: status_node
          expose:
            operator: ''
          group: 1
        comment_type:
          id: comment_type
          table: comment_field_data
          field: comment_type
          relationship: none
          group_type: group
          admin_label: ''
          operator: in
          value:
            comment_node_locations: comment_node_locations
          group: 1
          exposed: false
          expose:
            operator_id: ''
            label: ''
            description: ''
            use_operator: false
            operator: ''
            identifier: ''
            required: false
            remember: false
            multiple: false
            remember_roles:
              authenticated: authenticated
            reduce: false
          is_grouped: false
          group_info:
            label: ''
            description: ''
            identifier: ''
            optional: true
            widget: select
            multiple: false
            remember: false
            default_group: All
            default_group_multiple: {  }
            group_items: {  }
          entity_type: comment
          entity_field: comment_type
          plugin_id: bundle
      sorts:
        created:
          id: created
          table: comment_field_data
          field: created
          order: DESC
          entity_type: comment
          entity_field: created
          plugin_id: date
          relationship: none
          group_type: group
          admin_label: ''
          exposed: false
          expose:
            label: ''
          granularity: second
      title: 'My Reviews'
      header: {  }
      footer: {  }
      empty:
        area:
          id: area
          table: views
          field: area
          relationship: none
          group_type: group
          admin_label: ''
          empty: true
          tokenize: false
          content:
            value: "MY OOPS MESSAGE"
            format: basic_html
          plugin_id: text
      arguments: {  }
      display_extenders: {  }
    cache_metadata:
      max-age: -1
      contexts:
        - 'languages:language_content'
        - 'languages:language_interface'
        - user.roles
      tags:
        - 'config:field.storage.comment.comment_body'
        - 'config:field.storage.comment.field_review'
  block_my_reviews:
    display_plugin: block
    id: block_my_reviews
    display_title: 'Block My Reviews'
    position: 2
    display_options:
      display_extenders: {  }
      style:
        type: default
      defaults:
        style: false
        row: false
        pager: false
        use_more: false
        use_more_always: false
        use_more_text: false
      row:
        type: fields
        options:
          default_field_elements: true
          inline: {  }
          separator: ''
          hide_empty: false
      pager:
        type: some
        options:
          items_per_page: 4
          offset: 0
      use_more: true
      use_more_always: true
      use_more_text: 'View more'
      display_description: ''
    cache_metadata:
      max-age: -1
      contexts:
        - 'languages:language_content'
        - 'languages:language_interface'
        - user.roles
      tags:
        - 'config:field.storage.comment.comment_body'
        - 'config:field.storage.comment.field_review'
  page_my_reviews:
    display_plugin: page
    id: page_my_reviews
    display_title: 'Page My Reviews'
    position: 1
    display_options:
      display_extenders: {  }
      path: user/%user/my-reviews
      display_description: ''
      pager:
        type: infinite_scroll
        options:
          items_per_page: 6
          offset: 0
          id: 0
          total_pages: null
          tags:
            previous: '‹ Previous'
            next: 'Next ›'
          expose:
            items_per_page: false
            items_per_page_label: 'Items per page'
            items_per_page_options: '5, 10, 25, 50'
            items_per_page_options_all: false
            items_per_page_options_all_label: '- All -'
            offset: false
            offset_label: Offset
          views_infinite_scroll:
            button_text: 'Load More'
            automatically_load_content: false
      defaults:
        pager: false
    cache_metadata:
      max-age: -1
      contexts:
        - 'languages:language_content'
        - 'languages:language_interface'
        - url.query_args
        - user.roles
      tags:
        - 'config:field.storage.comment.comment_body'
        - 'config:field.storage.comment.field_review'
  • It sounds like it should work, maybe if you posted your Contextual filter settings? Does the View list results as expected if you remove the contextual filter? – prkos Feb 26 '19 at 16:11
  • I tried what you said and removed the Contextual filter. Now it shows ALL the comments of everyone. – Camille B. Feb 27 '19 at 8:58
  • It's obvious your contextual configuration isn't right. Can you add it to your question? – prkos Feb 27 '19 at 20:10
  • My client agree to let me export the view. – Camille B. Feb 28 '19 at 7:51
  • Thank you for the export, that is useful but alas not very readable (and can't be imported locally to test because other structure may mismatch). Could you make screenshots instead? Or simply type the options you have enabled and their values? Most importantly include the Contextual field configuration you were using, because that wasn't included in your export so I still can't say what might be wrong. – prkos Feb 28 '19 at 14:32
2

There are several issues to address here:

You have added the Author Relationship, yet it isn't necessary, neither of your fields or filters is using it. You have required it, which excludes comments from Anonymous users, but since you're already contextually filtering real users, this is unnecessary. You should remove the Author Relationship since it adds to the performance strain but doesn't add anything useful.

You have tried adding "Comment: Author" contextual filter with the "User ID from Logged in User" option, but these aren't compatible (textual name is not the same as the numerical ID).
You need to add "Comment: Author uid" Contextual instead and configure it:
When the filter value is NOT available
Provide default value
User ID from logged in user
When the filter value IS available or a default is provided
Specify validation criteria
User ID
Single ID
Configure other options to your needs.

This will show the current logged in user comments.

But I also see your path is user/%user/my-reviews. Does this mean you want to show the related user comments there, and not always the logged-in user's no matter which profile they're viewing?
If so, then you need to use the User ID from route context option instead of the "User ID from logged in user".

| improve this answer | |
  • I'm glad to help :) You can accept the answer if it solved your question. – prkos Mar 1 '19 at 16:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.