forked from weeshop/WeeShop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
catshop_hotel.module
70 lines (64 loc) · 2.2 KB
/
catshop_hotel.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
<?php
/**
* @file
* Defines the Product entity and associated features.
*/
use Drupal\entity\BundleFieldDefinition;
use Drupal\catshop_hotel\Entity\HotelType;
/**
* Adds the default body field to a hotel type.
*
* @param \Drupal\catshop_hotel\Entity\HotelType $hotel_type
* The hotel type.
* @param string $label
* (optional) The label for the body instance. Defaults to 'Body'.
*/
function catshop_hotel_add_body_field(HotelType $hotel_type, $label = 'Body') {
$field_definition = BundleFieldDefinition::create('text_with_summary')
->setTargetEntityTypeId('catshop_hotel')
->setTargetBundle($hotel_type->id())
->setName('body')
->setLabel($label)
->setSetting('display_summary', FALSE)
->setDisplayOptions('form', [
'type' => 'text_textarea_with_summary',
'weight' => 1,
])
->setDisplayOptions('view', [
'label' => 'hidden',
'type' => 'text_default',
]);
$configurable_field_manager = \Drupal::service('commerce.configurable_field_manager');
$configurable_field_manager->createField($field_definition, FALSE);
}
/**
* Adds the default variations field to a hotel type.
*
* Variations can't be a base field because the Views integration is broken.
* Instead, it is created as a configurable field for each hotel type.
*
* @param \Drupal\catshop_hotel\Entity\HotelType $hotel_type
* The hotel type.
*/
function catshop_hotel_add_rooms_field(HotelType $hotel_type) {
$field_definition = BundleFieldDefinition::create('entity_reference')
->setTargetEntityTypeId('catshop_hotel')
->setTargetBundle($hotel_type->id())
->setName('rooms')
->setLabel('Rooms')
->setCardinality(BundleFieldDefinition::CARDINALITY_UNLIMITED)
->setRequired(TRUE)
->setSetting('target_type', 'catshop_hotel_room')
->setSetting('handler', 'default')
->setDisplayOptions('form', [
'type' => 'inline_entity_form_complex',
'weight' => 10,
'settings' => [
'override_labels' => TRUE,
'label_singular' => 'room',
'label_plural' => 'rooms',
],
]);
$configurable_field_manager = \Drupal::service('commerce.configurable_field_manager');
$configurable_field_manager->createField($field_definition);
}