You are here

public function DefaultTwigExtension::get_default_image in Opigno training catalog 8

Same name and namespace in other branches
  1. 3.x src/TwigExtension/DefaultTwigExtension.php \Drupal\opigno_catalog\TwigExtension\DefaultTwigExtension::get_default_image()

Returns default image.

File

src/TwigExtension/DefaultTwigExtension.php, line 76

Class

DefaultTwigExtension
Class DefaultTwigExtension.

Namespace

Drupal\opigno_catalog\TwigExtension

Code

public function get_default_image($type, $title) {
  $request = \Drupal::request();
  $path = \Drupal::service('module_handler')
    ->getModule('opigno_catalog')
    ->getPath();
  $title = t('Picture of') . ' ' . $title;
  switch ($type) {
    case 'course':
      $img = '<img src="' . $request
        ->getBasePath() . '/' . $path . '/img/img_course.png" alt="' . $title . '">';
      break;
    case 'module':
      $img = '<img src="' . $request
        ->getBasePath() . '/' . $path . '/img/img_module.png" alt="' . $title . '">';
      break;
    case 'learning_path':
      $img = '<img src="' . $request
        ->getBasePath() . '/' . $path . '/img/img_training.png" alt="' . $title . '">';
      break;
    default:
      $img = NULL;
      break;
  }
  return Markup::create($img);
}