-
Notifications
You must be signed in to change notification settings - Fork 0
/
os2web_news.install
85 lines (70 loc) · 3.13 KB
/
os2web_news.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
/**
* @file
* Install, uninstall and update hooks for page builder module.
*/
use Drupal\Core\Config\FileStorage;
use Drupal\field\Entity\FieldStorageConfig;
use Symfony\Component\Yaml\Yaml;
function os2web_news_read_in_new_config($config_name) {
$path = drupal_get_path('module', 'os2web_news');
/** @var \Drupal\Core\Config\StorageInterface $active_storage */
$active_storage = \Drupal::service('config.storage');
$active_storage->write($config_name, Yaml::parse(file_get_contents($path . '/config/optional/' . $config_name . '.yml')));
}
/**
* Implements hook_update_N().
*
* Clears default value for News date.
*/
function os2web_news_update_8001($config_name) {
os2web_news_read_in_new_config('field.field.node.os2web_news.field_os2web_news_article_date');
}
/**
* Adds new field for selecting the news category.
*/
function os2web_news_update_8002($config_name) {
// Create field storage and field storage.
$module_handler = \Drupal::moduleHandler();
$config_storage = new FileStorage($module_handler->getModule('os2web_news')->getPath() . '/config/optional');
foreach (['field.storage.paragraph.field_os2web_news_par_section', 'field.field.paragraph.os2web_news_block.field_os2web_news_par_section', 'field.field.paragraph.os2web_news_page.field_os2web_news_par_section'] as $config_name) {
$config_record = $config_storage->read($config_name);
$entity_type = \Drupal::service('config.manager')->getEntityTypeIdByName($config_name);
/** @var \Drupal\Core\Config\Entity\ConfigEntityStorageInterface $storage */
$storage = \Drupal::entityTypeManager()->getStorage($entity_type);
$entity = $storage->createFromStorageRecord($config_record);
$entity->save();
}
// Updating view mode.
os2web_news_read_in_new_config('core.entity_view_display.paragraph.os2web_news_block.default', 'os2web_news');
// Updating form mode.
os2web_news_read_in_new_config('core.entity_form_display.paragraph.os2web_news_block.default', 'os2web_news');
// Updating view mode.
os2web_news_read_in_new_config('core.entity_view_display.paragraph.os2web_news_page.default', 'os2web_news');
// Updating form mode.
os2web_news_read_in_new_config('core.entity_form_display.paragraph.os2web_news_page.default', 'os2web_news');
// Updating view.
os2web_news_read_in_new_config('views.view.os2web_news', 'os2web_news');
}
/**
* Making field for selecting the news section multivalue.
*/
function os2web_news_update_8003($config_name) {
// Updating field storage.
$storegeConfig = FieldStorageConfig::loadByName('paragraph', 'field_os2web_news_par_section');
$storegeConfig->setCardinality(-1);
$storegeConfig->save();
// Updating form mode.
os2web_news_read_in_new_config('core.entity_form_display.paragraph.os2web_news_block.default');
// Updating form mode.
os2web_news_read_in_new_config('core.entity_form_display.paragraph.os2web_news_page.default');
// Updating view.
os2web_news_read_in_new_config('views.view.os2web_news');
}
/**
*
* Making field for selecting the news section multivalue.
*/
function os2web_news_update_8004() {
os2web_news_read_in_new_config('field.storage.node.field_os2web_news_section');
}