SplashBlock.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. /**
  3. * @file
  4. * SplashBlock.php
  5. *
  6. * @author: Frédéric G. MARAND <fgm@osinet.fr>
  7. *
  8. * @copyright (c) 2015 Ouest Systèmes Informatiques (OSInet).
  9. *
  10. * @license General Public License version 2 or later
  11. */
  12. namespace OSInet\Splash;
  13. class SplashBlock {
  14. const MODULE = 'splash';
  15. const DELTA = 'splash';
  16. protected static $defaults = [
  17. 'source' => '#block-system-main',
  18. 'destination' => '#block-splash-splash',
  19. 'timeout' => 3,
  20. 'body' => '',
  21. ];
  22. public static function info() {
  23. $ret = [
  24. 'info' => t('Splash image'),
  25. 'cache' => DRUPAL_CACHE_GLOBAL,
  26. ];
  27. return $ret;
  28. }
  29. public static function variableGet($name) {
  30. return variable_get(static::MODULE . "-$name", static::$defaults[$name]);
  31. }
  32. public function build() {
  33. $subject = NULL;
  34. $content = '<span />';
  35. $settings = [
  36. 'splash' => [
  37. 'source' => static::variableGet('source'),
  38. 'destination' => static::variableGet('destination'),
  39. 'timeout' => static::variableGet('timeout'),
  40. 'body' => static::variableGet('body'),
  41. ],
  42. ];
  43. drupal_add_js($settings, 'setting');
  44. $file = drupal_get_path('module', 'splash') . '/scripts/splash.js';
  45. $options = [
  46. // 'defer' => TRUE,
  47. // 'every_page' => TRUE,
  48. ];
  49. drupal_add_js($file, 'file', $options);
  50. $ret = [
  51. 'subject' => $subject,
  52. 'content' => $content,
  53. ];
  54. return $ret;
  55. }
  56. }