ShareEverywhereBlock.php in Share Everywhere 2.x
File
src/Plugin/Block/ShareEverywhereBlock.php
View source
<?php
namespace Drupal\share_everywhere\Plugin\Block;
use Drupal\Core\Block\BlockBase;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Url;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\share_everywhere\ShareEverywhereServiceInterface;
use Drupal\path_alias\AliasManagerInterface;
class ShareEverywhereBlock extends BlockBase implements ContainerFactoryPluginInterface {
protected $shareService;
protected $aliasManager;
public function __construct(array $configuration, $plugin_id, $plugin_definition, ShareEverywhereServiceInterface $share_service, AliasManagerInterface $alias_manager) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->shareService = $share_service;
$this->aliasManager = $alias_manager;
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('share_everywhere.service'), $container
->get('path_alias.manager'));
}
public function build() {
$url = Url::fromRoute('<current>');
$id = str_replace('/', '', $this->aliasManager
->getPathByAlias($url
->toString()));
$build = $this->shareService
->build($url
->setAbsolute()
->toString(), $id);
return $build;
}
}