openlayers.theme.inc 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. /**
  3. * @file
  4. * This file holds all the theme related functions.
  5. */
  6. /**
  7. * Implements hook_preprocess_HOOK().
  8. */
  9. function template_preprocess_openlayers(&$variables) {
  10. /** @var \Drupal\openlayers\Types\MapInterface $map */
  11. $map = $variables['openlayers']['#map'];
  12. /*
  13. * Add a theme suggestion so the template can be customized for a particular
  14. * map if needed.
  15. *
  16. * Default template: openlayers.tpl.php
  17. * Custom map template: openlayers--[map-machine-name].tpl.php
  18. */
  19. $variables['theme_hook_suggestions'][] = 'openlayers__' . str_replace('-', '_', $map->getMachineName());
  20. // The map ID.
  21. $variables['openlayers']['id'] = $map->getId();
  22. // The map container CSS styles.
  23. $variables['openlayers']['styles'] = implode(array_map(function ($key) use ($map) {
  24. return $key . ':' . $map->getOption($key) . ';';
  25. }, array('width', 'height')));
  26. // The map element classes.
  27. $variables['openlayers']['classes'] = trim(implode(
  28. ' ',
  29. array(
  30. 'openlayers-map',
  31. $map->getMachineName(),
  32. ((bool) $map->isAsynchronous()) ? 'asynchronous' : NULL,
  33. )
  34. ));
  35. }