You are here

public function EntityPrintPdf::getShareLink in Social simple 8

Same name and namespace in other branches
  1. 2.0.x src/SocialNetwork/EntityPrintPdf.php \Drupal\social_simple\SocialNetwork\EntityPrintPdf::getShareLink()

Checks whether the given transition is allowed.

Parameters

string $share_url: The url to share.

string $title: The page's title to share.

\Drupal\Core\Entity\EntityInterface $entity: The parent entity.

array $additional_options: Additional options to pass as que query parameter to the social link.

Return value

array the renderable array of the social share link.

Overrides SocialNetworkInterface::getShareLink

File

src/SocialNetwork/EntityPrintPdf.php, line 73

Class

EntityPrintPdf
The social network Twitter.

Namespace

Drupal\social_simple\SocialNetwork

Code

public function getShareLink($share_url, $title = '', EntityInterface $entity = NULL, array $additional_options = []) {
  $link = [
    'url' => Url::fromUserInput('#'),
    'title' => [
      '#markup' => '<i class="fa fa-file-pdf-o"></i><span class="visually-hidden">' . $this
        ->getLabel() . '</span>',
    ],
    'attributes' => [
      'style' => 'display: none;',
    ],
  ];
  if (!$this->moduleHandler
    ->moduleExists('entity_print')) {
    return $link;
  }
  if (!$entity instanceof ContentEntityInterface) {
    return $link;
  }
  $entity_type_id = $entity
    ->getEntityTypeId();
  $entity_id = $entity
    ->id();
  $enabled_entity_type_ids = $this->configFactory
    ->get('entity_print.settings')
    ->get('enabled_entity_type_ids');
  if (!empty($enabled_entity_type_ids) && !in_array($entity_type_id, $enabled_entity_type_ids)) {
    return $link;
  }
  $route_params = [
    'entity_type' => $entity_type_id,
    'entity_id' => $entity_id,
    'export_type' => trim(self::ENTITY_PRINT_EXPORT_TYPE, '_engine'),
  ];
  $options = [];
  if ($additional_options) {
    foreach ($additional_options as $id => $value) {
      $options['query'][$id] = $value;
    }
  }
  $url = Url::fromRoute(self::ENTITY_PRINT_ROUTE, $route_params, $options);
  $link = [
    'url' => $url,
    'title' => [
      '#markup' => '<i class="fa fa-file-pdf-o"></i><span class="visually-hidden">' . $this
        ->getLabel() . '</span>',
    ],
    'attributes' => $this
      ->getLinkAttributes($this
      ->getLabel()),
  ];
  return $link;
}