-
Notifications
You must be signed in to change notification settings - Fork 0
/
owlcarousel.module
67 lines (60 loc) · 1.68 KB
/
owlcarousel.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\owlcarousel\Entity\OwlCarouselStyleVariant;
use Drupal\Core\Entity\EntityInterface;
/**
* Implements hook_help().
*/
function owlcarousel_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
case 'entity.owl_carousel_style.collection':
return '<p>' . t('Lorem ipsum.') . '</p>';
}
}
/**
* Implements hook_theme().
*/
function owlcarousel_theme() {
return [
'owlcarousel_wrapper' => [
'variables' => [
'items' => [],
'preset' => NULL,
],
],
'owlcarousel_item' => [
'variables' => [
'type' => NULL,
],
],
];
}
/**
* Implements hook_entity_presave().
*/
function owlcarousel_entity_presave(EntityInterface $entity) {
if ('owl_carousel_style' === $entity->getEntityTypeId()) {
/** @var \Drupal\owlcarousel\OwlCarouselManager $owlCarouselManager */
$owlCarouselManager = \Drupal::service('owlcarousel.manager');
$owlCarouselManager->generateVariants($entity);
}
}
/**
* Implements hook_entity_operation_alter().
*/
function owlcarousel_entity_operation_alter(&$operations, $entity) {
if($entity instanceof OwlCarouselStyleVariant) {
$owlCarouselStyle = \Drupal::request()->get('owl_carousel_style');
foreach($operations as $operation) {
/** @var \Drupal\Core\Url $url_info */
$url_info = $operation['url'];
$url_info->setRouteParameter('owl_carousel_style', $owlCarouselStyle);
}
}
}
/**
* Implements hook_preprocess_views_view_owlcarousel().
*/
function owlcarousel_preprocess_views_view_owlcarousel(&$variables) {
$variables['#attached']['library'][] = 'owlcarousel/owlsettings';
}