TemplateCreator.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. /**
  3. * Created by IntelliJ IDEA.
  4. * User: logicp
  5. * Date: 6/20/17
  6. * Time: 7:51 PM
  7. */
  8. namespace Drupal\statusmessage;
  9. class TemplateCreator {
  10. protected $markup;
  11. protected $images;
  12. protected $imageMarkup;
  13. protected $title;
  14. protected $description;
  15. /**
  16. * @param $image
  17. */
  18. public function generateImage($image) {
  19. $this->images[] = '<img class="statusmessage-image" src="' . $image . '"/ >"';
  20. }
  21. /**
  22. * @param $title
  23. */
  24. public function generateTitle($title) {
  25. $this->title = '<h3 class="statusmessage-title">' . $title . '</h3>';
  26. }
  27. /**
  28. * @param $description
  29. */
  30. public function generateDescription($description) {
  31. $this->description = '<p class="statusmessage-description">' . $description. '</p>';
  32. }
  33. /**
  34. *
  35. */
  36. private function generateImageMarkup() {
  37. foreach ($this->images as $image) {
  38. $this->imageMarkup .= $image;
  39. }
  40. }
  41. /**
  42. * @return string
  43. */
  44. public function getPreview() {
  45. if ($this->imageMarkup === null) {
  46. $this->generateImageMarkup();
  47. }
  48. return $this->wrap($this->title . $this->description . $this->imageMarkup);
  49. }
  50. private function wrap($string) {
  51. return '<div class="statusmessage-preview">' . $string . '</div>';
  52. }
  53. }