TipPluginText.php in Zircon Profile 8
File
core/modules/tour/src/Plugin/tour/tip/TipPluginText.php
View source
<?php
namespace Drupal\tour\Plugin\tour\tip;
use Drupal\Component\Utility\Html;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Utility\Token;
use Drupal\tour\TipPluginBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
class TipPluginText extends TipPluginBase implements ContainerFactoryPluginInterface {
protected $body;
protected $token;
protected $location;
public function __construct(array $configuration, $plugin_id, $plugin_definition, Token $token) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->token = $token;
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('token'));
}
public function getAriaId() {
static $id;
if (!isset($id)) {
$id = Html::getUniqueId($this
->get('id'));
}
return $id;
}
public function getBody() {
return $this
->get('body');
}
public function getLocation() {
return $this
->get('location');
}
public function getAttributes() {
$attributes = parent::getAttributes();
$attributes['data-aria-describedby'] = 'tour-tip-' . $this
->getAriaId() . '-contents';
$attributes['data-aria-labelledby'] = 'tour-tip-' . $this
->getAriaId() . '-label';
if ($location = $this
->get('location')) {
$attributes['data-options'] = 'tipLocation:' . $location;
}
return $attributes;
}
public function getOutput() {
$output = '<h2 class="tour-tip-label" id="tour-tip-' . $this
->getAriaId() . '-label">' . Html::escape($this
->getLabel()) . '</h2>';
$output .= '<p class="tour-tip-body" id="tour-tip-' . $this
->getAriaId() . '-contents">' . $this->token
->replace($this
->getBody()) . '</p>';
return array(
'#markup' => $output,
);
}
}