Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
project
drupal
Commits
584911ae
Commit
584911ae
authored
Aug 25, 2014
by
webchick
Browse files
Issue
#2326707
by tim.plunkett: Use dynamic entity type upcasting for comment.reply.
parent
bfcd644b
Changes
5
Hide whitespace changes
Inline
Side-by-side
core/modules/comment/comment.routing.yml
View file @
584911ae
...
...
@@ -51,13 +51,17 @@ entity.comment.delete_form:
_entity_access
:
'
comment.delete'
comment.reply
:
path
:
'
/comment/reply/{entity_type}/{entity
_id
}/{field_name}/{pid}'
path
:
'
/comment/reply/{entity_type}/{entity}/{field_name}/{pid}'
defaults
:
_content
:
'
\Drupal\comment\Controller\CommentController::getReplyForm'
_title
:
'
Add
new
comment'
pid
:
~
requirements
:
_access
:
'
TRUE'
options
:
parameters
:
entity
:
type
:
entity:{entity_type}
comment.new_comments_node_links
:
path
:
'
/comments/render_new_comments_node_links'
...
...
core/modules/comment/comment.services.yml
View file @
584911ae
...
...
@@ -3,7 +3,6 @@ services:
class
:
Drupal\comment\CommentBreadcrumbBuilder
tags
:
-
{
name
:
breadcrumb_builder
,
priority
:
100
}
arguments
:
[
'
@entity.manager'
]
comment.manager
:
class
:
Drupal\comment\CommentManager
...
...
core/modules/comment/src/CommentBreadcrumbBuilder.php
View file @
584911ae
...
...
@@ -8,7 +8,6 @@
namespace
Drupal\comment
;
use
Drupal\Core\Breadcrumb\BreadcrumbBuilderInterface
;
use
Drupal\Core\Entity\EntityManagerInterface
;
use
Drupal\Core\Link
;
use
Drupal\Core\Routing\RouteMatchInterface
;
use
Drupal\Core\StringTranslation\StringTranslationTrait
;
...
...
@@ -19,31 +18,11 @@
class
CommentBreadcrumbBuilder
implements
BreadcrumbBuilderInterface
{
use
StringTranslationTrait
;
/**
* Stores the Entity manager service.
*
* @var \Drupal\Core\Entity\EntityManagerInterface
*/
protected
$entityManager
;
/**
* Constructs a CommentBreadcrumbBuilder object.
*
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
* The entity manager.
*/
public
function
__construct
(
EntityManagerInterface
$entity_manager
)
{
$this
->
entityManager
=
$entity_manager
;
}
/**
* {@inheritdoc}
*/
public
function
applies
(
RouteMatchInterface
$route_match
)
{
return
$route_match
->
getRouteName
()
==
'comment.reply'
&&
$route_match
->
getParameter
(
'entity_type'
)
&&
$route_match
->
getParameter
(
'entity_id'
)
&&
$route_match
->
getParameter
(
'field_name'
);
return
$route_match
->
getRouteName
()
==
'comment.reply'
&&
$route_match
->
getParameter
(
'entity'
);
}
/**
...
...
@@ -53,9 +32,7 @@ public function build(RouteMatchInterface $route_match) {
$breadcrumb
=
array
();
$breadcrumb
[]
=
Link
::
createFromRoute
(
$this
->
t
(
'Home'
),
'<front>'
);
$entity
=
$this
->
entityManager
->
getStorage
(
$route_match
->
getParameter
(
'entity_type'
))
->
load
(
$route_match
->
getParameter
(
'entity_id'
));
$entity
=
$route_match
->
getParameter
(
'entity'
);
$breadcrumb
[]
=
new
Link
(
$entity
->
label
(),
$entity
->
urlInfo
());
return
$breadcrumb
;
}
...
...
core/modules/comment/src/CommentLinkBuilder.php
View file @
584911ae
...
...
@@ -139,7 +139,7 @@ public function buildCommentedEntityLinks(ContentEntityInterface $entity, array
$links
[
'comment-add'
][
'route_name'
]
=
'comment.reply'
;
$links
[
'comment-add'
][
'route_parameters'
]
=
array
(
'entity_type'
=>
$entity
->
getEntityTypeId
(),
'entity
_id
'
=>
$entity
->
id
(),
'entity'
=>
$entity
->
id
(),
'field_name'
=>
$field_name
,
);
}
...
...
@@ -174,7 +174,7 @@ public function buildCommentedEntityLinks(ContentEntityInterface $entity, array
$links
[
'comment-add'
][
'route_name'
]
=
'comment.reply'
;
$links
[
'comment-add'
][
'route_parameters'
]
=
array
(
'entity_type'
=>
$entity
->
getEntityTypeId
(),
'entity
_id
'
=>
$entity
->
id
(),
'entity'
=>
$entity
->
id
(),
'field_name'
=>
$field_name
,
);
}
...
...
core/modules/comment/src/Controller/CommentController.php
View file @
584911ae
...
...
@@ -143,7 +143,7 @@ public function redirectNode(EntityInterface $node) {
if
(
!
empty
(
$fields
)
&&
(
$field_names
=
array_keys
(
$fields
))
&&
(
$field_name
=
reset
(
$field_names
)))
{
return
$this
->
redirect
(
'comment.reply'
,
array
(
'entity_type'
=>
'node'
,
'entity
_id
'
=>
$node
->
id
(),
'entity'
=>
$node
->
id
(),
'field_name'
=>
$field_name
,
));
}
...
...
@@ -162,10 +162,8 @@ public function redirectNode(EntityInterface $node) {
*
* @param \Symfony\Component\HttpFoundation\Request $request
* The current request object.
* @param string $entity_type
* Every comment belongs to an entity. This is the type of the entity.
* @param string $entity_id
* Every comment belongs to an entity. This is the ID of the entity.
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity this comment belongs to.
* @param string $field_name
* The field_name to which the comment belongs.
* @param int $pid
...
...
@@ -191,11 +189,10 @@ public function redirectNode(EntityInterface $node) {
* - If user is not authorized to view comments.
* - If current entity comments are disable.
*/
public
function
getReplyForm
(
Request
$request
,
$entity_type
,
$entity_id
,
$field_name
,
$pid
=
NULL
)
{
public
function
getReplyForm
(
Request
$request
,
EntityInterface
$entity
,
$field_name
,
$pid
=
NULL
)
{
// Check if entity and field exists.
$fields
=
$this
->
commentManager
->
getFields
(
$entity
_type
);
if
(
empty
(
$fields
[
$field_name
])
||
!
(
$entity
=
$this
->
entityManager
()
->
getStorage
(
$entity_type
)
->
load
(
$entity_id
))
)
{
$fields
=
$this
->
commentManager
->
getFields
(
$entity
->
getEntityTypeId
()
);
if
(
empty
(
$fields
[
$field_name
]))
{
throw
new
NotFoundHttpException
();
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a 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