core/modules/shortcut/src/Entity/Shortcut.php | 14 -------------- core/modules/shortcut/src/ShortcutForm.php | 8 +++++--- core/modules/shortcut/src/Tests/ShortcutCacheTagsTest.php | 1 - 3 files changed, 5 insertions(+), 18 deletions(-) diff --git a/core/modules/shortcut/src/Entity/Shortcut.php b/core/modules/shortcut/src/Entity/Shortcut.php index ec344d8..200ecf8 100644 --- a/core/modules/shortcut/src/Entity/Shortcut.php +++ b/core/modules/shortcut/src/Entity/Shortcut.php @@ -12,7 +12,6 @@ use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Field\FieldDefinition; -use Drupal\Core\Url; use Drupal\shortcut\ShortcutInterface; /** @@ -126,19 +125,6 @@ public static function preCreate(EntityStorageInterface $storage, array &$values /** * {@inheritdoc} */ - public function preSave(EntityStorageInterface $storage) { - parent::preSave($storage); - - if ($this->isNew() || !empty($this->path->value)) { - $url = Url::createFromPath($this->path->value); - $this->setRouteName($url->getRouteName()); - $this->setRouteParams($url->getRouteParameters()); - } - } - - /** - * {@inheritdoc} - */ public function postSave(EntityStorageInterface $storage, $update = TRUE) { parent::postSave($storage, $update); diff --git a/core/modules/shortcut/src/ShortcutForm.php b/core/modules/shortcut/src/ShortcutForm.php index 0e101ff..4764ddc 100644 --- a/core/modules/shortcut/src/ShortcutForm.php +++ b/core/modules/shortcut/src/ShortcutForm.php @@ -9,6 +9,7 @@ use Drupal\Core\Entity\ContentEntityForm; use Drupal\Core\Language\Language; +use Drupal\Core\Url; /** * Form controller for the shortcut entity forms. @@ -53,9 +54,10 @@ public function form(array $form, array &$form_state) { public function buildEntity(array $form, array &$form_state) { $entity = parent::buildEntity($form, $form_state); - // Set the computed 'path' value so it can used in the preSave() method to - // derive the route name and parameters. - $entity->path->value = $form_state['values']['path']; + // Transform the (computed) 'path' value to a route name and parameters. + $url = Url::createFromPath($form_state['values']['path']); + $entity->setRouteName($url->getRouteName()); + $entity->setRouteParams($url->getRouteParameters()); return $entity; } diff --git a/core/modules/shortcut/src/Tests/ShortcutCacheTagsTest.php b/core/modules/shortcut/src/Tests/ShortcutCacheTagsTest.php index bdaf44b..6178538 100644 --- a/core/modules/shortcut/src/Tests/ShortcutCacheTagsTest.php +++ b/core/modules/shortcut/src/Tests/ShortcutCacheTagsTest.php @@ -44,7 +44,6 @@ public function setUp() { */ protected function createEntity() { // Create a "Llama" shortcut. - /** @var \Drupal\shortcut\Entity\Shortcut $shortcut */ $shortcut = entity_create('shortcut', array( 'set' => 'default', 'title' => t('Llama'),