You are here

function entityqueue_update_8004 in Entityqueue 8

Add the publishing status field to subqueues.

File

./entityqueue.install, line 66
Install, update and uninstall functions for the Entityqueue module.

Code

function entityqueue_update_8004() {
  $definition_update_manager = \Drupal::entityDefinitionUpdateManager();
  $entity_type = $definition_update_manager
    ->getEntityType('entity_subqueue');

  // Add the 'published' entity key to the entity_subqueue entity type.
  $entity_keys = $entity_type
    ->getKeys();
  $entity_keys['published'] = 'status';
  $entity_type
    ->set('entity_keys', $entity_keys);
  $definition_update_manager
    ->updateEntityType($entity_type);

  // Add the status field.
  $status = BaseFieldDefinition::create('boolean')
    ->setLabel(t('Publishing status'))
    ->setDescription(t('A boolean indicating the published state.'))
    ->setRevisionable(TRUE)
    ->setTranslatable(TRUE)
    ->setDefaultValue(TRUE);
  $has_content_translation_status_field = $definition_update_manager
    ->getFieldStorageDefinition('content_translation_status', 'entity_subqueue');
  if ($has_content_translation_status_field) {
    $status
      ->setInitialValueFromField('content_translation_status', TRUE);
  }
  else {
    $status
      ->setInitialValue(TRUE);
  }
  $definition_update_manager
    ->installFieldStorageDefinition('status', 'entity_subqueue', 'entity_subqueue', $status);

  // Uninstall the 'content_translation_status' field if needed.
  if ($has_content_translation_status_field) {
    $content_translation_status = $definition_update_manager
      ->getFieldStorageDefinition('content_translation_status', 'entity_subqueue');
    $definition_update_manager
      ->uninstallFieldStorageDefinition($content_translation_status);
  }
  return t('The publishing status field has been added to Entity Subqueues.');
}