Saves a path alias to the database.
string $source: The internal system path.
string $alias: The URL alias.
string $langcode: The language code of the alias.
int $pid: Unique path alias identifier.
FALSE if the path could not be saved or an associative array containing the following keys:
public function save($source, $alias, $langcode = Language::LANGCODE_NOT_SPECIFIED, $pid = NULL) {
$fields = array(
'source' => $source,
'alias' => $alias,
'langcode' => $langcode,
);
// Insert or update the alias.
if (empty($pid)) {
$query = $this->connection
->insert('url_alias')
->fields($fields);
$pid = $query
->execute();
$fields['pid'] = $pid;
// @todo: Find a correct place to invoke hook_path_insert().
$hook = 'path_insert';
}
else {
$fields['pid'] = $pid;
$query = $this->connection
->update('url_alias')
->fields($fields)
->condition('pid', $pid);
$pid = $query
->execute();
// @todo: figure out where we can invoke hook_path_update()
$hook = 'path_update';
}
if ($pid) {
// @todo Switch to using an event for this instead of a hook.
module_invoke_all($hook, $fields);
$this->alias_manager
->cacheClear();
return $fields;
}
return FALSE;
}