Created
September 7, 2016 08:33
-
-
Save vlledo/a6adbaa088dbfa744325635c7e1a1e61 to your computer and use it in GitHub Desktop.
Adds custom theme settings variables to make it avaiables in twig files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function ujaen_subsite_preprocess_page(&$variables) { | |
$variables['sidebar'] = theme_get_setting('sidebar'); | |
$variables['menu_horizontal'] = theme_get_setting('menu_horizontal'); | |
// Load the contact node | |
if (!is_null(theme_get_setting('contact'))) { | |
$contact = \Drupal\node\Entity\Node::load(theme_get_setting('contact')); | |
$variables['contact'] = TRUE; | |
if (!empty($contact->field_telefono->value)) { | |
$variables['contact_telefono'] = $contact->field_telefono->value; | |
} | |
if (!empty($contact->field_correo_electronico->value)) { | |
$variables['contact_email'] = $contact->field_correo_electronico->value; | |
} | |
if (!empty($contact->field_direccion_resumida->value)) { | |
$variables['contact_lugar'] = $contact->field_direccion_resumida->value; | |
} | |
if (!empty($contact->field_fax->value)) { | |
$variables['contact_fax'] = $contact->field_fax->value; | |
} | |
if (!empty($contact->field_horario->value)) { | |
$variables['contact_horario'] = $contact->field_horario->value; | |
} | |
} | |
// Buid the image with the apropiate style | |
$fid = theme_get_setting('image'); | |
if (empty($fid)) { | |
$fids = \Drupal::entityQuery('file')->condition('uri', 'public://default-site-image.jpg')->execute(); | |
$fid = reset($fids); | |
$file = File::load($fid); | |
if ($file) { | |
$image_alt = t('Image from @site_title', array('@site_title' => \Drupal::config('system.site')->get('name'))); | |
$image = ResponsiveImage::build_by_fid($file->id(), 'header_subsite_image', $image_alt); | |
$image_footer = ResponsiveImage::build_by_fid($file->id(), 'header_subsite_image', $image_alt); | |
} | |
} else { | |
$image = ResponsiveImage::build_by_fid($fid[0], 'header_subsite_image', theme_get_setting('image_alt')); | |
$image_footer = ResponsiveImage::build_by_fid($fid[0], 'bloque_paragraph_image', theme_get_setting('image_alt')); | |
} | |
if (isset($image)) { | |
$variables['header_image'] = $image; | |
} | |
if (isset($image_footer)) { | |
$variables['footer_image'] = $image_footer; | |
} | |
$fid_logo = theme_get_setting('logo_subsitio'); | |
if (!empty($fid_logo)) { | |
$file = File::load($fid_logo[0]); | |
if (isset($file)) { | |
$logotipo = ImageStyle::load('logotipo_subsitio')->buildUrl($file->getFileUri()); | |
if (isset($logotipo)) { | |
$variables['header_logo'] = $logotipo; | |
} | |
} | |
} | |
$variables['header_background_color'] = theme_get_setting('background_color'); | |
$variables['site_name'] = \Drupal::config('system.site')->get('name'); | |
$variables['search_path'] = getenv('UJAEN_HOMEURL') . '/search'; | |
$variables['#cache']['tags'][] = 'subsite_header'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment