Hi,

I'm creating a script to migrate redirects from an old site to the new one.

When a redirect is imported I want to check if that redirect already exists, if so update it instead of creating a new one.

But when I'm executing an entity query searching for the 'redirect_source' field I get an error that that field doesn't exist!
When I Devel a redirect the field clearly exists.

This is the query:

$rid = \Drupal::entityQuery('redirect')
      ->condition('redirect_source', $source)
      ->execute();

Does someone maybe know a solution to this?

Thanks,
- Perry

Comments

perryjanssen created an issue. See original summary.

mr.baileys’s picture

Category: Bug report » Support request
Status: Active » Fixed

You can use \Drupal\redirect\RedirectRepository::findBySourcePath($source_path) to get redirect entities for a given source path.

If you do want/need to use EntityQuery, the redirect_source field has multiple columns (path & query), so you'll need to specify the column name:

$rid = \Drupal::entityQuery('redirect')
      ->condition('redirect_source.path', $source)
      ->execute();

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.