Implements hook_preprocess_HOOK().

File

./easy_breadcrumb.module, line 46

Code

function easy_breadcrumb_preprocess_block(&$variables) {
    if ($variables['plugin_id'] == 'system_breadcrumb_block') {
        // Get JSON-LD.
        if ($json_ld = \Drupal::service('easy_breadcrumb.structured_data_json_ld')->value()) {
            // Prepare script tag.
            $structured_data = [
                '#tag' => 'script',
                '#attributes' => [
                    'type' => 'application/ld+json',
                ],
                '#value' => $json_ld,
            ];
            // Add script tag.
            $variables['#attached']['html_head'][] = [
                $structured_data,
                'easy_breadcrumb_structured_data_json_ld',
            ];
        }
    }
}