You are here

class ForwardLink in Forward 8

Same name in this branch
  1. 8 src/Plugin/DsField/ForwardLink.php \Drupal\forward\Plugin\DsField\ForwardLink
  2. 8 src/Plugin/views/field/ForwardLink.php \Drupal\forward\Plugin\views\field\ForwardLink
Same name and namespace in other branches
  1. 8.3 src/Plugin/DsField/ForwardLink.php \Drupal\forward\Plugin\DsField\ForwardLink
  2. 8.2 src/Plugin/DsField/ForwardLink.php \Drupal\forward\Plugin\DsField\ForwardLink

Forward link plugin.

Plugin annotation


@DsField(
  id = "forward_link",
  title = @Translation("Forward link"),
  entity_type = "node"
)

Hierarchy

Expanded class hierarchy of ForwardLink

File

src/Plugin/DsField/ForwardLink.php, line 21

Namespace

Drupal\forward\Plugin\DsField
View source
class ForwardLink extends DsFieldBase implements ContainerFactoryPluginInterface {

  /**
   * The access checker service.
   *
   * @var \Drupal\forward\ForwardAccessCheckerInterface
   */
  protected $accessChecker;

  /**
   * The link builder service.
   *
   * @var \Drupal\forward\ForwardLinkBuilderInterface
   */
  protected $linkBuilder;

  /**
   * The settings used for this plugin instance.
   *
   * @var array
   */
  protected $settings;

  /**
   * Constructs a Display Suite field plugin.
   *
   * @param array $configuration
   * @param string $plugin_id
   * @param mixed $plugin_definition
   * @param \Drupal\forward\ForwardAccessCheckerInterface $access_checker
   * @param \Drupal\forward\ForwardLinkBuilderInterface $link_builder
   * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
   */
  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;

    // Force standard render since inline render is part of the "Links" DS element
    $settings = $config_factory
      ->get('forward.settings')
      ->get();
    $settings['forward_link_inline'] = FALSE;
    $this->settings = $settings;
  }

  /**
   * @param \Symfony\Component\DependencyInjection\ContainerInterface $container
   * @param array $configuration
   * @param string $plugin_id
   * @param mixed $plugin_definition
   * @return static
   */
  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'));
  }

  /**
   * {@inheritdoc}
   */
  public function isAllowed() {
    $config = $this
      ->getConfiguration();
    $entity = isset($config['entity']) ? $this
      ->entity() : NULL;
    return $this->accessChecker
      ->isAllowed($this->settings, $entity, $this
      ->viewMode(), $this
      ->getEntityTypeId(), $this
      ->bundle());
  }

  /**
   * {@inheritdoc}
   */
  public function build() {
    $render_array = array();

    // Build the link unless Forward is rendering an email
    $config = $this
      ->getConfiguration();
    if (empty($config['build']['#forward_build'])) {
      $render_array = $this->linkBuilder
        ->buildForwardEntityLink($this
        ->entity(), $this->settings);
    }
    return $render_array;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ForwardLink::$accessChecker protected property The access checker service.
ForwardLink::$linkBuilder protected property The link builder service.
ForwardLink::$settings protected property The settings used for this plugin instance.
ForwardLink::build public function
ForwardLink::create public static function Overrides ContainerFactoryPluginInterface::create
ForwardLink::isAllowed public function
ForwardLink::__construct public function Constructs a Display Suite field plugin.