You are here

function node_update_8003 in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/node/node.install \node_update_8003()

Promote 'status' and 'uid' fields to entity keys.

File

core/modules/node/node.install, line 196
Install, update and uninstall functions for the node module.

Code

function node_update_8003() {

  // The 'status' and 'uid' fields were added to the 'entity_keys' annotation
  // of \Drupal\node\Entity\Node in https://www.drupal.org/node/2498919, but
  // this update function wasn't added until
  // https://www.drupal.org/node/2542748.
  $manager = \Drupal::entityDefinitionUpdateManager();
  $entity_type = $manager
    ->getEntityType('node');
  $entity_keys = $entity_type
    ->getKeys();
  $entity_keys['status'] = 'status';
  $entity_keys['uid'] = 'uid';
  $entity_type
    ->set('entity_keys', $entity_keys);
  $manager
    ->updateEntityType($entity_type);

  // @todo The above should be enough, since that is the only definition that
  //   changed. But \Drupal\Core\Entity\Sql\SqlContentEntityStorageSchema varies
  //   field schema by whether a field is an entity key, so invoke
  //   EntityDefinitionUpdateManagerInterface::updateFieldStorageDefinition()
  //   with an unmodified field storage definition to trigger the necessary
  //   changes. SqlContentEntityStorageSchema::onEntityTypeUpdate() should be
  //   fixed to automatically handle this.
  //   See https://www.drupal.org/node/2554245.
  foreach (array(
    'status',
    'uid',
  ) as $field_name) {
    $manager
      ->updateFieldStorageDefinition($manager
      ->getFieldStorageDefinition($field_name, 'node'));
  }
}