function improved_theme_settings_page_attachments in Open Social 8.6
Same name and namespace in other branches
- 8.9 modules/custom/improved_theme_settings/improved_theme_settings.module \improved_theme_settings_page_attachments()
- 8 modules/custom/improved_theme_settings/improved_theme_settings.module \improved_theme_settings_page_attachments()
- 8.2 modules/custom/improved_theme_settings/improved_theme_settings.module \improved_theme_settings_page_attachments()
- 8.3 modules/custom/improved_theme_settings/improved_theme_settings.module \improved_theme_settings_page_attachments()
- 8.4 modules/custom/improved_theme_settings/improved_theme_settings.module \improved_theme_settings_page_attachments()
- 8.5 modules/custom/improved_theme_settings/improved_theme_settings.module \improved_theme_settings_page_attachments()
- 8.7 modules/custom/improved_theme_settings/improved_theme_settings.module \improved_theme_settings_page_attachments()
- 8.8 modules/custom/improved_theme_settings/improved_theme_settings.module \improved_theme_settings_page_attachments()
- 10.3.x modules/custom/improved_theme_settings/improved_theme_settings.module \improved_theme_settings_page_attachments()
- 10.0.x modules/custom/improved_theme_settings/improved_theme_settings.module \improved_theme_settings_page_attachments()
- 10.1.x modules/custom/improved_theme_settings/improved_theme_settings.module \improved_theme_settings_page_attachments()
- 10.2.x modules/custom/improved_theme_settings/improved_theme_settings.module \improved_theme_settings_page_attachments()
Implements hook_page_attachments().
File
- modules/
custom/ improved_theme_settings/ improved_theme_settings.module, line 47 - Improved theme settings module file.
Code
function improved_theme_settings_page_attachments(array &$page) {
// Check for the current active theme.
$active_theme = \Drupal::theme()
->getActiveTheme()
->getName();
// Determine the admin theme from config.
$config = \Drupal::config('system.theme');
// If we're in the admin theme we need to add a library.
if ($active_theme == $config
->get('admin')) {
$page['#attached']['library'][] = 'improved_theme_settings/color.admin';
}
// If socialblue is our default theme.
$system_theme_settings = \Drupal::configFactory()
->get('system.theme')
->get('default');
// We render our color & font settings in the head. Only if socialblue is
// the default theme. And only if the current active theme is socialblue.
// Otherwise we also render it on all admin pages.
if (array_key_exists('socialbase', \Drupal::service('theme.manager')
->getActiveTheme()
->getBaseThemes())) {
if ($active_theme == $system_theme_settings) {
$style_to_add = '';
if (\Drupal::moduleHandler()
->moduleExists('social_font')) {
// Render font value here.
$style_to_add .= social_font_render();
}
$card_radius = improved_theme_settings_get_setting('card_radius', $system_theme_settings);
if ($card_radius >= 0) {
$style_to_add .= '
.card,
.card-radius,
.hero-canvas {
border-radius: ' . $card_radius . 'px !important;
}
.tabs-left .vertical-tabs-list {
border-radius: ' . $card_radius . 'px 0 0 ' . $card_radius . 'px !important;
}
.teaser--stream:last-child,
.card__block:last-child,
.card__nested-section:last-child {
border-bottom-left-radius: ' . $card_radius . 'px !important;
border-bottom-right-radius: ' . $card_radius . 'px !important;
}
.teaser--stream:last-child .teaser__image {
border-bottom-left-radius: ' . $card_radius . 'px !important;
}
.card__block:first-child {
border-top-left-radius: ' . $card_radius . 'px !important;
border-top-right-radius: ' . $card_radius . 'px !important;
}
@media (min-width: 600px) {
.teaser__teaser-type {
border-radius: 0 0 ' . $card_radius . 'px 0 !important;
}
}
@media (min-width: 900px) {
.off-canvas-xs-only {
border-radius: ' . $card_radius . 'px !important;
}
}
.message__message-body {
border-radius: ' . $card_radius / 2 . 'px !important;
}
';
}
$form_control_radius = improved_theme_settings_get_setting('form_control_radius', $system_theme_settings);
if ($form_control_radius >= 0) {
$style_to_add .= '
.form-control-radius,
.form-control {
border-radius: ' . $form_control_radius . 'px !important;
}
.search-take-over .form-control {
border-radius: 0 !important;
}
.input-group .form-control:first-child, .input-group-addon:first-child {
border-bottom-right-radius: 0 !important;
border-top-right-radius: 0 !important;
}
.input-group .form-control:last-child, .input-group-addon:last-child {
border-bottom-left-radius: 0 !important;
border-top-left-radius: 0 !important;
}
.input-group .select-wrapper:first-child .form-control:first-child {
border-bottom-left-radius: ' . $form_control_radius . 'px !important;
border-top-left-radius: ' . $form_control_radius . 'px !important;
}
';
}
$button_radius = improved_theme_settings_get_setting('button_radius', $system_theme_settings);
if ($button_radius >= 0) {
$style_to_add .= '
:not(.btn-group) > .btn {
border-radius: ' . $button_radius . 'px !important;
}
.btn.btn-floating,
.btn.btn-icon-toggle {
border-radius: 50% !important;
}
.shariff-button {
border-radius: ' . $button_radius . 'px !important;
}
';
}
// Default values.
$hero_gradient_opacity_start = 0.1;
$hero_gradient_opacity_end = 0.7;
// Alwasys cast as an integer.
$hero_gradient_opacity = improved_theme_settings_get_setting('hero_gradient_opacity', $system_theme_settings);
if ($hero_gradient_opacity !== FALSE) {
// Convert to values that the gradient can work with.
$hero_gradient_opacity_end = (int) $hero_gradient_opacity / 100;
// If our opacity has been set to 0, also change the start value to 0.
if ($hero_gradient_opacity_end === 0) {
$hero_gradient_opacity_start = 0;
}
}
$style_to_add .= '
.hero__bgimage-overlay {
background: -webkit-gradient(linear, left top, left bottom, from(rgba(0, 0, 0,' . $hero_gradient_opacity_start . ')), to(rgba(34, 34, 34,' . $hero_gradient_opacity_end . '))) !important;
background: linear-gradient(rgba(0, 0, 0, ' . $hero_gradient_opacity_start . ') 0%, rgba(34, 34, 34, ' . $hero_gradient_opacity_end . ') 100%) !important;
}
';
if (!empty($style_to_add)) {
$page['#attached']['html_head'][] = [
[
'#type' => 'html_tag',
'#tag' => 'style',
'#value' => Markup::create($style_to_add),
],
// A key, to make it possible to recognize this HTML element when
// altering.
'social_theme_preprocess',
];
}
}
}
}