3 namespace Drupal\tour\Plugin\tour\tip;
5 use Drupal\Component\Utility\Html;
6 use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
7 use Drupal\Core\Utility\Token;
8 use Drupal\tour\TipPluginBase;
9 use Symfony\Component\DependencyInjection\ContainerInterface;
12 * Displays some text as a tip.
16 * title = @Translation("Text")
19 class TipPluginText extends TipPluginBase implements ContainerFactoryPluginInterface {
22 * The body text which is used for render of this Text Tip.
31 * @var \Drupal\Core\Utility\Token
36 * The forced position of where the tip will be located.
43 * Constructs a \Drupal\tour\Plugin\tour\tip\TipPluginText object.
45 * @param array $configuration
46 * A configuration array containing information about the plugin instance.
47 * @param string $plugin_id
48 * The plugin_id for the plugin instance.
49 * @param mixed $plugin_definition
50 * The plugin implementation definition.
51 * @param \Drupal\Core\Utility\Token $token
54 public function __construct(array $configuration, $plugin_id, $plugin_definition, Token $token) {
55 parent::__construct($configuration, $plugin_id, $plugin_definition);
56 $this->token = $token;
62 public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
63 return new static($configuration, $plugin_id, $plugin_definition, $container->get('token'));
67 * Returns a ID that is guaranteed uniqueness.
70 * A unique id to be used to generate aria attributes.
72 public function getAriaId() {
75 $id = Html::getUniqueId($this->get('id'));
81 * Returns body of the text tip.
86 public function getBody() {
87 return $this->get('body');
91 * Returns location of the text tip.
96 public function getLocation() {
97 return $this->get('location');
103 public function getAttributes() {
104 $attributes = parent::getAttributes();
105 $attributes['data-aria-describedby'] = 'tour-tip-' . $this->getAriaId() . '-contents';
106 $attributes['data-aria-labelledby'] = 'tour-tip-' . $this->getAriaId() . '-label';
107 if ($location = $this->get('location')) {
108 $attributes['data-options'] = 'tipLocation:' . $location;
116 public function getOutput() {
117 $output = '<h2 class="tour-tip-label" id="tour-tip-' . $this->getAriaId() . '-label">' . Html::escape($this->getLabel()) . '</h2>';
118 $output .= '<p class="tour-tip-body" id="tour-tip-' . $this->getAriaId() . '-contents">' . $this->token->replace($this->getBody()) . '</p>';
119 return ['#markup' => $output];