Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Issue forks
linkit-2886455
Commits
7e80ae23
Commit
7e80ae23
authored
Jul 14, 2016
by
Emil Stjerneman
Committed by
Emil Stjerneman
Jul 14, 2016
Browse files
Issue
#2766593
by anon: Make the EntityMatcherDeriver more strict
parent
577c096f
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/Plugin/Derivative/EntityMatcherDeriver.php
View file @
7e80ae23
...
...
@@ -45,9 +45,12 @@ class EntityMatcherDeriver extends DeriverBase implements ContainerDeriverInterf
*/
public
function
getDerivativeDefinitions
(
$base_plugin_definition
)
{
foreach
(
$this
->
entityTypeManager
->
getDefinitions
()
as
$entity_type_id
=>
$entity_type
)
{
$has_canonical
=
$entity_type
->
hasLinkTemplate
(
'canonical'
);
$canonical
=
$entity_type
->
getLinkTemplate
(
'canonical'
);
$edit_form
=
$entity_type
->
getLinkTemplate
(
'edit-form'
);
if
(
$has_canonical
)
{
// Only entities that has a distinct canonical URI that is not the same
// as the edit-form URI will be derived.
if
(
$canonical
&&
(
$canonical
!==
$edit_form
))
{
$this
->
derivatives
[
$entity_type_id
]
=
$base_plugin_definition
;
$this
->
derivatives
[
$entity_type_id
][
'id'
]
=
$base_plugin_definition
[
'id'
]
.
':'
.
$entity_type_id
;
$this
->
derivatives
[
$entity_type_id
][
'label'
]
=
$entity_type
->
getLabel
();
...
...
tests/src/Kernel/EntityMatcherDeriverTest.php
0 → 100644
View file @
7e80ae23
<?php
namespace
Drupal\Tests\linkit\Kernel
;
use
Drupal\Core\Menu\MenuTreeParameters
;
use
Drupal\Core\StringTranslation\TranslatableMarkup
;
use
Drupal\menu_link_content
\
Entity\MenuLinkContent
;
use
Drupal\KernelTests\KernelTestBase
;
use
Symfony\Component\Routing\Route
;
/**
* Tests the entity matcher deriver.
*
* @group linkit
*/
class
EntityMatcherDeriverTest
extends
LinkitKernelTestBase
{
/**
* {@inheritdoc}
*/
public
static
$modules
=
[
'block'
,
'block_content'
,
'node'
,
'field'
];
/**
* The matcher manager.
*
* @var \Drupal\linkit\MatcherManager
*/
protected
$manager
;
/**
* {@inheritdoc}
*/
protected
function
setUp
()
{
parent
::
setUp
();
$this
->
installConfig
([
'block_content'
]);
$this
->
installEntitySchema
(
'block_content'
);
$this
->
installEntitySchema
(
'node'
);
$this
->
installConfig
([
'field'
,
'node'
]);
$this
->
manager
=
$this
->
container
->
get
(
'plugin.manager.linkit.matcher'
);
}
/**
* Tests the deriver.
*/
public
function
testDeriver
()
{
$definition
=
$this
->
manager
->
getDefinition
(
'entity:block_content'
,
FALSE
);
$this
->
assertNull
(
$definition
);
$definition
=
$this
->
manager
->
getDefinition
(
'entity:node'
,
FALSE
);
$this
->
assertNotNull
(
$definition
);
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment