X-Git-Url: http://aleph1.co.uk/gitweb/?a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Fblock_content%2Fblock_content.install;h=43c832b552a77890ba1d789f7dddb94ce5cf030e;hb=5b8bb166bfa98770daef9de5c127fc2e6ef02340;hp=6af2ac4e8f2569531443e6a145fe227d3d897bb1;hpb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;p=yaffs-website diff --git a/web/core/modules/block_content/block_content.install b/web/core/modules/block_content/block_content.install index 6af2ac4e8..43c832b55 100644 --- a/web/core/modules/block_content/block_content.install +++ b/web/core/modules/block_content/block_content.install @@ -6,6 +6,7 @@ */ use Drupal\Core\Field\BaseFieldDefinition; +use Drupal\Core\StringTranslation\TranslatableMarkup; /** * Add 'revision_translation_affected' field to 'block_content' entities. @@ -70,5 +71,70 @@ function block_content_update_8300() { $entity_type = $definition_update_manager->getEntityType('block_content'); $entity_type->set('revision_data_table', 'block_content_field_revision'); $definition_update_manager->updateEntityType($entity_type); +} + +/** + * Add a publishing status field for block_content entities. + */ +function block_content_update_8400() { + $definition_update_manager = \Drupal::entityDefinitionUpdateManager(); + + // Add the published entity key to the block_content entity type. + $entity_type = $definition_update_manager->getEntityType('block_content'); + $entity_keys = $entity_type->getKeys(); + $entity_keys['published'] = 'status'; + $entity_type->set('entity_keys', $entity_keys); + $definition_update_manager->updateEntityType($entity_type); + + // Add the publishing status field to the block_content entity type. + $status = BaseFieldDefinition::create('boolean') + ->setLabel(new TranslatableMarkup('Publishing status')) + ->setDescription(new TranslatableMarkup('A boolean indicating the published state.')) + ->setRevisionable(TRUE) + ->setTranslatable(TRUE) + ->setDefaultValue(TRUE); + $has_content_translation_status_field = $definition_update_manager->getFieldStorageDefinition('content_translation_status', 'block_content'); + if ($has_content_translation_status_field) { + $status->setInitialValueFromField('content_translation_status', TRUE); + } + else { + $status->setInitialValue(TRUE); + } + $definition_update_manager->installFieldStorageDefinition('status', 'block_content', 'block_content', $status); + + // Uninstall the 'content_translation_status' field if needed. + $database = \Drupal::database(); + if ($has_content_translation_status_field) { + // First we have to remove the field data. + $database->update($entity_type->getDataTable()) + ->fields(['content_translation_status' => NULL]) + ->execute(); + + // A site may have disabled revisionability for this entity type. + if ($entity_type->isRevisionable()) { + $database->update($entity_type->getRevisionDataTable()) + ->fields(['content_translation_status' => NULL]) + ->execute(); + } + + $content_translation_status = $definition_update_manager->getFieldStorageDefinition('content_translation_status', 'block_content'); + $definition_update_manager->uninstallFieldStorageDefinition($content_translation_status); + } +} + +/** + * Add 'reusable' field to 'block_content' entities. + */ +function block_content_update_8600() { + $reusable = BaseFieldDefinition::create('boolean') + ->setLabel(t('Reusable')) + ->setDescription(t('A boolean indicating whether this block is reusable.')) + ->setTranslatable(FALSE) + ->setRevisionable(FALSE) + ->setDefaultValue(TRUE) + ->setInitialValue(TRUE); + + \Drupal::entityDefinitionUpdateManager() + ->installFieldStorageDefinition('reusable', 'block_content', 'block_content', $reusable); }