diff --git a/core/lib/Drupal/Core/Url.php b/core/lib/Drupal/Core/Url.php index 34be789..999f447 100644 --- a/core/lib/Drupal/Core/Url.php +++ b/core/lib/Drupal/Core/Url.php @@ -225,7 +225,7 @@ public static function fromRouteMatch(RouteMatchInterface $route_match) { * @see static::fromRoute() */ public static function fromUri($uri, $options = array()) { - if ($uri != 'base://' && !parse_url($uri, PHP_URL_SCHEME)) { + if (!parse_url($uri, PHP_URL_SCHEME)) { throw new \InvalidArgumentException(String::format('The URI "@uri" is invalid. You must use a valid URI scheme. Use base:// for a path, e.g., to a Drupal file that needs the base path. Do not use this for internal paths controlled by Drupal.', ['@uri' => $uri])); } diff --git a/core/modules/link/src/Plugin/Field/FieldType/LinkItem.php b/core/modules/link/src/Plugin/Field/FieldType/LinkItem.php index f84fd47..145252d 100644 --- a/core/modules/link/src/Plugin/Field/FieldType/LinkItem.php +++ b/core/modules/link/src/Plugin/Field/FieldType/LinkItem.php @@ -174,4 +174,18 @@ public function getUrl() { return \Drupal::pathValidator()->getUrlIfValidWithoutAccessCheck($this->uri); } + + /** + * {@inheritdoc} + */ + public function setValue($values, $notify = TRUE) { + // Unserialize the values. + // @todo The storage controller should take care of this, see + // SqlCOntentEntityStorage::loadFieldItems. + if (isset($values['options']) && is_string($values['options'])) { + $values['options'] = unserialize($values['options']); + } + parent::setValue($values, $notify); + } + } diff --git a/core/modules/link/src/Plugin/Field/FieldWidget/LinkWidget.php b/core/modules/link/src/Plugin/Field/FieldWidget/LinkWidget.php index 8d13e1b..3f3ea45 100644 --- a/core/modules/link/src/Plugin/Field/FieldWidget/LinkWidget.php +++ b/core/modules/link/src/Plugin/Field/FieldWidget/LinkWidget.php @@ -8,7 +8,6 @@ namespace Drupal\link\Plugin\Field\FieldWidget; use Drupal\Component\Utility\Unicode; -use Drupal\Component\Utility\UrlHelper; use Drupal\Core\Field\FieldItemListInterface; use Drupal\Core\Field\WidgetBase; use Drupal\Core\Form\FormStateInterface; @@ -45,7 +44,7 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen $default_url_value = NULL; if (isset($items[$delta]->uri)) { if ($url = \Drupal::pathValidator()->getUrlIfValid($items[$delta]->uri)) { - $url->setOptions($items[$delta]->options); + $url->setOptions($items[$delta]->options ?: []); $url_string = $url->toString(); $default_url_value = $url->isRouted() ? Unicode::substr($url_string, strlen(base_path())) : $url_string; } diff --git a/core/modules/shortcut/src/Controller/ShortcutSetController.php b/core/modules/shortcut/src/Controller/ShortcutSetController.php index 8d143b4..4489964 100644 --- a/core/modules/shortcut/src/Controller/ShortcutSetController.php +++ b/core/modules/shortcut/src/Controller/ShortcutSetController.php @@ -9,7 +9,6 @@ use Drupal\Core\Controller\ControllerBase; use Drupal\Core\Path\PathValidatorInterface; -use Drupal\Core\Url; use Drupal\shortcut\ShortcutSetInterface; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\RedirectResponse; diff --git a/core/modules/shortcut/src/Tests/ShortcutCacheTagsTest.php b/core/modules/shortcut/src/Tests/ShortcutCacheTagsTest.php index 0689ee1..e116214 100644 --- a/core/modules/shortcut/src/Tests/ShortcutCacheTagsTest.php +++ b/core/modules/shortcut/src/Tests/ShortcutCacheTagsTest.php @@ -46,7 +46,7 @@ protected function createEntity() { 'shortcut_set' => 'default', 'title' => t('Llama'), 'weight' => 0, - 'link' => ['url' => 'admin'], + 'link' => ['uri' => 'admin'], )); $shortcut->save(); diff --git a/core/modules/shortcut/src/Tests/ShortcutLinksTest.php b/core/modules/shortcut/src/Tests/ShortcutLinksTest.php index c186bf0..3b2461c 100644 --- a/core/modules/shortcut/src/Tests/ShortcutLinksTest.php +++ b/core/modules/shortcut/src/Tests/ShortcutLinksTest.php @@ -62,7 +62,7 @@ public function testShortcutLinkAdd() { $saved_set = ShortcutSet::load($set->id()); $paths = $this->getShortcutInformation($saved_set, 'link'); $test['path'] = $test['path'] != '' ? $test['path'] : ''; - $this->assertTrue(in_array(Url::fromUri('base://' . $test['path']), $paths), 'Shortcut created: ' . $test['path']); + $this->assertTrue(in_array($test['path'], $paths), 'Shortcut created: ' . $test['path']); $this->assertLink($title, 0, String::format('Shortcut link %url found on the page.', ['%url' => $test['path']])); } $saved_set = ShortcutSet::load($set->id()); diff --git a/core/modules/shortcut/src/Tests/ShortcutTestBase.php b/core/modules/shortcut/src/Tests/ShortcutTestBase.php index 6b6db1c..7acd3fc 100644 --- a/core/modules/shortcut/src/Tests/ShortcutTestBase.php +++ b/core/modules/shortcut/src/Tests/ShortcutTestBase.php @@ -22,7 +22,7 @@ * * @var array */ - public static $modules = array('node', 'toolbar', 'shortcut', 'views'); + public static $modules = array('node', 'toolbar', 'shortcut'); /** * User with permission to administer shortcuts. @@ -66,8 +66,8 @@ protected function setUp() { 'title' => t('Add content'), 'weight' => -20, 'link' => array( - 'url' => 'node/add', - 'route_name' => 'node.add_page', + 'uri' => 'node/add', + 'options' => [], ), )); $shortcut->save(); @@ -77,8 +77,8 @@ protected function setUp() { 'title' => t('All content'), 'weight' => -19, 'link' => array( - 'url' => 'admin/content', - 'route_name' => 'view.content.page_1', + 'uri' => 'admin/content', + 'options' => [], ), )); $shortcut->save(); @@ -128,7 +128,7 @@ function getShortcutInformation(ShortcutSetInterface $set, $key) { \Drupal::entityManager()->getStorage('shortcut')->resetCache(); foreach ($set->getShortcuts() as $shortcut) { if ($key == 'link') { - $info[] = $shortcut->getUrl()->toString(); + $info[] = $shortcut->link->uri; } else { $info[] = $shortcut->{$key}->value; diff --git a/core/modules/shortcut/src/Tests/ShortcutTranslationUITest.php b/core/modules/shortcut/src/Tests/ShortcutTranslationUITest.php index a9d3c2c..2944e1f 100644 --- a/core/modules/shortcut/src/Tests/ShortcutTranslationUITest.php +++ b/core/modules/shortcut/src/Tests/ShortcutTranslationUITest.php @@ -50,7 +50,7 @@ protected function getTranslatorPermissions() { * {@inheritdoc} */ protected function createEntity($values, $langcode, $bundle_name = NULL) { - $values['link']['route_name'] = 'user.page'; + $values['link']['uri'] = 'user'; return parent::createEntity($values, $langcode, $bundle_name); }