namespace Drupal\redirect\Entity;
use Drupal\Component\Utility\Crypt;
-use Drupal\Component\Utility\Unicode;
use Drupal\Component\Utility\UrlHelper;
use Drupal\Core\Entity\ContentEntityBase;
use Drupal\Core\Entity\EntityStorageInterface;
* "delete" = "Drupal\redirect\Form\RedirectDeleteForm",
* "edit" = "Drupal\redirect\Form\RedirectForm"
* },
- * "views_data" = "Drupal\views\EntityViewsData",
+ * "views_data" = "Drupal\redirect\RedirectViewsData",
* "storage_schema" = "\Drupal\redirect\RedirectStorageSchema"
* },
* base_table = "redirect",
*/
public static function generateHash($source_path, array $source_query, $language) {
$hash = array(
- 'source' => Unicode::strtolower($source_path),
+ 'source' => mb_strtolower($source_path),
'language' => $language,
);
* {@inheritdoc}
*/
public function preSave(EntityStorageInterface $storage_controller) {
- $this->set('hash', Redirect::generateHash($this->redirect_source->path, (array) $this->redirect_source->query, $this->language()->getId()));
+ // Get the language code directly from the field as language() might not
+ // be up to date if the language was just changed.
+ $this->set('hash', Redirect::generateHash($this->redirect_source->path, (array) $this->redirect_source->query, $this->get('language')->value));
}
/**
*/
public function setRedirect($url, array $query = array(), array $options = array()) {
$uri = $url . ($query ? '?' . UrlHelper::buildQuery($query) : '');
- $this->redirect_redirect->set(0, ['uri' => 'internal:/' . ltrim($uri, '/'), 'options' => $options]);
+ $external = UrlHelper::isValid($url, TRUE);
+ $uri = ($external ? $url : 'internal:/' . ltrim($uri, '/'));
+ $this->redirect_redirect->set(0, ['uri' => $uri, 'options' => $options]);
}
/**