Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
drupal
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
drupal
Commits
e7f8c6d7
Commit
e7f8c6d7
authored
Jul 7, 2014
by
Alex Pott
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#2289989
by marcingy, andypost: Remove comment_add and inline final occurrence.
parent
cfe3e159
No related branches found
No related tags found
2 merge requests
!7452
Issue #1797438. HTML5 validation is preventing form submit and not fully...
,
!789
Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
core/modules/comment/comment.module
+0
-27
0 additions, 27 deletions
core/modules/comment/comment.module
core/modules/comment/src/Plugin/Field/FieldFormatter/CommentDefaultFormatter.php
+22
-3
22 additions, 3 deletions
...c/Plugin/Field/FieldFormatter/CommentDefaultFormatter.php
with
22 additions
and
30 deletions
core/modules/comment/comment.module
+
0
−
27
View file @
e7f8c6d7
...
...
@@ -505,33 +505,6 @@ function comment_node_view_alter(array &$build, EntityInterface $node, EntityVie
}
}
/**
* Returns a rendered form to comment the given entity.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity to which the comments are in reply to.
* @param string $field_name
* The field name where the comments were entered.
* @param int $pid
* (optional) Some comments are replies to other comments. In those cases,
* $pid is the parent comment's comment ID. Defaults to NULL.
*
* @return array
* The renderable array for the comment addition form.
*/
function
comment_add
(
EntityInterface
$entity
,
$field_name
=
'comment'
,
$pid
=
NULL
)
{
$field
=
Fieldconfig
::
loadByName
(
$entity
->
getEntityTypeId
(),
$field_name
);
$values
=
array
(
'entity_type'
=>
$entity
->
getEntityTypeId
(),
'entity_id'
=>
$entity
->
id
(),
'field_name'
=>
$field_name
,
'comment_type'
=>
$field
->
getSetting
(
'bundle'
),
'pid'
=>
$pid
,
);
$comment
=
entity_create
(
'comment'
,
$values
);
return
\Drupal
::
service
(
'entity.form_builder'
)
->
getForm
(
$comment
);
}
/**
* Retrieves comments for a thread.
*
...
...
This diff is collapsed.
Click to expand it.
core/modules/comment/src/Plugin/Field/FieldFormatter/CommentDefaultFormatter.php
+
22
−
3
View file @
e7f8c6d7
...
...
@@ -10,6 +10,7 @@
use
Drupal\comment\CommentStorageInterface
;
use
Drupal\comment\Plugin\Field\FieldType\CommentItemInterface
;
use
Drupal\Core\Entity\EntityViewBuilderInterface
;
use
Drupal\Core\Entity\EntityFormBuilderInterface
;
use
Drupal\Core\Field\FieldItemListInterface
;
use
Drupal\Core\Session\AccountInterface
;
use
Drupal\Core\Field\FieldDefinitionInterface
;
...
...
@@ -64,6 +65,13 @@ public static function defaultSettings() {
*/
protected
$viewBuilder
;
/**
* The entity form builder.
*
* @var \Drupal\Core\Entity\EntityFormBuilderInterface
*/
protected
$entityFormBuilder
;
/**
* {@inheritdoc}
*/
...
...
@@ -78,7 +86,8 @@ public static function create(ContainerInterface $container, array $configuratio
$configuration
[
'third_party_settings'
],
$container
->
get
(
'current_user'
),
$container
->
get
(
'entity.manager'
)
->
getStorage
(
'comment'
),
$container
->
get
(
'entity.manager'
)
->
getViewBuilder
(
'comment'
)
$container
->
get
(
'entity.manager'
)
->
getViewBuilder
(
'comment'
),
$container
->
get
(
'entity.form_builder'
)
);
}
...
...
@@ -105,12 +114,15 @@ public static function create(ContainerInterface $container, array $configuratio
* The comment storage.
* @param \Drupal\Core\Entity\EntityViewBuilderInterface $comment_view_builder
* The comment view builder.
* @param \Drupal\Core\Entity\EntityFormBuilderInterface $entity_form_builder
* The entity form builder.
*/
public
function
__construct
(
$plugin_id
,
$plugin_definition
,
FieldDefinitionInterface
$field_definition
,
array
$settings
,
$label
,
$view_mode
,
array
$third_party_settings
,
AccountInterface
$current_user
,
CommentStorageInterface
$comment_storage
,
EntityViewBuilderInterface
$comment_view_builder
)
{
public
function
__construct
(
$plugin_id
,
$plugin_definition
,
FieldDefinitionInterface
$field_definition
,
array
$settings
,
$label
,
$view_mode
,
array
$third_party_settings
,
AccountInterface
$current_user
,
CommentStorageInterface
$comment_storage
,
EntityViewBuilderInterface
$comment_view_builder
,
EntityFormBuilderInterface
$entity_form_builder
)
{
parent
::
__construct
(
$plugin_id
,
$plugin_definition
,
$field_definition
,
$settings
,
$label
,
$view_mode
,
$third_party_settings
);
$this
->
viewBuilder
=
$comment_view_builder
;
$this
->
storage
=
$comment_storage
;
$this
->
currentUser
=
$current_user
;
$this
->
entityFormBuilder
=
$entity_form_builder
;
}
/**
...
...
@@ -174,7 +186,14 @@ public function viewElements(FieldItemListInterface $items) {
// All users in the "anonymous" role can use the same form: it is fine
// for this form to be stored in the render cache.
if
(
$this
->
currentUser
->
isAnonymous
())
{
$output
[
'comment_form'
]
=
comment_add
(
$entity
,
$field_name
);
$comment
=
$this
->
storage
->
create
(
array
(
'entity_type'
=>
$entity
->
getEntityTypeId
(),
'entity_id'
=>
$entity
->
id
(),
'field_name'
=>
$field_name
,
'comment_type'
=>
$this
->
getFieldSetting
(
'comment_type'
),
'pid'
=>
NULL
,
));
$output
[
'comment_form'
]
=
$this
->
entityFormBuilder
->
getForm
(
$comment
);
}
// All other users need a user-specific form, which would break the
// render cache: hence use a #post_render_cache callback.
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment