SharethisNode.php in ShareThis 8.2
File
src/Plugin/views/field/SharethisNode.php
View source
<?php
namespace Drupal\sharethis\Plugin\views\field;
use Drupal\sharethis\SharethisManagerInterface;
use Drupal\views\ResultRow;
use Drupal\views\Plugin\views\field\FieldPluginBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
class SharethisNode extends FieldPluginBase {
protected $sharethisManager;
public function __construct(array $configuration, $plugin_id, $plugin_definition, SharethisManagerInterface $sharethis_manager) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->sharethisManager = $sharethis_manager;
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('sharethis.manager'));
}
public function query() {
$this
->ensureMyTable();
$this
->addAdditionalFields();
}
public function render(ResultRow $values) {
$sharethis_manager = $this->sharethisManager;
$node = $values->_entity;
$m_title = $node
->getTitle();
$m_path = $node
->toUrl()
->setAbsolute()
->toString();
$data_options = $sharethis_manager
->getOptions();
$st_js = $sharethis_manager
->sharethisIncludeJs();
$content = $sharethis_manager
->renderSpans($data_options, $m_title, $m_path);
return [
'#theme' => 'sharethis_block',
'#content' => $content,
'#attached' => [
'library' => [
'sharethis/sharethispickerexternalbuttonsws',
'sharethis/sharethispickerexternalbuttons',
'sharethis/sharethis',
],
'drupalSettings' => [
'sharethis' => $st_js,
],
],
];
}
}