-
Notifications
You must be signed in to change notification settings - Fork 3
/
asklib.install
67 lines (57 loc) · 2.2 KB
/
asklib.install
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\comment\CommentManagerInterface;
use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
use Drupal\Core\Config\FileStorage;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\Core\StringTranslation\TranslatableMarkup;
function asklib_install() {
$em = Drupal::entityManager();
$em->getStorage('field_storage_config')->create([
'entity_type' => 'asklib_question',
'field_name' => 'comments',
'type' => 'comment',
'translatable' => true,
'settings' => [
'comment_type' => 'comment_asklib',
]
])->save();
$em->getStorage('field_config')->create([
'entity_type' => 'asklib_question',
'label' => t('Comments'),
'bundle' => 'asklib_question',
'description' => t('Comments posted on this question'),
'field_name' => 'comments',
'required' => 1,
'default_value' => [
[
'status' => CommentItemInterface::OPEN,
'cid' => 0,
'last_comment_name' => '',
'last_comment_timestamp' => 0,
'last_comment_uid' => 0,
],
],
])->save();
}
function asklib_update_8001() {
$storage_definition = BaseFieldDefinition::create('string')
->setLabel(new TranslatableMarkup('Asker\'s IP address'))
->setDescription(new TranslatableMarkup('IP address from which the question was originally submitted.'));
\Drupal::entityDefinitionUpdateManager()
->installFieldStorageDefinition('ip_address', 'asklib_question', 'asklib', $storage_definition);
}
/**
* Add missing form mode configuration to asklib_question. This helps to bypass
* an error that happens during Drupal core update, from 8.7 to 8.8.
*/
function asklib_update_8002() {
// Check if we already have installed the configuration
$entity = \Drupal::entityTypeManager()->getStorage('entity_form_mode')->load('asklib_question.edit');
if(!$entity) {
// If not load and write the configuration to Drupal config.
$config_path = drupal_get_path('module', 'asklib') . '/config/install';
$source = new FileStorage($config_path);
$config_storage = \Drupal::service('config.storage');
$config_storage->write('core.entity_form_mode.asklib_question.edit', $source->read('core.entity_form_mode.asklib_question.edit'));
}
}