Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / modules / block_content / block_content.install
1 <?php
2
3 /**
4  * @file
5  * Install, update and uninstall functions for the block_content module.
6  */
7
8 use Drupal\Core\Field\BaseFieldDefinition;
9 use Drupal\Core\StringTranslation\TranslatableMarkup;
10
11 /**
12  * Add 'revision_translation_affected' field to 'block_content' entities.
13  */
14 function block_content_update_8001() {
15   // Install the definition that this field had in
16   // \Drupal\block_content\Entity\BlockContent::baseFieldDefinitions()
17   // at the time that this update function was written. If/when code is
18   // deployed that changes that definition, the corresponding module must
19   // implement an update function that invokes
20   // \Drupal::entityDefinitionUpdateManager()->updateFieldStorageDefinition()
21   // with the new definition.
22   $storage_definition = BaseFieldDefinition::create('boolean')
23     ->setLabel(t('Revision translation affected'))
24     ->setDescription(t('Indicates if the last edit of a translation belongs to current revision.'))
25     ->setReadOnly(TRUE)
26     ->setRevisionable(TRUE)
27     ->setTranslatable(TRUE);
28
29   \Drupal::entityDefinitionUpdateManager()
30     ->installFieldStorageDefinition('revision_translation_affected', 'block_content', 'block_content', $storage_definition);
31 }
32
33 /**
34  * Generalizes the d6_block_content_type and d6_block_content_body_field
35  * migrations.
36  */
37 function block_content_update_8002() {
38   // Removed in issue #2569605. The Migrate and Migrate Drupal modules are
39   // marked experimental and do not need to support the update path until they
40   // are stable.
41   // @see https://www.drupal.org/node/2569469
42 }
43
44 /**
45  * Add 'revision_created' and 'revision_user' fields to 'block_content' entities.
46  */
47 function block_content_update_8003() {
48   $revision_created = BaseFieldDefinition::create('created')
49     ->setLabel(t('Revision create time'))
50     ->setDescription(t('The time that the current revision was created.'))
51     ->setRevisionable(TRUE);
52
53   \Drupal::entityDefinitionUpdateManager()
54     ->installFieldStorageDefinition('revision_created', 'block_content', 'block_content', $revision_created);
55
56   $revision_user = BaseFieldDefinition::create('entity_reference')
57     ->setLabel(t('Revision user'))
58     ->setDescription(t('The user ID of the author of the current revision.'))
59     ->setSetting('target_type', 'user')
60     ->setRevisionable(TRUE);
61
62   \Drupal::entityDefinitionUpdateManager()
63     ->installFieldStorageDefinition('revision_user', 'block_content', 'block_content', $revision_user);
64 }
65
66 /**
67  * Fix the block_content entity type to specify its revision data table.
68  */
69 function block_content_update_8300() {
70   $definition_update_manager = \Drupal::entityDefinitionUpdateManager();
71   $entity_type = $definition_update_manager->getEntityType('block_content');
72   $entity_type->set('revision_data_table', 'block_content_field_revision');
73   $definition_update_manager->updateEntityType($entity_type);
74 }
75
76 /**
77  * Add a publishing status field for block_content entities.
78  */
79 function block_content_update_8400() {
80   $definition_update_manager = \Drupal::entityDefinitionUpdateManager();
81
82   // Add the published entity key to the block_content entity type.
83   $entity_type = $definition_update_manager->getEntityType('block_content');
84   $entity_keys = $entity_type->getKeys();
85   $entity_keys['published'] = 'status';
86   $entity_type->set('entity_keys', $entity_keys);
87   $definition_update_manager->updateEntityType($entity_type);
88
89   // Add the publishing status field to the block_content entity type.
90   $status = BaseFieldDefinition::create('boolean')
91     ->setLabel(new TranslatableMarkup('Publishing status'))
92     ->setDescription(new TranslatableMarkup('A boolean indicating the published state.'))
93     ->setRevisionable(TRUE)
94     ->setTranslatable(TRUE)
95     ->setDefaultValue(TRUE);
96
97   $has_content_translation_status_field = $definition_update_manager->getFieldStorageDefinition('content_translation_status', 'block_content');
98   if ($has_content_translation_status_field) {
99     $status->setInitialValueFromField('content_translation_status', TRUE);
100   }
101   else {
102     $status->setInitialValue(TRUE);
103   }
104   $definition_update_manager->installFieldStorageDefinition('status', 'block_content', 'block_content', $status);
105
106   // Uninstall the 'content_translation_status' field if needed.
107   $database = \Drupal::database();
108   if ($has_content_translation_status_field) {
109     // First we have to remove the field data.
110     $database->update($entity_type->getDataTable())
111       ->fields(['content_translation_status' => NULL])
112       ->execute();
113
114     // A site may have disabled revisionability for this entity type.
115     if ($entity_type->isRevisionable()) {
116       $database->update($entity_type->getRevisionDataTable())
117         ->fields(['content_translation_status' => NULL])
118         ->execute();
119     }
120
121     $content_translation_status = $definition_update_manager->getFieldStorageDefinition('content_translation_status', 'block_content');
122     $definition_update_manager->uninstallFieldStorageDefinition($content_translation_status);
123   }
124 }
125
126 /**
127  * Add 'reusable' field to 'block_content' entities.
128  */
129 function block_content_update_8600() {
130   $reusable = BaseFieldDefinition::create('boolean')
131     ->setLabel(t('Reusable'))
132     ->setDescription(t('A boolean indicating whether this block is reusable.'))
133     ->setTranslatable(FALSE)
134     ->setRevisionable(FALSE)
135     ->setDefaultValue(TRUE)
136     ->setInitialValue(TRUE);
137
138   \Drupal::entityDefinitionUpdateManager()
139     ->installFieldStorageDefinition('reusable', 'block_content', 'block_content', $reusable);
140 }