You are here

class PrintPage in Social simple 2.0.x

Same name and namespace in other branches
  1. 8 src/SocialNetwork/PrintPage.php \Drupal\social_simple\SocialNetwork\PrintPage

The Printer button.

Hierarchy

Expanded class hierarchy of PrintPage

1 string reference to 'PrintPage'
social_simple.services.yml in ./social_simple.services.yml
social_simple.services.yml
1 service uses PrintPage
social_simple.printer in ./social_simple.services.yml
Drupal\social_simple\SocialNetwork\PrintPage

File

src/SocialNetwork/PrintPage.php, line 14

Namespace

Drupal\social_simple\SocialNetwork
View source
class PrintPage implements SocialNetworkInterface {
  use StringTranslationTrait;

  /**
   * The social network base share link.
   */
  const PRINTER = '#';

  /**
   * The module handler.
   *
   * @var \Drupal\Core\Extension\ModuleHandlerInterface
   */
  protected $moduleHandler;
  public function __construct(ModuleHandlerInterface $moduleHandler) {
    $this->moduleHandler = $moduleHandler;
  }

  /**
   * {@inheritdoc}
   */
  public function getId() {
    return 'print';
  }

  /**
   * {@inheritdoc}
   */
  public function getLabel() {
    return $this
      ->t('Print');
  }

  /**
   * {@inheritdoc}
   */
  public function getShareLink($share_url, $title = '', EntityInterface $entity = NULL, array $additional_options = []) {
    $options = [];
    if ($additional_options) {
      foreach ($additional_options as $id => $value) {
        $options['query'][$id] = $value;
      }
    }
    $url = Url::fromUserInput(self::PRINTER, $options);
    $link = [
      'url' => $url,
      'title' => [
        '#markup' => '<i class="fa fa-print"></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,
      'data-popup-open' => 'false',
      'onClick' => 'window.print();',
    ];
    return $attributes;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
PrintPage::$moduleHandler protected property The module handler.
PrintPage::getId public function Get the network id. Overrides SocialNetworkInterface::getId
PrintPage::getLabel public function Get the network name. Overrides SocialNetworkInterface::getLabel
PrintPage::getLinkAttributes public function Get common attributes for the share link. Overrides SocialNetworkInterface::getLinkAttributes
PrintPage::getShareLink public function Checks whether the given transition is allowed. Overrides SocialNetworkInterface::getShareLink
PrintPage::PRINTER constant The social network base share link.
PrintPage::__construct public function
StringTranslationTrait::$stringTranslation protected property The string translation service. 4
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.