You are here

function url_redirect_update_8101 in Url Redirect 8.2

Same name and namespace in other branches
  1. 8 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() {
  $redirects = \Drupal::entityTypeManager()
    ->getStorage('url_redirect')
    ->getQuery()
    ->notExists('user')
    ->execute();
  foreach ($redirects as $redirect) {
    $entity = \Drupal::entityTypeManager()
      ->getStorage('url_redirect')
      ->load($redirect);
    $entity
      ->set('user', [
      [
        'target_id' => '0',
      ],
    ]);
    $entity
      ->save();
  }
}