function ColorSystemBrandingBlockAlter::preRender

Same name and namespace in other branches
  1. 8.9.x core/modules/color/src/ColorSystemBrandingBlockAlter.php \Drupal\color\ColorSystemBrandingBlockAlter::preRender()

#pre_render callback: Sets color preset logo.

File

core/modules/color/src/ColorSystemBrandingBlockAlter.php, line 18

Class

ColorSystemBrandingBlockAlter
Provides a trusted callback to alter the system branding block.

Namespace

Drupal\color

Code

public static function preRender($build) {
    $theme_key = \Drupal::theme()->getActiveTheme()
        ->getName();
    $config = \Drupal::config('color.theme.' . $theme_key);
    CacheableMetadata::createFromRenderArray($build)->addCacheableDependency($config)
        ->applyTo($build);
    // Override logo.
    $logo = $config->get('logo');
    if ($logo && $build['content']['site_logo'] && preg_match('!' . $theme_key . '/logo.svg$!', $build['content']['site_logo']['#uri'])) {
        $build['content']['site_logo']['#uri'] = \Drupal::service('file_url_generator')->generateString($logo);
    }
    return $build;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.