-
Notifications
You must be signed in to change notification settings - Fork 0
/
commerce_recruiting.module
128 lines (119 loc) · 3.62 KB
/
commerce_recruiting.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<?php
/**
* @file
* Contains commerce_recruiting.module.
*/
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\Core\Url;
/**
* Implements hook_theme().
*/
function commerce_recruiting_theme($existing, $type, $theme, $path) {
$theme = [];
$theme['friend_share_block'] = [
'path' => $path . '/templates',
'template' => 'friend-share-block',
'variables' => [
'share_link' => NULL,
'block_headline' => NULL,
'block_description' => NULL,
'option' => NULL,
],
];
$theme['recruiter_campaigns'] = [
'path' => $path . '/templates',
'template' => 'recruiter-campaigns',
'variables' => [
'campaigns' => [],
],
];
$theme['recruitment_summary'] = [
'path' => $path . '/templates',
'template' => 'recruitment-summary',
'variables' => [
'summaries' => [],
],
];
$theme['recruitment_rewards'] = [
'path' => $path . '/templates',
'template' => 'recruitment-rewards',
'variables' => [
'rewards' => [],
],
];
$theme['recruitment'] = [
'render element' => 'elements',
'file' => 'commerce_recruiting.page.inc',
'template' => 'recruitment',
];
$theme['recruitment_content_add_list'] = [
'render element' => 'content',
'variables' => ['content' => NULL],
'file' => 'commerce_recruiting.page.inc',
];
$theme['recruitment_session_info'] = [
'path' => $path . '/templates',
'template' => 'recruitment-session-info',
'variables' => [
'recruiter' => NULL,
'option' => NULL,
],
];
return $theme;
}
/**
* Implements hook_cron().
*/
function commerce_recruiting_cron() {
\Drupal::service('commerce_recruiting.recruitment_manager')->applyTransitions('accept');
}
/**
* Implements hook_entity_base_field_info().
*/
function commerce_recruiting_entity_base_field_info(EntityTypeInterface $entity_type) {
if ($entity_type->id() == 'user') {
$fields['code'] = BaseFieldDefinition::create('string')
->setLabel(new TranslatableMarkup('Code'))
->setDescription(new TranslatableMarkup('Your personal recommendation code.'))
->setTranslatable(FALSE)
->setSettings([
'default_value' => '',
'max_length' => 50,
])
->setDisplayOptions('form', [
'type' => 'string_textfield',
'weight' => 1,
])
->setDisplayConfigurable('view', TRUE)
->setDisplayConfigurable('form', TRUE)
// ->setDefaultValueCallback('Drupal\commerce_recruiting\Entity\CampaignOption::getDefaultCode')
->addConstraint('CodeUnique');
return $fields;
}
if ($entity_type->id() == 'commerce_order_item') {
$fields['recruitment_info'] = BaseFieldDefinition::create('recruitment_info')
->setLabel(new TranslatableMarkup('Recruitment Info'))
->setDescription(new TranslatableMarkup('The recruitment information.'))
->setTranslatable(FALSE)
->setDisplayConfigurable('view', FALSE)
->setDisplayConfigurable('form', FALSE);
return $fields;
}
}
/**
* Implements hook_entity_operation_alter().
*/
function commerce_recruiting_entity_operation_alter(array &$operations, EntityInterface $entity) {
if ($entity->getEntityTypeId() == 'commerce_recruitment_campaign') {
$operations['commerce_recruitment_campaign_' . $entity->id() . '_recruiters'] = [
'title' => t('View on recruiters list'),
'url' => Url::fromRoute('commerce_recruiting.campaign.recruiters_list', [
'commerce_recruitment_campaign' => $entity->id(),
]),
'weight' => 100,
];
}
}