summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorgit2016-06-15 18:06:05 -0700
committermicropat2016-06-15 18:06:05 -0700
commitc6b1844e78ed2326c253832455a36eae6326ddb6 (patch)
treef24082c32e43a1bb30f51192f1cf5d88d8f74205
parent815acaf457f03d3a6af6dc3d455efec53a01c102 (diff)
Issue #2739096 by sitiveni: Views support, and minor changes
-rw-r--r--addtoany.views.inc21
-rw-r--r--src/Plugin/views/field/NodeAddToAnyShare.php41
-rw-r--r--views/addtoany.views.inc23
3 files changed, 62 insertions, 23 deletions
diff --git a/addtoany.views.inc b/addtoany.views.inc
new file mode 100644
index 0000000..8956e61
--- /dev/null
+++ b/addtoany.views.inc
@@ -0,0 +1,21 @@
+<?php
+
+/**
+ * @file
+ * Views integration for AddToAny.
+ */
+
+/**
+ * Implementation of hook_views_data_alter().
+ */
+function addtoany_views_data_alter(array &$data) {
+ // Add the addtoany link to the node fields
+ $data['node']['addtoany_share'] = array(
+ 'title' => t('AddToAny share buttons'),
+ 'field' => array(
+ 'title' => t('AddToAny share buttons'),
+ 'help' => t('Provide share buttons for sharing the content.'),
+ 'id' => 'node_addtoany_share',
+ ),
+ );
+}
diff --git a/src/Plugin/views/field/NodeAddToAnyShare.php b/src/Plugin/views/field/NodeAddToAnyShare.php
new file mode 100644
index 0000000..926573d
--- /dev/null
+++ b/src/Plugin/views/field/NodeAddToAnyShare.php
@@ -0,0 +1,41 @@
+<?php
+
+/**
+ * @file
+ * Definition of Drupal\addtoany\Plugin\views\field\NodeAddToAnyShare
+ */
+
+namespace Drupal\addtoany\Plugin\views\field;
+
+use Drupal\views\Plugin\views\field\FieldPluginBase;
+use Drupal\views\ResultRow;
+
+/**
+* Field handler to flag the node type.
+*
+* @ingroup views_field_handlers
+*
+* @ViewsField("node_addtoany_share")
+*/
+class NodeAddToAnyShare extends FieldPluginBase {
+
+ /**
+ * @{inheritdoc}
+ */
+ public function query() {
+ // Leave empty to avoid a query on this field.
+ }
+
+ /**
+ * @{inheritdoc}
+ */
+ public function render(ResultRow $values) {
+ $entity = $values->_entity;
+ if ($entity->access('view')) {
+ return array(
+ '#theme' => 'addtoany_standard',
+ '#addtoany_html' => addtoany_create_node_buttons($entity),
+ );
+ }
+ }
+}
diff --git a/views/addtoany.views.inc b/views/addtoany.views.inc
deleted file mode 100644
index aceffa6..0000000
--- a/views/addtoany.views.inc
+++ /dev/null
@@ -1,23 +0,0 @@
-<?php
-
-/**
- * @file
- * Views integration for AddToAny.
- */
-
-/**
- * Implementation of hook_views_data().
- */
-function addtoany_views_data() {
- // Add the addtoany link to the node fields
- $data['node']['addtoany_link'] = array(
- 'title' => t('AddToAny link'),
- 'help' => t('Link provided by the AddToAny module'),
- 'group' => t('Content'),
- 'field' => array(
- 'handler' => 'addtoany_handler_field_addtoany_link',
- 'click sortable' => FALSE,
- )
- );
- return $data;
-}