<?php

use Drupal\restaurant\Helper\Helper;

class ImageHelper extends Helper
{
  public function image($args)
  {
    //mydump ($src);
    if (empty ($args[0])) {
      throw new Exception("image src attribute required");
    }
    if (strpos($args[0], "/") == 0) { //absolute path passed in as args[0]
      $src = $args[0];
    } else { //relative path passed in as args[0]. prepend the modulePath to args[0]
      $src = str_replace($_SERVER['DOCUMENT_ROOT'], '', $this->modulePath) . $args[0];
    }

    $return = '<img src="' . $src;
    if (isset ($args[1])) {
      $return .= '" alt="' . $args[1] . '">';
    } else {
      $return .= '">';
    }
    return $return;
  }
}
