class EntityPrintPdf in Social simple 8
Same name and namespace in other branches
- 2.0.x src/SocialNetwork/EntityPrintPdf.php \Drupal\social_simple\SocialNetwork\EntityPrintPdf
 
The social network Twitter.
Hierarchy
- class \Drupal\social_simple\SocialNetwork\EntityPrintPdf implements SocialNetworkInterface uses StringTranslationTrait
 
Expanded class hierarchy of EntityPrintPdf
1 string reference to 'EntityPrintPdf'
1 service uses EntityPrintPdf
File
- src/
SocialNetwork/ EntityPrintPdf.php, line 15  
Namespace
Drupal\social_simple\SocialNetworkView source
class EntityPrintPdf implements SocialNetworkInterface {
  use StringTranslationTrait;
  /**
   * The entity print view route.
   */
  const ENTITY_PRINT_ROUTE = 'entity_print.view';
  /**
   * The export type engine.
   */
  const ENTITY_PRINT_EXPORT_TYPE = 'pdf';
  /**
   * Drupal\Core\Config\ConfigFactoryInterface definition.
   *
   * @var \Drupal\Core\Config\ConfigFactoryInterface
   */
  protected $configFactory;
  /**
   * Drupal\Core\Extension\ModuleHandlerInterface
   *
   * @var \Drupal\Core\Extension\ModuleHandlerInterface
   */
  protected $moduleHandler;
  /**
   * Constructs a new Entity Print Pdf object.
   *
   * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
   *   The config factory.
   * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
   *   The module handler service.
   */
  public function __construct(ConfigFactoryInterface $config_factory, ModuleHandlerInterface $module_handler) {
    $this->configFactory = $config_factory;
    $this->moduleHandler = $module_handler;
  }
  /**
   * {@inheritdoc}
   */
  public function getId() {
    return 'entity_print_pdf';
  }
  /**
   * {@inheritdoc}
   */
  public function getLabel() {
    return $this
      ->t('PDF');
  }
  /**
   * {@inheritdoc}
   */
  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;
  }
  /**
   * {@inheritdoc}
   */
  public function getLinkAttributes($network_name) {
    $attributes = [
      'title' => $network_name,
      'target' => '_blank',
      'rel' => 'noopener noreferrer nofollow',
    ];
    return $attributes;
  }
}Members
| 
            Name | 
                  Modifiers | Type | Description | Overrides | 
|---|---|---|---|---|
| 
            EntityPrintPdf:: | 
                  protected | property | Drupal\Core\Config\ConfigFactoryInterface definition. | |
| 
            EntityPrintPdf:: | 
                  protected | property | Drupal\Core\Extension\ModuleHandlerInterface | |
| 
            EntityPrintPdf:: | 
                  constant | The export type engine. | ||
| 
            EntityPrintPdf:: | 
                  constant | The entity print view route. | ||
| 
            EntityPrintPdf:: | 
                  public | function | 
            Get the network id. Overrides SocialNetworkInterface:: | 
                  |
| 
            EntityPrintPdf:: | 
                  public | function | 
            Get the network name. Overrides SocialNetworkInterface:: | 
                  |
| 
            EntityPrintPdf:: | 
                  public | function | 
            Get common attributes for the share link. Overrides SocialNetworkInterface:: | 
                  |
| 
            EntityPrintPdf:: | 
                  public | function | 
            Checks whether the given transition is allowed. Overrides SocialNetworkInterface:: | 
                  |
| 
            EntityPrintPdf:: | 
                  public | function | Constructs a new Entity Print Pdf object. | |
| 
            StringTranslationTrait:: | 
                  protected | property | The string translation service. | 1 | 
| 
            StringTranslationTrait:: | 
                  protected | function | Formats a string containing a count of items. | |
| 
            StringTranslationTrait:: | 
                  protected | function | Returns the number of plurals supported by a given language. | |
| 
            StringTranslationTrait:: | 
                  protected | function | Gets the string translation service. | |
| 
            StringTranslationTrait:: | 
                  public | function | Sets the string translation service to use. | 2 | 
| 
            StringTranslationTrait:: | 
                  protected | function | Translates a string to the current language or to a given language. |