You are here

function views_url_alias_save in Views URL alias 8.2

Save URL alias.

Parameters

\Drupal\Core\Entity\EntityInterface $entity:

string|NULL $alias:

6 calls to views_url_alias_save()
views_url_alias_form_path_alias_delete_submit in ./views_url_alias.module
views_url_alias_pathauto_alias_alter in ./views_url_alias.module
Implements hook_pathauto_alias_alter().
views_url_alias_path_delete in ./views_url_alias.module
Respond to a path being deleted.
views_url_alias_path_insert in ./views_url_alias.module
Respond to a path being inserted.
views_url_alias_path_update in ./views_url_alias.module
Respond to a path being updated.

... See full list

File

./views_url_alias.module, line 174
Allows content entity Views to be filtered by path aliases.

Code

function views_url_alias_save($entity, $alias = NULL) {
  $database = \Drupal::database();
  $database
    ->delete('views_url_alias')
    ->condition('entity_id', $entity
    ->id())
    ->condition('entity_type', $entity
    ->getEntityTypeId())
    ->condition('langcode', $entity
    ->language()
    ->getId())
    ->execute();
  if (empty($alias)) {
    return;
  }
  try {
    $database
      ->insert('views_url_alias')
      ->fields([
      'alias' => $alias,
      'entity_id' => $entity
        ->id(),
      'entity_type' => $entity
        ->getEntityTypeId(),
      'langcode' => $entity
        ->language()
        ->getId(),
    ])
      ->execute();
  } catch (Exception $e) {
    watchdog_exception('views_url_alias', $e);
  }
}