-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjigs.module
executable file
·162 lines (145 loc) · 4.85 KB
/
jigs.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
<?php
/**
* @file
* Contains hook implementations for the jigs module.
*/
use Drupal\Core\Block\BlockPluginInterface;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\node\NodeInterface;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Entity\FieldDefinition;
function jigs_page_attachments(array &$page) {
$computed_settings = [
// stuff from mysql and user objects.
'foo' => 'bar',
'baz' => 'qux',
];
//$uid = \Drupal::currentUser()->id();
$node = \Drupal::request()->get('node');
if (isset($node) && $node instanceof NodeInterface) {
$title = $node->getTitle();
$type = $node->getType();
if ($type == 'game' or $type == 'map_grid') {
$page['#attached']['library'][] = 'jigs/client';
// $page['#attached']['library'][] = 'jigs/phaser';
// if (!\Drupal::currentUser()->hasPermission('access contextual links')) {
// return;
// }
}
}
}
/**
* Implements hook_form_alter().
*/
/* function jigs_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id)
{
// if ($form_id == 'node-map-grid-form' || $form_id == 'node-map-grid-edit-form') {
$form['field_ image']['#states'] = [
'visible' => [
':input[name="field_image_or_video"]' => ['value' => 'Image'],
],
];
$form['field_ video']['#states'] = [
'visible' => [
':input[name="field_image_or_video"]' => ['value' => 'Video'],
],
];
// }
} */
/**
* Implements hook_field_create_definitions().
*/
/* function jigs_field_create_definitions_alter(array &$definitions)
{
// Define your fields here by entity type.
$definitions['node'] = [
'demo_field' => [
'name' => 'demo_field',
'label' => 'This is my field',
// 'type' => 'string',
'force' => FALSE, // No update once field exists.
'bundles' => [
'map_grid' => [],
'article' => [],
],
],
];
} */
/* function jigs_entity_bundle_field_info(\Drupal\Core\Entity\EntityTypeInterface $entity_type, $bundle, array $base_field_definitions)
{
if ($entity_type->id() == "node" && $bundle == "concert") {
$concert_fields['laatste_uitvoering'] = \Drupal\Core\Field\BaseFieldDefinition::create('datetime')
->setLabel('Laatste uitvoering')
->setRequired(TRUE)
->setDisplayConfigurable('view', TRUE)
->setDisplayConfigurable('form', FALSE)
->setDisplayOptions('view', array(
'label' => 'inline',
// 'type' => 'datetime_plain',
'weight' => '999',
));
$concert_fields['eerste_uitvoering'] = \Drupal\Core\Field\BaseFieldDefinition::create('datetime')
->setLabel('Eerste uitvoering')
->setRequired(TRUE)
->setDisplayConfigurable('view', TRUE)
->setDisplayConfigurable('form', FALSE)
->setDisplayOptions('view', array(
'label' => 'inline',
// 'type' => 'datetime_plain',
'weight' => '999',
));
return $concert_fields;
}
} */
/*
function jigs_entity_field_storage_info(\Drupal\Core\Entity\EntityTypeInterface $entity_type)
{
if ($entity_type->id() == 'node') {
$definitions['my_bundle_field'] = \Drupal\Core\Field\BaseFieldDefinition::create('string')
->setName('my_bundle_field')
->setLabel(t('My new bundle field'))
->setTargetEntityTypeId($entity_type->id());
return $definitions;
}
}
*/
function jigs_theme($existing, $type, $theme, $path) {
return [
'node__game' => [
'template' => 'node--game',
'base hook' => 'node',
'path' => \Drupal::service('extension.list.module')->getPath('jigs') . '/templates',
],
'profile__player__player' => [
'template' => 'profile--player--player',
'base hook' => 'profile',
'path' => \Drupal::service('extension.list.module')->getPath('jigs') . '/templates',
],
'page__front' => [
'template' => 'page--front',
'base hook' => 'page',
'path' => \Drupal::service('extension.list.module')->getPath('jigs') . '/templates',
],
];
}
function jigs_preprocess_page(&$variables) {
if (!\Drupal::service('router.admin_context')->isAdminRoute()) {
// $variables['#attached']['library'][] = 'jigs/coreui-styles';
$variables['#attached']['library'][] = 'jigs/jigs-theme';
}
}
/**
* Force default fields on profiles that were created programmatically.
*/
function jigs_profile_presave(\Drupal\Core\Entity\EntityInterface $entity) {
foreach ($entity->getFields() as $field_name => $field) {
if ($field->isEmpty()) {
$field_definition = $entity->getFieldDefinition($field_name);
$default_value = $field_definition->getDefaultValue($entity);
if (!empty($default_value)) {
$entity->set($field_name, $default_value);
}
}
}
}