@@ -14,23 +14,29 @@ use Drupal\node\NodeInterface;
1414 * Generic pre-process for all view mode of nodes.
1515 */
1616function _civictheme_preprocess_node (array &$ variables ): void {
17- $ node = $ variables ['node ' ];
18-
19- if (!$ node ) {
17+ $ node = $ variables ['node ' ] ?? NULL ;
18+ if (!$ node instanceof NodeInterface) {
2019 return ;
2120 }
2221
2322 $ variables ['attributes ' ]['class ' ][] = 'node ' ;
2423 if (!$ node ->isPublished ()) {
2524 $ variables ['attributes ' ]['class ' ][] = 'node--unpublished ' ;
2625 }
26+ }
2727
28- $ view_mode = $ variables ['elements ' ]['#view_mode ' ];
29- // Do not display node title on revision pages.
30- if ($ view_mode === 'full ' ) {
31- unset($ variables ['label ' ]);
28+ /**
29+ * Pre-process CivicTheme page nodes.
30+ */
31+ function _civictheme_preprocess_node__civictheme_page__full (array &$ variables ): void {
32+ $ node = $ variables ['node ' ] ?? NULL ;
33+ if (!$ node instanceof NodeInterface) {
34+ return ;
3235 }
3336
37+ // Do not display node title on revision pages.
38+ unset($ variables ['label ' ]);
39+
3440 // Add Table of Contents if the value is set on node.
3541 if (civictheme_get_field_value ($ node , 'field_c_n_show_toc ' )) {
3642 array_unshift ($ variables ['content ' ], [
@@ -63,8 +69,11 @@ function _civictheme_preprocess_node(array &$variables): void {
6369 * Pre-process Full view mode of nodes.
6470 */
6571function _civictheme_preprocess_node__full (array &$ variables ): void {
66- /** @var \Drupal\node\NodeInterface $node */
67- $ node = $ variables ['node ' ];
72+ $ node = $ variables ['node ' ] ?? NULL ;
73+ if (!$ node instanceof NodeInterface) {
74+ return ;
75+ }
76+
6877 $ type = $ node ->getType ();
6978 $ type_callback = '_civictheme_preprocess_node__ ' . $ type . '__full ' ;
7079 if (function_exists ($ type_callback )) {
@@ -76,8 +85,11 @@ function _civictheme_preprocess_node__full(array &$variables): void {
7685 * Default view mode fallback preprocessor for nodes.
7786 */
7887function _civictheme_preprocess_node__default (array &$ variables ): void {
79- /** @var \Drupal\node\NodeInterface $node */
80- $ node = $ variables ['node ' ];
88+ $ node = $ variables ['node ' ] ?? NULL ;
89+ if (!$ node instanceof NodeInterface) {
90+ return ;
91+ }
92+
8193 $ type = $ node ->getType ();
8294 $ type_callback = '_civictheme_preprocess_node__ ' . $ type . '__full ' ;
8395 if (function_exists ($ type_callback )) {
@@ -89,7 +101,11 @@ function _civictheme_preprocess_node__default(array &$variables): void {
89101 * Pre-process CivicTheme Alert nodes.
90102 */
91103function _civictheme_preprocess_node__civictheme_alert__full (array &$ variables ): void {
92- $ node = $ variables ['node ' ];
104+ $ node = $ variables ['node ' ] ?? NULL ;
105+ if (!$ node instanceof NodeInterface) {
106+ return ;
107+ }
108+
93109 $ variables ['id ' ] = $ node ->id ();
94110 $ variables ['title ' ] = $ node ->label ();
95111 $ variables ['description ' ] = _civictheme_process__html_content ((string ) civictheme_get_field_value ($ node , 'field_c_n_body ' , TRUE ), [
0 commit comments