Updated all the contrib modules to their latest versions.
[yaffs-website] / web / modules / contrib / redirect / src / Entity / Redirect.php
index ae54ec576b94cc0a4a5bd63387a2af25f8017ab7..cb5d4c56dd54f1bd12c3af2d4a5260133d590806 100644 (file)
@@ -3,7 +3,6 @@
 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;
@@ -25,7 +24,7 @@ use Drupal\link\LinkItemInterface;
  *       "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",
@@ -62,7 +61,7 @@ class Redirect extends ContentEntityBase {
    */
   public static function generateHash($source_path, array $source_query, $language) {
     $hash = array(
-      'source' => Unicode::strtolower($source_path),
+      'source' => mb_strtolower($source_path),
       'language' => $language,
     );
 
@@ -86,7 +85,9 @@ class Redirect extends ContentEntityBase {
    * {@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));
   }
 
   /**
@@ -205,7 +206,9 @@ class Redirect extends ContentEntityBase {
    */
   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]);
   }
 
   /**