You are here

public function ForwardLinkBuilder::buildForwardEntityLink in Forward 8

Same name and namespace in other branches
  1. 8.3 src/ForwardLinkBuilder.php \Drupal\forward\ForwardLinkBuilder::buildForwardEntityLink()
  2. 8.2 src/ForwardLinkBuilder.php \Drupal\forward\ForwardLinkBuilder::buildForwardEntityLink()

Builds a Forward link for a given entity.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: Entity for which the link is being built.

array $settings: Array of settings.

Return value

array A render array for the link.

Overrides ForwardLinkBuilderInterface::buildForwardEntityLink

File

src/ForwardLinkBuilder.php, line 123

Class

ForwardLinkBuilder
Defines a class for building markup for a Forward link on an entity.

Namespace

Drupal\forward

Code

public function buildForwardEntityLink(EntityInterface $entity, array $settings) {
  $link = $this
    ->buildLink($entity, $settings);
  if ($settings['forward_link_inline']) {

    // Render the link inline with other node links
    $render_array = array(
      '#theme' => 'links',
      '#links' => array(
        'forward' => array(
          'url' => $link['url'],
          'title' => $link['title'],
          'attributes' => $link['attributes'],
        ),
      ),
      '#attributes' => array(
        'class' => array(
          'links',
          'inline',
        ),
      ),
      '#attached' => array(
        'library' => array(
          'forward/forward',
        ),
      ),
      '#weight' => $settings['forward_interface_weight'],
    );
  }
  else {

    // Standard render
    $render_array = array(
      '#markup' => $this->linkGenerator
        ->generate($link['title'], $link['url']),
      '#attached' => array(
        'library' => array(
          'forward/forward',
        ),
      ),
      '#weight' => $settings['forward_interface_weight'],
    );
  }
  return $render_array;
}