Commit be586a99 authored by alexpott's avatar alexpott

Issue #2019469 followup by larowlan: Tour module should use token for it's body.

parent 2c616129
......@@ -7,15 +7,18 @@
namespace Drupal\tour\Plugin\tour\tip;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Utility\Token;
use Drupal\tour\Annotation\Tip;
use Drupal\tour\TipPluginBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Displays some text as a tip.
*
* @Tip("text")
*/
class TipPluginText extends TipPluginBase {
class TipPluginText extends TipPluginBase implements ContainerFactoryPluginInterface {
/**
* The body text which is used for render of this Text Tip.
......@@ -24,6 +27,13 @@ class TipPluginText extends TipPluginBase {
*/
protected $body;
/**
* Token service.
*
* @var \Drupal\Core\Utility\Token
*/
protected $token;
/**
* The forced position of where the tip will be located.
*
......@@ -31,6 +41,30 @@ class TipPluginText extends TipPluginBase {
*/
protected $location;
/**
* Constructs a \Drupal\tour\Plugin\tour\tip\TipPluginText object.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin_id for the plugin instance.
* @param array $plugin_definition
* The plugin implementation definition.
* @param \Drupal\Core\Utility\Token $token
* The token service.
*/
public function __construct(array $configuration, $plugin_id, array $plugin_definition, Token $token) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->token = $token;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, array $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container->get('token'));
}
/**
* Returns a ID that is guaranteed uniqueness.
*
......@@ -83,7 +117,7 @@ public function getAttributes() {
*/
public function getOutput() {
$output = '<h2 class="tour-tip-label" id="tour-tip-' . $this->getAriaId() . '-label">' . check_plain($this->getLabel()) . '</h2>';
$output .= '<p class="tour-tip-body" id="tour-tip-' . $this->getAriaId() . '-contents">' . \Drupal::token()->replace(filter_xss_admin($this->getBody())) . '</p>';
$output .= '<p class="tour-tip-body" id="tour-tip-' . $this->getAriaId() . '-contents">' . filter_xss_admin($this->token->replace($this->getBody())) . '</p>';
return array('#markup' => $output);
}
}
......@@ -49,10 +49,11 @@ public function testTourFunctionality() {
));
$this->assertEqual(count($elements), 1, 'Found English variant of tip 1.');
$elements = $this->xpath('//li[@data-id=:data_id and @class=:classes and ./p[contains(., :text)]]', array(
$elements = $this->xpath('//li[@data-id=:data_id and @class=:classes and ./p//a[@href=:href and contains(., :text)]]', array(
':classes' => 'tip-module-tour-test tip-type-text tip-tour-test-1 even last',
':data_id' => 'tour-test-1',
':text' => 'Is Drupal always the best dressed?',
':href' => url('<front>', array('absolute' => TRUE)),
':text' => 'Drupal',
));
$this->assertEqual(count($elements), 1, 'Found Token replacement.');
......
......@@ -7,12 +7,12 @@
namespace Drupal\tour;
use Drupal\Component\Plugin\Discovery\ProcessDecorator;
use Drupal\Component\Plugin\PluginManagerBase;
use Drupal\Component\Plugin\Factory\DefaultFactory;
use Drupal\Core\Plugin\Discovery\AlterDecorator;
use Drupal\Core\Plugin\Discovery\AnnotatedClassDiscovery;
use Drupal\Core\Plugin\Discovery\CacheDecorator;
use Drupal\Component\Plugin\Discovery\ProcessDecorator;
use Drupal\Core\Plugin\Factory\ContainerFactory;
/**
* Configurable tour manager.
......@@ -32,7 +32,7 @@ public function __construct(\Traversable $namespaces) {
$this->discovery = new AlterDecorator($this->discovery, 'tour_tips_info');
$this->discovery = new CacheDecorator($this->discovery, 'tour');
$this->factory = new DefaultFactory($this->discovery);
$this->factory = new ContainerFactory($this->discovery);
}
}
......@@ -9,7 +9,7 @@ tips:
id: tour-test-1
plugin: text
label: The first tip
body: Is [site:name] always the best dressed?
body: Is <a href="[site:url]">[site:name]</a> always the best dressed?
weight: "1"
attributes:
data-id: tour-test-1
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment