Unverified Commit d0e9ea09 authored by larowlan's avatar larowlan

Issue #2914785 by acbramley, jungle, Hardik_Patel_12, mrinalini9, larowlan:...

Issue #2914785 by acbramley, jungle, Hardik_Patel_12, mrinalini9, larowlan: Entities with external urls as a uri relationship can not be deleted when menu_link_content is installed
parent 582584e4
......@@ -104,6 +104,11 @@ function menu_link_content_entity_predelete(EntityInterface $entity) {
$entity_type_id = $entity->getEntityTypeId();
foreach ($entity->uriRelationships() as $rel) {
$url = $entity->toUrl($rel);
// Entities can provide uri relationships that are not routed, in this case
// getRouteParameters() will throw an exception.
if (!$url->isRouted()) {
continue;
}
$route_parameters = $url->getRouteParameters();
if (!isset($route_parameters[$entity_type_id])) {
// Do not delete links which do not relate to this exact entity. For
......
......@@ -4,6 +4,7 @@
use Drupal\Component\Render\FormattableMarkup;
use Drupal\Core\Menu\MenuTreeParameters;
use Drupal\entity_test\Entity\EntityTestExternal;
use Drupal\KernelTests\KernelTestBase;
use Drupal\menu_link_content\Entity\MenuLinkContent;
use Drupal\system\Entity\Menu;
......@@ -17,11 +18,10 @@
class MenuLinksTest extends KernelTestBase {
/**
* Modules to enable.
*
* @var array
* {@inheritdoc}
*/
public static $modules = [
protected static $modules = [
'entity_test',
'link',
'menu_link_content',
'router_test',
......@@ -46,6 +46,7 @@ protected function setUp() {
$this->installSchema('system', ['sequences']);
$this->installSchema('user', ['users_data']);
$this->installEntitySchema('entity_test_external');
$this->installEntitySchema('menu_link_content');
$this->installEntitySchema('user');
......@@ -163,6 +164,12 @@ public function testMenuLinkOnEntityDelete() {
$user = User::create(['name' => 'username']);
$user->save();
// Create External test entity.
$external_entity = EntityTestExternal::create();
$external_entity->save();
// Ensure an external entity can be deleted.
$external_entity->delete();
// Create "canonical" menu link pointing to the user.
$menu_link_content = MenuLinkContent::create([
'title' => 'username profile',
......
<?php
namespace Drupal\entity_test\Entity;
use Drupal\Core\Url;
/**
* Test entity class.
*
* @ContentEntityType(
* id = "entity_test_external",
* label = @Translation("Entity test external"),
* base_table = "entity_test_external",
* entity_keys = {
* "id" = "id",
* "uuid" = "uuid",
* "bundle" = "type",
* },
* links = {
* "canonical" = "/entity_test_external/{entity_test_external}"
* },
* )
*/
class EntityTestExternal extends EntityTest {
/**
* {@inheritdoc}
*/
public function toUrl($rel = 'canonical', array $options = []) {
if ($rel === 'canonical') {
return Url::fromUri('http://example.com', $options);
}
return parent::toUrl($rel, $options);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment