You are here

function url_redirect_update_8101 in Url Redirect 8

Same name and namespace in other branches
  1. 8.2 url_redirect.install \url_redirect_update_8101()

Set the user value to be anonymous user if the field was left empty.

File

./url_redirect.install, line 6

Code

function url_redirect_update_8101() {
  \Drupal::entityDefinitionUpdateManager()
    ->applyUpdates();
  $redirects = \Drupal::entityQuery('url_redirect')
    ->notExists('user')
    ->execute();
  foreach ($redirects as $redirect) {
    $entity = \Drupal::entityTypeManager()
      ->getStorage('url_redirect')
      ->load($redirect);
    $entity
      ->set('user', [
      [
        'target_id' => '0',
      ],
    ]);
    $entity
      ->save();
  }
}