X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Ftour%2Fsrc%2FPlugin%2Ftour%2Ftip%2FTipPluginText.php;fp=web%2Fcore%2Fmodules%2Ftour%2Fsrc%2FPlugin%2Ftour%2Ftip%2FTipPluginText.php;h=268741a83d9bc0df10b8581b86adee9055b69e6d;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hp=0000000000000000000000000000000000000000;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad;p=yaffs-website diff --git a/web/core/modules/tour/src/Plugin/tour/tip/TipPluginText.php b/web/core/modules/tour/src/Plugin/tour/tip/TipPluginText.php new file mode 100644 index 000000000..268741a83 --- /dev/null +++ b/web/core/modules/tour/src/Plugin/tour/tip/TipPluginText.php @@ -0,0 +1,122 @@ +token = $token; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { + return new static($configuration, $plugin_id, $plugin_definition, $container->get('token')); + } + + /** + * Returns a ID that is guaranteed uniqueness. + * + * @return string + * A unique id to be used to generate aria attributes. + */ + public function getAriaId() { + static $id; + if (!isset($id)) { + $id = Html::getUniqueId($this->get('id')); + } + return $id; + } + + /** + * Returns body of the text tip. + * + * @return string + * The tip body. + */ + public function getBody() { + return $this->get('body'); + } + + /** + * Returns location of the text tip. + * + * @return string + * The tip location. + */ + public function getLocation() { + return $this->get('location'); + } + + /** + * {@inheritdoc} + */ + 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; + } + + /** + * {@inheritdoc} + */ + public function getOutput() { + $output = '

' . Html::escape($this->getLabel()) . '

'; + $output .= '

' . $this->token->replace($this->getBody()) . '

'; + return ['#markup' => $output]; + } + +}