ShareEverywhereField.php in Share Everywhere 2.x
File
src/Plugin/views/field/ShareEverywhereField.php
View source
<?php
namespace Drupal\share_everywhere\Plugin\views\field;
use Drupal\views\ResultRow;
use Drupal\views\Plugin\views\field\FieldPluginBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\share_everywhere\ShareEverywhereServiceInterface;
class ShareEverywhereField extends FieldPluginBase {
protected $shareService;
public function __construct(array $configuration, $plugin_id, $plugin_definition, ShareEverywhereServiceInterface $share_service) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->shareService = $share_service;
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('share_everywhere.service'));
}
public function query() {
$this
->ensureMyTable();
$this
->addAdditionalFields();
}
public function render(ResultRow $values) {
$node = $values->_entity;
$url = $node
->toUrl()
->setAbsolute()
->toString();
$id = $node
->getEntityTypeId() . $node
->id();
return $this->shareService
->build($url, $id);
}
}