I use ZURB theme and following I post the code of my template.php file.
My problem is, that type="application/ld+json"
in <script type="application/ld+json">
gets stripped out so it is rendered as just <script>
.
The problem with this is that I can't add structured markup to any pages.
To reproduce just insert jsonld script in any way (third party module or using custom fields for nodes) and display it with a zurb theme.
The same issue has already been reported for ZEN: https://www.drupal.org/project/zen/issues/2934644
To I have to adapt my template.php in a similar way as suggested in the ZEN patch in terms of not stripping out JSON-ld?
Here is my template.php
<?php
/**
* Implements template_preprocess_html().
*
*/
//function gonzo_preprocess_html(&$variables) {
// // Add conditional CSS for IE. To use uncomment below and add IE css file
// drupal_add_css(path_to_theme() . '/css/ie.css', array('weight' => CSS_THEME, 'browsers' => array('!IE' => FALSE), 'preprocess' => FALSE));
//
// // Need legacy support for IE downgrade to Foundation 2 or use JS file below
// // drupal_add_js('http://ie7-js.googlecode.com/svn/version/2.1(beta4)/IE7.js', 'external');
//}
/**
* Implements template_preprocess_page
*
*/
//function gonzo_preprocess_page(&$variables) {
//}
/**
* Implements template_preprocess_node
*
*/
//function gonzo_preprocess_node(&$variables) {
//}
/**
* Implements hook_preprocess_block()
*/
//function gonzo_preprocess_block(&$variables) {
// // Add wrapping div with global class to all block content sections.
// $variables['content_attributes_array']['class'][] = 'block-content';
//
// // Convenience variable for classes based on block ID
// $block_id = $variables['block']->module . '-' . $variables['block']->delta;
//
// // Add classes based on a specific block
// switch ($block_id) {
// // System Navigation block
// case 'system-navigation':
// // Custom class for entire block
// $variables['classes_array'][] = 'system-nav';
// // Custom class for block title
// $variables['title_attributes_array']['class'][] = 'system-nav-title';
// // Wrapping div with custom class for block content
// $variables['content_attributes_array']['class'] = 'system-nav-content';
// break;
//
// // User Login block
// case 'user-login':
// // Hide title
// $variables['title_attributes_array']['class'][] = 'element-invisible';
// break;
//
// // Example of adding Foundation classes
// case 'block-foo': // Target the block ID
// // Set grid column or mobile classes or anything else you want.
// $variables['classes_array'][] = 'six columns';
// break;
// }
//
// // Add template suggestions for blocks from specific modules.
// switch($variables['elements']['#block']->module) {
// case 'menu':
// $variables['theme_hook_suggestions'][] = 'block__nav';
// break;
// }
//}
//function gonzo_preprocess_views_view(&$variables) {
//}
/**
* Implements template_preprocess_panels_pane().
*
*/
//function gonzo_preprocess_panels_pane(&$variables) {
//}
/**
* Implements template_preprocess_views_views_fields().
*
*/
//function gonzo_preprocess_views_view_fields(&$variables) {
//}
/**
* Implements theme_form_element_label()
* Use foundation tooltips
*/
//function gonzo_form_element_label($variables) {
// if (!empty($variables['element']['#title'])) {
// $variables['element']['#title'] = '<span class="secondary label">' . $variables['element']['#title'] . '</span>';
// }
// if (!empty($variables['element']['#description'])) {
// $variables['element']['#description'] = ' <span data-tooltip="top" class="has-tip tip-top" data-width="250" title="' . $variables['element']['#description'] . '">' . t('More information?') . '</span>';
// }
// return theme_form_element_label($variables);
//}
/**
* Implements hook_preprocess_button().
*/
//function gonzo_preprocess_button(&$variables) {
// $variables['element']['#attributes']['class'][] = 'button';
// if (isset($variables['element']['#parents'][0]) && $variables['element']['#parents'][0] == 'submit') {
// $variables['element']['#attributes']['class'][] = 'secondary';
// }
//}
/**
* Implements hook_form_alter()
* Example of using foundation sexy buttons
*/
//function gonzo_form_alter(&$form, &$form_state, $form_id) {
// // Sexy submit buttons
// if (!empty($form['actions']) && !empty($form['actions']['submit'])) {
// $classes = (is_array($form['actions']['submit']['#attributes']['class']))
// ? $form['actions']['submit']['#attributes']['class']
// : array();
// $classes = array_merge($classes, array('secondary', 'button', 'radius'));
// $form['actions']['submit']['#attributes']['class'] = $classes;
// }
//}
/**
* Implements hook_form_FORM_ID_alter()
* Example of using foundation sexy buttons on comment form
*/
//function gonzo_form_comment_form_alter(&$form, &$form_state) {
// Sexy preview buttons
// $classes = (is_array($form['actions']['preview']['#attributes']['class']))
// ? $form['actions']['preview']['#attributes']['class']
// : array();
// $classes = array_merge($classes, array('secondary', 'button', 'radius'));
// $form['actions']['preview']['#attributes']['class'] = $classes;
//}
/**
* Implements template_preprocess_panels_pane().
*/
// function zurb_foundation_preprocess_panels_pane(&$variables) {
// }
/**
* Implements template_preprocess_views_views_fields().
*/
/* Delete me to enable
function THEMENAME_preprocess_views_view_fields(&$variables) {
if ($variables['view']->name == 'nodequeue_1') {
// Check if we have both an image and a summary
if (isset($variables['fields']['field_image'])) {
// If a combined field has been created, unset it and just show image
if (isset($variables['fields']['nothing'])) {
unset($variables['fields']['nothing']);
}
} elseif (isset($variables['fields']['title'])) {
unset ($variables['fields']['title']);
}
// Always unset the separate summary if set
if (isset($variables['fields']['field_summary'])) {
unset($variables['fields']['field_summary']);
}
}
}
// */
/**
* Implements hook_css_alter().
*/
//function gonzo_css_alter(&$css) {
// // Always remove base theme CSS.
// $theme_path = drupal_get_path('theme', 'zurb_foundation');
//
// foreach($css as $path => $values) {
// if(strpos($path, $theme_path) === 0) {
// unset($css[$path]);
// }
// }
//}
/**
* Implements hook_js_alter().
*/
//function gonzo_js_alter(&$js) {
// // Always remove base theme JS.
// $theme_path = drupal_get_path('theme', 'zurb_foundation');
//
// foreach($js as $path => $values) {
// if(strpos($path, $theme_path) === 0) {
// unset($js[$path]);
// }
// }
//}
// Enabling customized login form (attempt I)
// function gonzo_theme() {
// $items = array();
//
// $items['user_login'] = array(
// 'render element' => 'form',
// 'path' => drupal_get_path('theme', 'gonzo') . '/templates',
// 'template' => 'user-login',
// 'preprocess functions' => array(
// 'gonzo_preprocess_user_login'
// ),
// );
// $items['user_register_form'] = array(
// 'render element' => 'form',
// 'path' => drupal_get_path('theme', 'gonzo') . '/templates',
// 'template' => 'user-register-form',
// 'preprocess functions' => array(
// 'gonzo_preprocess_user_register_form'
// ),
// );
// $items['user_pass'] = array(
// 'render element' => 'form',
// 'path' => drupal_get_path('theme', 'gonzo') . '/templates',
// 'template' => 'user-pass',
// 'preprocess functions' => array(
// 'gonzo_preprocess_user_pass'
// ),
// );
// return $items;
// }
// function gonzo_preprocess_user_login(&$vars) {
// $vars['intro_text'] = t('This is my awesome login form');
// }
// function gonzo_preprocess_user_register_form(&$vars) {
// $vars['intro_text'] = t('This is my super awesome reg form');
// }
//
// function gonzo_preprocess_user_pass(&$vars) {
// $vars['intro_text'] = t('This is my super awesome request new password form');
// }
// Enabling customized login form attempt II
function gonzo_form_alter(&$form, $form_state, $form_id) {
//print_r($form) // This will display form elements.
if($form_id == "user_login_block") {
$form['actions']['submit']['#value']= "›";
}
}
// Enabling customized Teaser Display
function gonzo_preprocess_node(&$vars) {
if($vars['view_mode'] == 'teaser') {
$vars['theme_hook_suggestions'][] = 'node__' . $vars['node']->type . '__teaser';
}
}
// Customizing visibilty radio buttons in edit/create form
// function theme_form_element (https://api.drupal.org/api/drupal/includes!form.inc/function/theme_radios/7)
function gonzo_form_element($variables) {
$element = &$variables ['element'];
// This function is invoked as theme wrapper, but the rendered form element
// may not necessarily have been processed by form_builder().
$element += array(
'#title_display' => 'before',
);
// Add element #id for #type 'item'.
if (isset($element ['#markup']) && !empty($element ['#id'])) {
$attributes ['id'] = $element ['#id'];
}
// Add element's #type and #name as class to aid with JS/CSS selectors.
$attributes ['class'] = array('form-item');
if (!empty($element ['#type'])) {
$attributes ['class'][] = 'form-type-' . strtr($element ['#type'], '_', '-');
}
if (!empty($element ['#name'])) {
$attributes ['class'][] = 'form-item-' . strtr($element ['#name'], array(' ' => '-', '_' => '-', '[' => '-', ']' => ''));
}
// Add a class for disabled elements to facilitate cross-browser styling.
if (!empty($element ['#attributes']['disabled'])) {
$attributes ['class'][] = 'form-disabled';
}
// only prints the wrapper for elements that are not radio elements
$output = '';
if ($element['#type'] != 'radios' && $element['#type'] != 'radio') {
$output = '<div' . drupal_attributes($attributes) . '>' . "\n";
}
// If #title is not set, we don't display any label or required marker.
if (!isset($element ['#title'])) {
$element ['#title_display'] = 'none';
}
$prefix = isset($element ['#field_prefix']) ? '<span class="field-prefix">' . $element ['#field_prefix'] . '</span> ' : '';
$suffix = isset($element ['#field_suffix']) ? ' <span class="field-suffix">' . $element ['#field_suffix'] . '</span>' : '';
switch ($element ['#title_display']) {
case 'before':
case 'invisible':
$output .= ' ' . theme('form_element_label', $variables);
$output .= ' ' . $prefix . $element ['#children'] . $suffix . "\n";
break;
case 'after':
$output .= ' ' . $prefix . $element ['#children'] . $suffix;
$output .= ' ' . theme('form_element_label', $variables) . "\n";
break;
if (strpos($element['#id'], 'edit-group-content-access-und') !== FALSE) {
$output .= "<span class=\"switch-selection\"></span>\n";
}
case 'none':
case 'attribute':
// Output no label and no required marker, only the children.
$output .= ' ' . $prefix . $element ['#children'] . $suffix . "\n";
break;
}
if (!empty($element ['#description'])) {
$output .= '<div class="description">' . $element ['#description'] . "</div>\n";
}
//only prints the wrapper for elements that are not radio elements
if ($element['#type'] != 'radios' && $element['#type'] != 'radio') {
$output .= "</div>\n";
}
// if (strpos($element['#id'], 'edit-og-group-ref') !== FALSE) {
return $output;
// }
// dpm(strpos($element['#id'], 'edit-og-group-ref'));
// if (strpos($element['#id'], 'edit-og-group-ref') !== FALSE) {
// dpm(strpos($element));
// return $output;
// }
}
// function theme_radios (https://api.drupal.org/api/drupal/includes!form.inc/function/theme_radio/7)
function gonzo_radios($variables) {
$element = $variables ['element'];
$attributes = array();
if (isset($element ['#id'])) {
$attributes ['id'] = $element ['#id'];
}
$attributes ['class'] = 'form-radios';
if (!empty($element ['#attributes']['class'])) {
$attributes ['class'] .= ' ' . implode(' ', $element ['#attributes']['class']);
}
if (isset($element ['#attributes']['title'])) {
$attributes ['title'] = $element ['#attributes']['title'];
}
return '<div' . drupal_attributes($attributes) . '>' . (!empty($element ['#children']) ? $element ['#children'] : '') . '<span class="switch-selection"></span></div>';
}
/**
* Custom changes by Gonzo 13. 1. 2018 from https://drupal.stackexchange.com/questions/107311/eliminate-render-blocking-javascript-and-css-in-above-the-fold-content#107332
* Implements hook_page_alter().
*/
function gonzo_page_alter(&$page) {
// Get critical css file.
$filename = FALSE;
$current_path = current_path();
$path = drupal_get_path('theme', $GLOBALS['theme']);
// Detect frontpage.
if (!$filename
&& drupal_is_front_page()
&& is_readable("$path/critical-css/urls/front.css")
) {
$filename = "$path/critical-css/urls/front";
}
// Detect specific urls.
if (!$filename
&& is_readable("$path/critical-css/urls/{$current_path}.css")
) {
$filename = "$path/critical-css/urls/{$current_path}";
}
// Detection by node type.
if (!$filename) {
$object = menu_get_object();
if (isset($object->nid)
&& is_readable("$path/critical-css/node_type/{$object->type}.css")
) {
$filename = "$path/critical-css/node_type/{$object->type}";
}
}
// Add inline critical css for front page.
if (!empty($filename)) {
$inline_css = advagg_load_stylesheet("$filename.css", TRUE);
$page['content']['#attached']['css']["$filename.css"] = array(
'data' => $inline_css,
'type' => 'inline',
'group' => CSS_SYSTEM - 1,
'weight' => -50000,
'movable' => FALSE,
'critical-css' => TRUE,
);
// Add in domain prefetch.
if (is_readable("$filename.dns")) {
$domains = file("$filename.dns", FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
$domains = array_unique($domains);
foreach ($domains as $domain) {
advagg_add_dns_prefetch($domain);
}
}
}
}