1111 */
1212class ReactComponentHelperFunctions {
1313
14+ /**
15+ *
16+ */
1417 public function getImagesItems ($ block , $ rand_id ) {
1518 $ image_carousel = new \stdClass ();
1619 $ image_carousel ->items = [];
@@ -29,6 +32,9 @@ public function getImagesItems($block, $rand_id) {
2932 return $ settings ;
3033 }
3134
35+ /**
36+ *
37+ */
3238 public function getCardContent ($ paragraph ) {
3339 if (empty ($ paragraph )) {
3440 return ;
@@ -42,18 +48,23 @@ public function getCardContent($paragraph) {
4248 case 'card_with_icon ' :
4349 $ card ->cardType = 'default ' ;
4450 break ;
51+
4552 case 'card_degree ' :
4653 $ card ->cardType = 'degree ' ;
4754 break ;
55+
4856 case 'card_event ' :
4957 $ card ->cardType = 'event ' ;
5058 break ;
59+
5160 case 'card_story ' :
5261 $ card ->cardType = 'story ' ;
5362 break ;
63+
5464 case 'card_ranking ' :
5565 $ card ->cardType = 'ranking ' ;
5666 break ;
67+
5768 case 'image_based_card ' :
5869 $ card ->cardType = 'image ' ;
5970 break ;
@@ -89,7 +100,7 @@ public function getCardContent($paragraph) {
89100 $ cta ->label = $ paragraph ->field_cta ->entity ->field_cta_link ->title ;
90101 $ cta ->href = $ this ->processLink ($ paragraph ->field_cta ->entity ->field_cta_link ->uri );
91102 $ options = $ paragraph ->field_cta ->entity ->field_cta_link ->options ;
92- $ color = $ this ->getButtonColor ($ options ,'maroon ' );
103+ $ color = $ this ->getButtonColor ($ options , 'maroon ' );
93104 if (isset ($ options ['attributes ' ]['target ' ])) {
94105 $ cta ->target = $ options ['attributes ' ]['target ' ];
95106 }
@@ -102,15 +113,15 @@ public function getCardContent($paragraph) {
102113 $ cta ->label = $ paragraph ->field_cta_secondary ->entity ->field_cta_link ->title ;
103114 $ cta ->href = $ this ->processLink ($ paragraph ->field_cta_secondary ->entity ->field_cta_link ->uri );
104115 $ options = $ paragraph ->field_cta_secondary ->entity ->field_cta_link ->options ;
105- $ color = $ this ->getButtonColor ($ options ,'gold ' );
116+ $ color = $ this ->getButtonColor ($ options , 'gold ' );
106117 if (isset ($ options ['attributes ' ]['target ' ])) {
107118 $ cta ->target = $ options ['attributes ' ]['target ' ];
108119 }
109120 $ cta ->color = $ color ;
110121 $ cta ->size = 'small ' ;
111122 $ card ->buttons [] = $ cta ;
112123 }
113- // Field link URL with title and URL
124+ // Field link URL with title and URL.
114125 if ($ paragraph ->field_link && $ paragraph ->field_link ->title && $ paragraph ->field_link ->uri ) {
115126 $ card ->linkLabel = $ paragraph ->field_link ->title ;
116127 $ card ->linkUrl = $ this ->processLink ($ paragraph ->field_link ->uri );
@@ -121,27 +132,28 @@ public function getCardContent($paragraph) {
121132 if ($ paragraph ->field_card_ranking_image_size ->value === 'small ' ) {
122133 $ card ->imageSize = 'small ' ;
123134 $ card ->citation = $ paragraph ->field_citation_title ->value ;
124- } elseif ($ paragraph ->field_card_ranking_image_size ->value === 'large ' ) {
135+ }
136+ elseif ($ paragraph ->field_card_ranking_image_size ->value === 'large ' ) {
125137 $ card ->imageSize = 'large ' ;
126138 }
127139 }
128140
129- // WS2-1674 - Card ranking link URL, no link title
141+ // WS2-1674 - Card ranking link URL, no link title.
130142 if (isset ($ paragraph ->field_card_ranking_image_size ->value ) && isset ($ paragraph ->field_link ->uri )) {
131143 $ link = Url::fromUri ($ paragraph ->field_link ->uri );
132144 $ card ->linkUrl = $ this ->processLink ($ paragraph ->field_link ->uri );
133145 }
134146
135- //@TODO We are not going to send this information to the react component,
147+ // @TODO We are not going to send this information to the react component,
136148 // since the functionality in webspark for the tags has not yet been defined
137149 /*if (!empty($paragraph->field_tags)) {
138- foreach ($paragraph->field_tags as $term) {
139- $tag = new \stdClass();
140- $tag->label = $term->entity->name->value;
141- $link = Url::fromRoute('entity.taxonomy_term.canonical', ['taxonomy_term' => $term->entity->tid->value]);
142- $tag->href = $link->toString();
143- $card->tags[] = $tag;
144- }
150+ foreach ($paragraph->field_tags as $term) {
151+ $tag = new \stdClass();
152+ $tag->label = $term->entity->name->value;
153+ $link = Url::fromRoute('entity.taxonomy_term.canonical', ['taxonomy_term' => $term->entity->tid->value]);
154+ $tag->href = $link->toString();
155+ $card->tags[] = $tag;
156+ }
145157 }*/
146158
147159 // WS2-1643 - Adding validating to set icon setting only when it exists.
@@ -150,27 +162,28 @@ public function getCardContent($paragraph) {
150162 $ icon_style = $ paragraph ->field_icon ->style ;
151163 if (isset ($ paragraph ->field_icon ->settings )) {
152164 // PHP 8.1 warning - when null is passed to build in function,
153- // it is no longer silently converted to empty string
165+ // it is no longer silently converted to empty string.
154166 $ icon_settings = unserialize ($ paragraph ->field_icon ->settings );
155- } else {
167+ }
168+ else {
156169 $ icon_settings = '' ;
157170 }
158171 $ card ->icon = [$ icon_style , $ icon_name , $ icon_settings ];
159172 }
160173
161- $ card ->clickable = false ;
162- if (isset ($ paragraph ->field_clickable ->value ) && isset ($ paragraph ->field_card_link ->uri )){
163- $ card ->clickable = true ;
174+ $ card ->clickable = FALSE ;
175+ if (isset ($ paragraph ->field_clickable ->value ) && isset ($ paragraph ->field_card_link ->uri )) {
176+ $ card ->clickable = TRUE ;
164177 $ link = Url::fromUri ($ paragraph ->field_card_link ->uri );
165178 $ card ->clickHref = $ this ->processLink ($ paragraph ->field_card_link ->uri );
166179 }
167180
168- $ card ->showBorders = false ;
181+ $ card ->showBorders = FALSE ;
169182 if ($ paragraph ->field_show_borders && $ paragraph ->field_show_borders ->value ) {
170- $ card ->showBorders = true ;
183+ $ card ->showBorders = TRUE ;
171184 }
172185
173- // WS2-1711 - Image based card
186+ // WS2-1711 - Image based card.
174187 if (isset ($ paragraph ->field_loading ->value )) {
175188 $ card ->loading = $ paragraph ->field_loading ->value ;
176189 }
@@ -181,7 +194,7 @@ public function getCardContent($paragraph) {
181194 $ card ->captionTitle = $ paragraph ->field_caption_title ->value ;
182195 }
183196 if (isset ($ paragraph ->field_drop_shadow ->value ) && $ paragraph ->field_drop_shadow ->value ) {
184- $ card ->dropShadow = true ;
197+ $ card ->dropShadow = TRUE ;
185198 }
186199
187200 $ settings = [];
@@ -190,32 +203,39 @@ public function getCardContent($paragraph) {
190203 return $ settings ;
191204 }
192205
193- function getButtonColor ($ options , $ default ) {
206+ /**
207+ *
208+ */
209+ public function getButtonColor ($ options , $ default ) {
194210 $ color = $ default ;
195211 if (isset ($ options ['attributes ' ]['class ' ])) {
196- //class structure from custom widget 'btn-size btn-color btn'
197- $ class = explode ( ' ' , $ options ['attributes ' ]['class ' ]);
212+ // Class structure from custom widget 'btn-size btn-color btn'.
213+ $ class = explode (' ' , $ options ['attributes ' ]['class ' ]);
198214 $ color = substr ($ class [1 ], 4 );
199215 }
200216 return $ color ;
201217 }
202218
203- function processLink ($ raw_link ) {
219+ /**
220+ *
221+ */
222+ public function processLink ($ raw_link ) {
204223 if (isset ($ raw_link )) {
205- if (preg_match ('/^https?:\/\/ / ' , $ raw_link )) {
224+ if (preg_match ('/^( https?|mailto|tel): / ' , $ raw_link )) {
206225 return $ raw_link ;
207226 }
208227 // Drupal prepends internal links with 'internal:' so we need to strip it.
209- else if (str_starts_with ($ raw_link , 'internal: ' )) {
228+ elseif (str_starts_with ($ raw_link , 'internal: ' )) {
210229 $ raw_link = preg_replace ('/internal:/ ' , '' , $ raw_link );
211230 $ link = Url::fromUserInput ($ raw_link );
212231 return $ link ->toString () ?: $ raw_link ;
213232 }
214- else if (str_starts_with ($ raw_link , 'route: ' ) || str_starts_with ($ raw_link , 'entity: ' ) || str_starts_with ($ raw_link , 'base: ' )) {
233+ elseif (str_starts_with ($ raw_link , 'route: ' ) || str_starts_with ($ raw_link , 'entity: ' ) || str_starts_with ($ raw_link , 'base: ' )) {
215234 $ link = Url::fromUri ($ raw_link );
216235 return $ link ->toString () ?: '' ;
217236 }
218237 }
219238 return NULL ;
220239 }
240+
221241}
0 commit comments