Skip to content

Commit 7f7248e

Browse files
authored
Merge pull request #1 from UCBoulder/ft-1427
update to work with shortcode 3.0.x
2 parents 80e4f33 + ab8154a commit 7f7248e

3 files changed

Lines changed: 27 additions & 71 deletions

File tree

‎src/Plugin/Shortcode/TutorialStep.php‎

Lines changed: 22 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -5,53 +5,25 @@
55
use Drupal\Component\Utility\Xss;
66
use Drupal\Core\Database\Connection;
77
use Drupal\Core\File\FileUrlGeneratorInterface;
8-
use Drupal\Core\Language\Language;
8+
use Drupal\Core\Language\LanguageInterface;
99
use Drupal\Core\Render\RendererInterface;
10+
use Drupal\Core\StringTranslation\TranslatableMarkup;
1011
use Drupal\file\Entity\File;
1112
use Drupal\image\Entity\ImageStyle;
13+
use Drupal\shortcode\Attribute\Shortcode;
1214
use Drupal\shortcode\Plugin\ShortcodeBase;
13-
use Drupal\shortcode_svg\Plugin\ShortcodeIcon;
14-
use Symfony\Component\DependencyInjection\ContainerInterface;
15+
use Drupal\shortcode_svg\ShortcodeIcon;
1516

1617
/**
1718
* Provides a shortcode for tutorial steps.
18-
*
19-
* @Shortcode(
20-
* id = "step",
21-
* title = @Translation("Tutorial"),
22-
* description = @Translation("Shortcode for adding steps to Tutorials")
23-
* )
2419
*/
20+
#[Shortcode(
21+
id: 'step',
22+
title: new TranslatableMarkup('Tutorial'),
23+
description: new TranslatableMarkup('Shortcode for adding steps to Tutorials'),
24+
)]
2525
class TutorialStep extends ShortcodeBase {
2626

27-
/**
28-
* Run Database query.
29-
*
30-
* @var \Drupal\Core\Database\Connection
31-
*/
32-
protected $connection;
33-
34-
/**
35-
* File Url Generator.
36-
*
37-
* @var \Drupal\Core\File\FileUrlGeneratorInterface
38-
*/
39-
protected $fileUrlGenerator;
40-
41-
/**
42-
* Call shortcode svg icon.
43-
*
44-
* @var \Drupal\shortcode_svg\Plugin\ShortcodeIcon
45-
*/
46-
protected $shortcodeSvgIcon;
47-
48-
/**
49-
* The renderer service.
50-
*
51-
* @var \Drupal\Core\Render\RendererInterface
52-
*/
53-
protected $renderer;
54-
5527
/**
5628
* Iterate.
5729
*
@@ -72,45 +44,28 @@ class TutorialStep extends ShortcodeBase {
7244
* The renderer service.
7345
* @param \Drupal\Core\Database\Connection $connection
7446
* Establish database connection.
75-
* @param \Drupal\Core\File\FileUrlGeneratorInterface $file_url_generator
47+
* @param \Drupal\Core\File\FileUrlGeneratorInterface $fileUrlGenerator
7648
* File URL generator.
77-
* @param \Drupal\shortcode_svg\Plugin\ShortcodeIcon $shortcode_svg_icon
49+
* @param \Drupal\shortcode_svg\ShortcodeIcon $shortcodeSvgIcon
7850
* Call shortcode svg icon.
7951
*/
8052
public function __construct(
8153
array $configuration,
8254
$plugin_id,
8355
$plugin_definition,
8456
RendererInterface $renderer,
85-
Connection $connection,
86-
FileUrlGeneratorInterface $file_url_generator,
87-
ShortcodeIcon $shortcode_svg_icon,
57+
protected Connection $connection,
58+
protected FileUrlGeneratorInterface $fileUrlGenerator,
59+
protected ShortcodeIcon $shortcodeSvgIcon,
8860
) {
8961
parent::__construct($configuration, $plugin_id, $plugin_definition, $renderer);
90-
$this->connection = $connection;
91-
$this->fileUrlGenerator = $file_url_generator;
92-
$this->shortcodeSvgIcon = $shortcode_svg_icon;
93-
}
94-
95-
/**
96-
* {@inheritdoc}
97-
*/
98-
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition): self {
99-
return new self(
100-
$configuration,
101-
$plugin_id,
102-
$plugin_definition,
103-
$container->get('renderer'),
104-
$container->get('database'),
105-
$container->get('file_url_generator'),
106-
$container->get('shortcode_svg.icon')
107-
);
10862
}
10963

11064
/**
11165
* {@inheritdoc}
11266
*/
113-
public function process(array $attributes, $text, $langcode = Language::LANGCODE_NOT_SPECIFIED) {
67+
#[\Override]
68+
public function process(array $attributes, string $text, string $langcode = LanguageInterface::LANGCODE_NOT_SPECIFIED): string {
11469
$attributes = $this->getAttributes(
11570
[
11671
'fid' => '',
@@ -162,8 +117,8 @@ public function process(array $attributes, $text, $langcode = Language::LANGCODE
162117
$width = round($width, 0);
163118
}
164119
$icon = $this->shortcodeSvgIcon;
165-
// Get svg icon path.
166-
$icon = $icon->getSvg();
120+
// Build the close icon markup for the modal window.
121+
$icon_markup = $icon->setIcon('x-fat', '20', 'fff');
167122

168123
$img_html = [
169124
'#theme' => 'tutorial_step_image',
@@ -173,9 +128,9 @@ public function process(array $attributes, $text, $langcode = Language::LANGCODE
173128
'#width' => $width,
174129
'#height' => $height,
175130
'#alt' => $alt,
176-
'#icon' => $icon,
131+
'#icon' => $icon_markup,
177132
];
178-
$img_html = $this->renderer->render($img_html);
133+
$img_html = $this->render($img_html);
179134
}
180135
else {
181136
$img_html = $this->t('Missing Image or incorrect fid set');
@@ -202,12 +157,13 @@ public function process(array $attributes, $text, $langcode = Language::LANGCODE
202157
],
203158
];
204159

205-
return $this->renderer->render($step);
160+
return $this->render($step);
206161
}
207162

208163
/**
209164
* {@inheritdoc}
210165
*/
166+
#[\Override]
211167
public function tips($long = FALSE) {
212168
$output = [];
213169
$output[] = '<p><strong>' . $this->t('[step fid="3" reset]Other HTML content here [/step]') . '</strong> ';

‎templates/tutorial-step-image.html.twig‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
* - width: Calculated thumbnail width.
1111
* - height: Calculated thumbnail height.
1212
* - alt: Alternative text for the image.
13-
* - icon: Path to the SVG sprite used for the close icon.
13+
* - icon: Rendered markup for the close icon, built via
14+
* ShortcodeIcon::setIcon().
1415
*
1516
* @ingroup themeable
1617
*/
@@ -22,9 +23,7 @@
2223
<div>
2324
<div class="header">
2425
<a href="#step-{{ fid }}" title="Close" class="modal-close">
25-
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 34 34" class="svg-icon x-fat" width="20">
26-
<use fill="#fff" xlink:href="{{ icon }}#x-fat"></use>
27-
</svg>
26+
{{ icon|raw }}
2827
</a>
2928
</div>
3029
<img src="{{ image_full }}" alt="{{ alt }}" loading="lazy">

‎tutorial.info.yml‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ type: module
33
description: 'Create step shortcode and display correctly on tutorial nodes'
44
dependencies:
55
- shortcode:shortcode
6+
- shortcode_svg:shortcode_svg
67
package: 'Input filters'
7-
core_version_requirement: ^11
8+
core_version_requirement: ^11.1 || ^12

0 commit comments

Comments
 (0)