ForwardLink.php in Forward 8
File
src/Plugin/views/field/ForwardLink.php
View source
<?php
namespace Drupal\forward\Plugin\views\field;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\ds\Plugin\DsField\DsFieldBase;
use Drupal\forward\ForwardAccessCheckerInterface;
use Drupal\forward\ForwardLinkBuilderInterface;
use Drupal\views\Plugin\views\field\FieldPluginBase;
use Drupal\views\ResultRow;
use Symfony\Component\DependencyInjection\ContainerInterface;
class ForwardLink extends FieldPluginBase implements ContainerFactoryPluginInterface {
protected $accessChecker;
protected $linkBuilder;
protected $settings;
public function __construct($configuration, $plugin_id, $plugin_definition, ForwardAccessCheckerInterface $access_checker, ForwardLinkBuilderInterface $link_builder, ConfigFactoryInterface $config_factory) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->accessChecker = $access_checker;
$this->linkBuilder = $link_builder;
$settings = $config_factory
->get('forward.settings')
->get();
$settings['forward_link_inline'] = FALSE;
$this->settings = $settings;
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('forward.access_checker'), $container
->get('forward.link_builder'), $container
->get('config.factory'));
}
public function query() {
}
protected function defineOptions() {
$options = parent::defineOptions();
return $options;
}
public function render(ResultRow $values) {
$view_mode = FALSE;
if ($this->accessChecker
->isAllowed($this->settings, $values->_entity, $view_mode)) {
return $this->linkBuilder
->buildForwardEntityLink($values->_entity, $this->settings);
}
}
}