55use Drupal \Component \Utility \Xss ;
66use Drupal \Core \Database \Connection ;
77use Drupal \Core \File \FileUrlGeneratorInterface ;
8- use Drupal \Core \Language \Language ;
8+ use Drupal \Core \Language \LanguageInterface ;
99use Drupal \Core \Render \RendererInterface ;
10+ use Drupal \Core \StringTranslation \TranslatableMarkup ;
1011use Drupal \file \Entity \File ;
1112use Drupal \image \Entity \ImageStyle ;
13+ use Drupal \shortcode \Attribute \Shortcode ;
1214use 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+ )]
2525class 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> ' ;
0 commit comments