Drupal 9 - Path Alias - Alle duplikate/mehrfache URLs löschen

Delete all duplicate URL Aliases ( langcode-path-alias ) :


function drupal9_delete_all_duplicate_path_aliases( )
{
    
    $properties = []; // $properties = [ 'path' => '/node/123' ]
    $path_alias_manager = \Drupal::entityTypeManager()->getStorage('path_alias');
    $alias_objects = $path_alias_manager->loadByProperties( $properties );
    
    $unique_alias_arr = [];
    
    foreach($alias_objects as $alias_object) {


        $path       = $alias_object->getAlias();
        $alias      = $alias_object->getPath();
        $langcode   = $alias_object->language()->getId();

        $path_and_alias = $langcode . $path . $alias ;

        if( empty( $unique_alias_arr[ $path_and_alias ] ) ) {
            $unique_alias_arr[ $path_and_alias ] = $path_and_alias;
        } else {
            $alias_object->delete();
        }
    }
}

 

Neuen Kommentar schreiben

CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.

Suche

Neueste Kommentare