Upgraded imagemagick and manually altered pdf to image module to handle changes....
[yaffs-website] / web / modules / contrib / paragraphs / paragraphs.install
1 <?php
2 /**
3  * @file
4  * Installation hooks for paragraphs module.
5  */
6
7 use Drupal\Core\Entity\EntityTypeInterface;
8 use Drupal\Core\Field\BaseFieldDefinition;
9 use Drupal\field\Entity\FieldStorageConfig;
10 use Drupal\paragraphs\ParagraphStorageSchema;
11
12 /**
13  * Implements hook_install().
14  */
15 function paragraphs_install() {
16   // Assign a weight 1 higher than content_translation to ensure paragraphs_module_implements_alter
17   // runs after content_translation_module_implements_alter.
18   module_set_weight('paragraphs', 11);
19 }
20
21 /**
22  * Add status field.
23  */
24 function paragraphs_update_8001() {
25   $storage_definition = BaseFieldDefinition::create('boolean')
26     ->setLabel(t('Published'))
27     ->setRevisionable(TRUE)
28     ->setTranslatable(TRUE);
29   \Drupal::entityDefinitionUpdateManager()
30     ->installFieldStorageDefinition('status', 'paragraph', 'paragraph', $storage_definition);
31 }
32
33 /**
34  * Add parent ID, parent type and parent field name fields.
35  */
36 function paragraphs_update_8002() {
37   $storage_definition = BaseFieldDefinition::create('string')
38     ->setLabel(t('Parent ID'))
39     ->setDescription(t('The ID of the parent entity of which this entity is referenced.'))
40     ->setSetting('is_ascii', TRUE);
41   \Drupal::entityDefinitionUpdateManager()
42     ->installFieldStorageDefinition('parent_id', 'paragraph', 'paragraph', $storage_definition);
43
44   $storage_definition = BaseFieldDefinition::create('string')
45     ->setLabel(t('Parent type'))
46     ->setDescription(t('The entity parent type to which this entity is referenced.'))
47     ->setSetting('is_ascii', TRUE)
48     ->setSetting('max_length', EntityTypeInterface::ID_MAX_LENGTH);
49   \Drupal::entityDefinitionUpdateManager()
50     ->installFieldStorageDefinition('parent_type', 'paragraph', 'paragraph', $storage_definition);
51
52   $storage_definition = BaseFieldDefinition::create('string')
53     ->setLabel(t('Parent field name'))
54     ->setDescription(t('The entity parent field name to which this entity is referenced.'))
55     ->setSetting('is_ascii', TRUE)
56     ->setSetting('max_length', FieldStorageConfig::NAME_MAX_LENGTH);
57   \Drupal::entityDefinitionUpdateManager()
58     ->installFieldStorageDefinition('parent_field_name', 'paragraph', 'paragraph', $storage_definition);
59 }
60
61 /**
62  * Placeholder for the previous 8003 update.
63  */
64 function paragraphs_update_8003() {
65   // The original update function was moved to be post update.
66   \Drupal::state()->set('paragraphs_update_8003_placeholder', TRUE);
67 }
68
69 /**
70  * Truncate the content_translation_status columns.
71  */
72 function paragraphs_update_8004() {
73
74   $field_name = 'content_translation_status';
75
76   $tables_to_update = [
77     'paragraphs_item_field_data',
78     'paragraphs_item_revision_field_data'
79   ];
80
81   $database = Drupal::database();
82   $entity_definition_update_manager = Drupal::entityDefinitionUpdateManager();
83
84   // Ensure that the data from the content translation status field is deleted
85   // so that the field can safely be deleted.
86   foreach ($tables_to_update as $table_to_update) {
87     if ($database->schema()->fieldExists($table_to_update, $field_name)) {
88       $database->update($table_to_update)
89         ->fields([$field_name => NULL])
90         ->execute();
91     }
92   }
93
94
95   // Delete the storage definition if it was defined before.
96   $storage_definition = $entity_definition_update_manager->getFieldStorageDefinition($field_name, 'paragraph');
97   if ($storage_definition) {
98     $entity_definition_update_manager->uninstallFieldStorageDefinition($storage_definition);
99   }
100 }
101
102 /**
103  * Remove revision_timestamp, changed fields, add content_translation_changed.
104  */
105 function paragraphs_update_8006() {
106
107   $tables_fields = [
108     'paragraphs_item_revision' => 'revision_timestamp',
109     'paragraphs_item_field_data' => 'changed',
110     'paragraphs_item_revision_field_data' => 'changed',
111   ];
112
113   $database = Drupal::database();
114   $entity_definition_update_manager = Drupal::entityDefinitionUpdateManager();
115
116   // Ensure that the data from the content translation status field is deleted
117   // so that the field can safely be deleted.
118   foreach ($tables_fields as $table => $field) {
119     if ($database->schema()->fieldExists($table, $field)) {
120       $database->update($table)
121         ->fields([$field => NULL])
122         ->execute();
123     }
124   }
125
126   foreach ($tables_fields as $table => $field) {
127     // Delete the storage definition if it was defined before.
128     $storage_definition = $entity_definition_update_manager->getFieldStorageDefinition($field, 'paragraph');
129     if ($storage_definition) {
130       $entity_definition_update_manager->uninstallFieldStorageDefinition($storage_definition);
131     }
132   }
133
134   // Add content_translation_changed field.
135   $field_storage_definitions = \Drupal::service('entity_field.manager')->getFieldStorageDefinitions('paragraph');
136   if (isset($field_storage_definitions['content_translation_changed'])) {
137     $storage_definition = BaseFieldDefinition::create('changed')
138       ->setLabel(t('Translation changed time'))
139       ->setDescription(t('The Unix timestamp when the translation was most recently saved.'))
140       ->setRevisionable(TRUE)
141       ->setTranslatable(TRUE);
142     \Drupal::entityDefinitionUpdateManager()
143       ->installFieldStorageDefinition('content_translation_changed', 'paragraph', 'paragraph', $storage_definition);
144   }
145 }
146
147 /**
148  * Ensure that existing paragraphs are published.
149  */
150 function paragraphs_update_8007() {
151   \Drupal::database()
152     ->update('paragraphs_item_field_data')
153     ->fields(['status' => 1])
154     ->isNull('status')
155     ->execute();
156   \Drupal::database()
157     ->update('paragraphs_item_revision_field_data')
158     ->fields(['status' => 1])
159     ->isNull('status')
160     ->execute();
161 }
162
163 /**
164  * Ensure that the parent indexes are added to the paragraphs entity.
165  */
166 function paragraphs_update_8008() {
167   $manager = \Drupal::entityDefinitionUpdateManager();
168
169   // Get the current paragraph entity type definition, ensure the storage schema
170   // class is set.
171   $entity_type = $manager->getEntityType('paragraph')
172     ->setHandlerClass('storage_schema', ParagraphStorageSchema::class);
173
174   // Regenerate entity type indexes.
175   $manager->updateEntityType($entity_type);
176 }
177
178 /**
179  * Set the weight to 11 to override content_translation's hook_module_implements_alter implementation
180  */
181 function paragraphs_update_8009() {
182   module_set_weight('paragraphs', 11);
183 }
184
185 /**
186  * Add behavior plugins fields.
187  */
188 function paragraphs_update_8010() {
189   $storage_definition = BaseFieldDefinition::create('string_long')
190     ->setLabel(t('Behavior settings'))
191     ->setDescription(t('The behavior plugin settings'));
192   \Drupal::entityDefinitionUpdateManager()
193     ->installFieldStorageDefinition('behavior_settings', 'paragraph', 'paragraph', $storage_definition);
194 }
195
196 /**
197  * Make the behavior plugins field of Paragraphs revisionable.
198  */
199 function paragraphs_update_8011() {
200   \Drupal::database()->update('paragraphs_item_field_data')
201     ->fields(['behavior_settings' => NULL])
202     ->execute();
203
204   /** @var \Drupal\Core\Field\BaseFieldDefinition $storage_definition */
205   $storage_definition = \Drupal::entityDefinitionUpdateManager()->getFieldStorageDefinition('behavior_settings', 'paragraph');
206   $storage_definition->setRevisionable(TRUE);
207   \Drupal::entityDefinitionUpdateManager()->updateFieldStorageDefinition($storage_definition);
208 }
209
210 /**
211  * Install file module.
212  */
213 function paragraphs_update_8012() {
214   \Drupal::service('module_installer')->install(['file']);
215 }