Commit 0ecb96a2 authored by Eleo Basili's avatar Eleo Basili
Browse files

Issue #3262662 by eleonel: Views integration

parent f1968fc1
Loading
Loading
Loading
Loading
+282 −0
Original line number Diff line number Diff line
<?php

/**
 * @file
 * Provide views data for ayrshare_node.module.
 */

/**
 * Implements hook_views_data().
 */
function ayrshare_node_views_data() {
  $data = [];

  // Ayrshare Pos Base data.
  $data['ayrshare_post']['table']['group'] = t('Ayrshare Post');
  $data['ayrshare_post']['table']['base'] = [
    'title' => t('Ayrshare Post'),
    'help' => t('Ayrshare Post data from ayrshare_post DB table.'),
  ];

  // Ayrshare Pos Fields.
  $data['ayrshare_post']['id'] = [
    'title' => t('Entry ID'),
    'help' => t('Entry ID.'),
    'field' => [
      'id' => 'numeric',
    ],
    'sort' => [
      'id' => 'standard',
    ],
    'filter' => [
      'id' => 'numeric',
    ],
  ];

  $data['ayrshare_post']['pid'] = [
    'title' => t('Post ID'),
    'help' => t('Post entry ID.'),
    'field' => [
      'id' => 'standard',
    ],
    'sort' => [
      'id' => 'standard',
    ],
    'filter' => [
      'id' => 'string',
    ],
  ];

  $data['ayrshare_post']['tid'] = [
    'title' => t('Top Level ID'),
    'help' => t('Top Level entry ID.'),
    'field' => [
      'id' => 'standard',
    ],
    'sort' => [
      'id' => 'standard',
    ],
    'filter' => [
      'id' => 'string',
    ],
  ];

  $data['ayrshare_post']['nid'] = [
    'title' => t('Node ID'),
    'help' => t('The node ID.'),
    'field' => [
      'id' => 'standard',
    ],
    'sort' => [
      'id' => 'standard',
    ],
    'filter' => [
      'id' => 'numeric',
    ],
    'argument' => [
      'id' => 'numeric',
    ],
    'relationship' => [
      'title' => t('Node'),
      'help' => t('The node entity used in the Post.'),
      'base' => 'node',
      'base field' => 'nid',
      'id' => 'standard',
    ],
  ];

  // Ayrshare Comment Base data.
  $data['ayrshare_comment']['table']['group'] = t('Ayrshare Comment');
  $data['ayrshare_comment']['table']['base'] = [
    'title' => t('Ayrshare Comment'),
    'help' => t('Ayrshare Comment data from ayrshare_comment DB table.'),
  ];

  // Ayrshare Comment Fields.
  $data['ayrshare_comment']['id'] = [
    'title' => t('Entry ID'),
    'help' => t('Entry ID.'),
    'field' => [
      'id' => 'numeric',
    ],
    'sort' => [
      'id' => 'standard',
    ],
    'filter' => [
      'id' => 'numeric',
    ],
  ];

  $data['ayrshare_comment']['cid'] = [
    'title' => t('Comment ID'),
    'help' => t('Comment entry ID.'),
    'field' => [
      'id' => 'standard',
    ],
    'sort' => [
      'id' => 'standard',
    ],
    'filter' => [
      'id' => 'string',
    ],
  ];

  $data['ayrshare_comment']['tid'] = [
    'title' => t('Top Level ID'),
    'help' => t('Top Level entry ID.'),
    'field' => [
      'id' => 'standard',
    ],
    'sort' => [
      'id' => 'standard',
    ],
    'filter' => [
      'id' => 'string',
    ],
  ];

  $data['ayrshare_comment']['nid'] = [
    'title' => t('Node ID'),
    'help' => t('The node ID.'),
    'field' => [
      'id' => 'standard',
    ],
    'sort' => [
      'id' => 'standard',
    ],
    'filter' => [
      'id' => 'numeric',
    ],
    'argument' => [
      'id' => 'numeric',
    ],
    'relationship' => [
      'title' => t('Node'),
      'help' => t('The node entity used in the Post.'),
      'base' => 'node',
      'base field' => 'nid',
      'id' => 'standard',
    ],
  ];

  $data['ayrshare_comment']['comment'] = [
    'title' => t('Comment'),
    'help' => t('The comment content.'),
    'field' => [
      'id' => 'standard',
    ],
    'filter' => [
      'id' => 'string',
    ],
  ];

  $data['ayrshare_comment']['from'] = [
    'title' => t('From'),
    'help' => t('The author information.'),
    'field' => [
      'id' => 'ayrshare_unserialized_data',
    ],
    'filter' => [
      'id' => 'string',
    ],
  ];

  $data['ayrshare_comment']['created'] = [
    'title' => t('Creation Date Time'),
    'help' => t('The creation date from the comment entry.'),
    'field' => [
      'id' => 'date',
      'click sortable' => TRUE,
    ],
    'filter' => [
      'id' => 'date',
    ],
  ];

  // Ayrshare Analytics Base data.
  $data['ayrshare_analytics']['table']['group'] = t('Ayrshare Analytics');
  $data['ayrshare_analytics']['table']['base'] = [
    'title' => t('Ayrshare Analytics'),
    'help' => t('Ayrshare Analytics data from ayrshare_analytics DB table.'),
  ];

  // Ayrshare Analytics Fields.
  $data['ayrshare_analytics']['id'] = [
    'title' => t('Entry ID'),
    'help' => t('Entry ID.'),
    'field' => [
      'id' => 'numeric',
    ],
    'sort' => [
      'id' => 'standard',
    ],
    'filter' => [
      'id' => 'numeric',
    ],
  ];

  $data['ayrshare_analytics']['pid'] = [
    'title' => t('Analytics ID'),
    'help' => t('Analytics entry ID.'),
    'field' => [
      'id' => 'standard',
    ],
    'sort' => [
      'id' => 'standard',
    ],
    'filter' => [
      'id' => 'string',
    ],
  ];

  $data['ayrshare_analytics']['tid'] = [
    'title' => t('Top Level ID'),
    'help' => t('Top Level entry ID.'),
    'field' => [
      'id' => 'standard',
    ],
    'sort' => [
      'id' => 'standard',
    ],
    'filter' => [
      'id' => 'string',
    ],
  ];

  $data['ayrshare_analytics']['nid'] = [
    'title' => t('Node ID'),
    'help' => t('The node ID.'),
    'field' => [
      'id' => 'standard',
    ],
    'sort' => [
      'id' => 'standard',
    ],
    'filter' => [
      'id' => 'numeric',
    ],
    'argument' => [
      'id' => 'numeric',
    ],
    'relationship' => [
      'title' => t('Node'),
      'help' => t('The node entity used in the Analytics.'),
      'base' => 'node',
      'base field' => 'nid',
      'id' => 'standard',
    ],
  ];

  $data['ayrshare_analytics']['data'] = [
    'title' => t('Data'),
    'help' => t('The analytics data information.'),
    'field' => [
      'id' => 'ayrshare_unserialized_data',
    ],
    'filter' => [
      'id' => 'string',
    ],
  ];

  return $data;
}
+385 −0
Original line number Diff line number Diff line
langcode: en
status: true
dependencies:
  module:
    - ayrshare_node
id: ayshare_analytics
label: "Ayshare Analytics"
module: views
description: "Shows real-time analytical data for posts, such as clicks, likes, shares, and impressions."
tag: ""
base_table: ayrshare_analytics
base_field: ""
display:
  default:
    id: default
    display_title: Default
    display_plugin: default
    position: 0
    display_options:
      fields:
        id:
          id: id
          table: ayrshare_analytics
          field: id
          relationship: none
          group_type: group
          admin_label: ""
          entity_type: null
          entity_field: null
          plugin_id: numeric
          label: "Entry ID"
          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: true
          element_wrapper_type: ""
          element_wrapper_class: ""
          element_default_classes: true
          empty: ""
          hide_empty: false
          empty_zero: false
          hide_alter_empty: true
          set_precision: false
          precision: 0
          decimal: .
          separator: ","
          format_plural: false
          format_plural_string: !!binary MQNAY291bnQ=
          prefix: ""
          suffix: ""
        pid:
          id: pid
          table: ayrshare_analytics
          field: pid
          relationship: none
          group_type: group
          admin_label: ""
          plugin_id: standard
          label: "Post ID"
          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: true
          element_wrapper_type: ""
          element_wrapper_class: ""
          element_default_classes: true
          empty: ""
          hide_empty: false
          empty_zero: false
          hide_alter_empty: true
        tid:
          id: tid
          table: ayrshare_analytics
          field: tid
          relationship: none
          group_type: group
          admin_label: ""
          plugin_id: standard
          label: "Top Level ID"
          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: true
          element_wrapper_type: ""
          element_wrapper_class: ""
          element_default_classes: true
          empty: ""
          hide_empty: false
          empty_zero: false
          hide_alter_empty: true
        data:
          id: data
          table: ayrshare_analytics
          field: data
          relationship: none
          group_type: group
          admin_label: ""
          plugin_id: standard
          label: Data
          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: pre
          element_class: ""
          element_label_type: ""
          element_label_class: ""
          element_label_colon: true
          element_wrapper_type: ""
          element_wrapper_class: ""
          element_default_classes: true
          empty: ""
          hide_empty: false
          empty_zero: false
          hide_alter_empty: true
      pager:
        type: mini
        options:
          offset: 0
          items_per_page: 10
          total_pages: null
          id: 0
          tags:
            next: ››
            previous: ‹‹
          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
      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
      access:
        type: none
        options: {}
      cache:
        type: tag
        options: {}
      empty: {}
      sorts: {}
      arguments:
        nid:
          id: nid
          table: ayrshare_analytics
          field: nid
          relationship: none
          group_type: group
          admin_label: ""
          plugin_id: numeric
          default_action: default
          exception:
            value: all
            title_enable: false
            title: All
          title_enable: false
          title: ""
          default_argument_type: node
          default_argument_options: {}
          default_argument_skip_url: false
          summary_options:
            base_path: ""
            count: true
            override: false
            items_per_page: 25
          summary:
            sort_order: asc
            number_of_records: 0
            format: default_summary
          specify_validation: false
          validate:
            type: none
            fail: "not found"
          validate_options: {}
          break_phrase: false
          not: false
      filters: {}
      style:
        type: table
        options:
          grouping: {}
          row_class: ""
          default_row_class: true
          columns:
            id: id
            pid: pid
            data: data
            tid: tid
          default: "-1"
          info:
            id:
              sortable: false
              default_sort_order: asc
              align: ""
              separator: ""
              empty_column: false
              responsive: ""
            pid:
              sortable: false
              default_sort_order: asc
              align: ""
              separator: ""
              empty_column: false
              responsive: ""
            data:
              sortable: false
              default_sort_order: asc
              align: ""
              separator: ""
              empty_column: false
              responsive: ""
            tid:
              sortable: false
              default_sort_order: asc
              align: ""
              separator: ""
              empty_column: false
              responsive: ""
          override: true
          sticky: false
          summary: ""
          empty_table: false
          caption: ""
          description: ""
      row:
        type: fields
        options:
          default_field_elements: true
          inline: {}
          separator: ""
          hide_empty: false
      query:
        type: views_query
        options:
          query_comment: ""
          disable_sql_rewrite: false
          distinct: false
          replica: false
          query_tags: {}
      relationships: {}
      header: {}
      footer: {}
      display_extenders: {}
    cache_metadata:
      max-age: -1
      contexts:
        - "languages:language_interface"
        - url
        - url.query_args
      tags: {}
  ayrshare_analytics_block:
    id: ayrshare_analytics_block
    display_title: Block
    display_plugin: block
    position: 1
    display_options:
      display_extenders: {}
    cache_metadata:
      max-age: -1
      contexts:
        - "languages:language_interface"
        - url
        - url.query_args
      tags: {}
+442 −0

File added.

Preview size limit exceeded, changes collapsed.

+336 −0

File added.

Preview size limit exceeded, changes collapsed.

+27 −0
Original line number Diff line number Diff line
<?php

namespace Drupal\ayrshare_node\Plugin\views\field;

use Drupal\views\Plugin\views\field\FieldPluginBase;
use Drupal\views\ResultRow;

/**
 * Field handler to present serialized data in Json format.
 *
 * @group views_field_handlers
 *
 * @ViewsField("ayrshare_unserialized_data")
 */
class UnserializedData extends FieldPluginBase {

  /**
   * {@inheritdoc}
   */
  public function render(ResultRow $values) {
    $value = unserialize($this->getValue($values));
    return json_encode($value,
      JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE
    );
  }

}