class DefaultTwigExtension in Opigno training catalog 8
Same name and namespace in other branches
- 3.x src/TwigExtension/DefaultTwigExtension.php \Drupal\opigno_catalog\TwigExtension\DefaultTwigExtension
Class DefaultTwigExtension.
Hierarchy
- class \Drupal\opigno_catalog\TwigExtension\DefaultTwigExtension extends \Drupal\opigno_catalog\TwigExtension\Twig_Extension
Expanded class hierarchy of DefaultTwigExtension
1 string reference to 'DefaultTwigExtension'
1 service uses DefaultTwigExtension
File
- src/
TwigExtension/ DefaultTwigExtension.php, line 11
Namespace
Drupal\opigno_catalog\TwigExtensionView source
class DefaultTwigExtension extends \Twig_Extension {
/**
* {@inheritdoc}
*/
public function getFunctions() {
return [
new \Twig_SimpleFunction('opigno_catalog_get_style', [
$this,
'get_row_style',
]),
new \Twig_SimpleFunction('opigno_catalog_is_member', [
$this,
'is_member',
]),
new \Twig_SimpleFunction('opigno_catalog_is_started', [
$this,
'is_started',
]),
new \Twig_SimpleFunction('opigno_catalog_get_default_image', [
$this,
'get_default_image',
]),
];
}
/**
* {@inheritdoc}
*/
public function getName() {
return 'opigno_catalog.twig.extension';
}
/**
* Gets row style.
*/
public function get_row_style() {
$style = \Drupal::service('opigno_catalog.get_style')
->getStyle();
return $style == 'line' ? 'style-line' : 'style-block';
}
/**
* Checks if user is a member of group.
*/
public function is_member($group_id) {
$group = Group::load($group_id);
$account = \Drupal::currentUser();
return (bool) $group
->getMember($account);
}
/**
* Checks if training started.
*/
public function is_started($group_id) {
$group = Group::load($group_id);
$account = \Drupal::currentUser();
return (bool) opigno_learning_path_started($group, $account);
}
/**
* Returns default image.
*/
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);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DefaultTwigExtension:: |
public | function | ||
DefaultTwigExtension:: |
public | function | ||
DefaultTwigExtension:: |
public | function | Returns default image. | |
DefaultTwigExtension:: |
public | function | Gets row style. | |
DefaultTwigExtension:: |
public | function | Checks if user is a member of group. | |
DefaultTwigExtension:: |
public | function | Checks if training started. |