diff --git a/core/modules/tour/lib/Drupal/tour/Plugin/tour/tip/TipPluginText.php b/core/modules/tour/lib/Drupal/tour/Plugin/tour/tip/TipPluginText.php index cb93887e56629138d3e9851a292d1a1b2e5687b6..9484812b5138f6b3c223a160f7d539487e5ab2ce 100644 --- a/core/modules/tour/lib/Drupal/tour/Plugin/tour/tip/TipPluginText.php +++ b/core/modules/tour/lib/Drupal/tour/Plugin/tour/tip/TipPluginText.php @@ -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); } } diff --git a/core/modules/tour/lib/Drupal/tour/Tests/TourTest.php b/core/modules/tour/lib/Drupal/tour/Tests/TourTest.php index a8e7b8a3d5f3c549bb1964f582081193598b06d4..db69e189c023f91a3ef9307edd59f4720a8250f5 100644 --- a/core/modules/tour/lib/Drupal/tour/Tests/TourTest.php +++ b/core/modules/tour/lib/Drupal/tour/Tests/TourTest.php @@ -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.'); diff --git a/core/modules/tour/lib/Drupal/tour/TipPluginManager.php b/core/modules/tour/lib/Drupal/tour/TipPluginManager.php index 4fc8b99f370c1d96b411b251f38886cc6fc3e7c8..e23669b747d036fb5dc163c5aa37755463c8e6b1 100644 --- a/core/modules/tour/lib/Drupal/tour/TipPluginManager.php +++ b/core/modules/tour/lib/Drupal/tour/TipPluginManager.php @@ -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); } } diff --git a/core/modules/tour/tests/tour_test/config/tour.tour.tour-test.yml b/core/modules/tour/tests/tour_test/config/tour.tour.tour-test.yml index 31dd41148d03c4b5b5dede2f6d2b98ef69ae09ac..9d389eda640e7332aeb3f9a3f5b34258fa5866ff 100644 --- a/core/modules/tour/tests/tour_test/config/tour.tour.tour-test.yml +++ b/core/modules/tour/tests/tour_test/config/tour.tour.tour-test.yml @@ -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