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
389d435c
Commit
389d435c
authored
Oct 08, 2013
by
webchick
Browse files
Issue
#2101155
by andypost: Add CommentManagerInterface.
parent
122b0719
Changes
5
Hide whitespace changes
Inline
Side-by-side
core/modules/comment/lib/Drupal/comment/CommentManager.php
View file @
389d435c
...
...
@@ -14,7 +14,7 @@
/**
* Comment manager contains common functions to manage comment fields.
*/
class
CommentManager
{
class
CommentManager
implements
CommentManagerInterface
{
/**
* The field info service.
...
...
@@ -44,13 +44,7 @@ public function __construct(FieldInfo $field_info, EntityManager $entity_manager
}
/**
* Utility function to return URI of the comment's parent entity.
*
* @param \Drupal\comment\CommentInterface $comment
* The comment entity.
*
* @return array
* An array returned by \Drupal\Core\Entity\EntityInterface::uri().
* {@inheritdoc}
*/
public
function
getParentEntityUri
(
CommentInterface
$comment
)
{
return
$this
->
entityManager
...
...
@@ -60,19 +54,7 @@ public function getParentEntityUri(CommentInterface $comment) {
}
/**
* Utility function to return an array of comment fields.
*
* @param string $entity_type
* The entity type to return fields which are attached on.
*
* @return array
* An array of comment field map definitions, keyed by field name. Each
* value is an array with two entries:
* - type: The field type.
* - bundles: The bundles in which the field appears, as an array with entity
* types as keys and the array of bundle names as values.
*
* @see field_info_field_map()
* {@inheritdoc}
*/
public
function
getFields
(
$entity_type
=
NULL
)
{
$map
=
$this
->
getAllFields
();
...
...
@@ -83,7 +65,7 @@ public function getFields($entity_type = NULL) {
}
/**
*
Utility function to return all comment fields.
*
{@inheritdoc}
*/
public
function
getAllFields
()
{
$map
=
$this
->
fieldInfo
->
getFieldMap
();
...
...
@@ -100,20 +82,7 @@ public function getAllFields() {
}
/**
* Utility method to add the default comment field to an entity.
*
* Attaches a comment field named 'comment' to the given entity type and
* bundle. Largely replicates the default behaviour in Drupal 7 and earlier.
*
* @param string $entity_type
* The entity type to attach the default comment field to.
* @param string $bundle
* The bundle to attach the default comment field instance to.
* @param string $field_name
* (optional) Field name to use for the comment field. Defaults to 'comment'.
* @param int $default_value
* (optional) Default value, one of COMMENT_HIDDEN, COMMENT_OPEN,
* COMMENT_CLOSED. Defaults to COMMENT_OPEN.
* {@inheritdoc}
*/
public
function
addDefaultField
(
$entity_type
,
$bundle
,
$field_name
=
'comment'
,
$default_value
=
COMMENT_OPEN
)
{
// Make sure the field doesn't already exist.
...
...
@@ -170,12 +139,7 @@ public function addDefaultField($entity_type, $bundle, $field_name = 'comment',
}
/**
* Creates a comment_body field instance.
*
* @param string $entity_type
* The type of the entity to which the comment field attached.
* @param string $field_name
* Name of the comment field to add comment_body field.
* {@inheritdoc}
*/
public
function
addBodyField
(
$entity_type
,
$field_name
)
{
// Create the field if needed.
...
...
@@ -224,13 +188,7 @@ public function addBodyField($entity_type, $field_name) {
}
/**
* Builds human readable page title for field_ui management screens.
*
* @param string $field_name
* The comment field for which the overview is to be displayed.
*
* @return string
* The human readable field name.
* {@inheritdoc}
*/
public
function
getFieldUIPageTitle
(
$field_name
)
{
list
(
$entity_type
,
$field
)
=
explode
(
'__'
,
$field_name
,
2
);
...
...
core/modules/comment/lib/Drupal/comment/CommentManagerInterface.php
0 → 100644
View file @
389d435c
<?php
/**
* @file
* Contains \Drupal\comment\CommentManagerInterface.
*/
namespace
Drupal\comment
;
/**
* Comment manager contains common functions to manage comment fields.
*/
interface
CommentManagerInterface
{
/**
* Utility function to return URI of the comment's parent entity.
*
* @param \Drupal\comment\CommentInterface $comment
* The comment entity.
*
* @return array
* An array returned by \Drupal\Core\Entity\EntityInterface::uri().
*/
public
function
getParentEntityUri
(
CommentInterface
$comment
);
/**
* Utility function to return an array of comment fields.
*
* @param string $entity_type
* The entity type to return fields which are attached on.
*
* @return array
* An array of comment field map definitions, keyed by field name. Each
* value is an array with two entries:
* - type: The field type.
* - bundles: The bundles in which the field appears, as an array with entity
* types as keys and the array of bundle names as values.
*
* @see field_info_field_map()
*/
public
function
getFields
(
$entity_type
=
NULL
);
/**
* Utility function to return all comment fields.
*/
public
function
getAllFields
();
/**
* Utility method to add the default comment field to an entity.
*
* Attaches a comment field named 'comment' to the given entity type and
* bundle. Largely replicates the default behaviour in Drupal 7 and earlier.
*
* @param string $entity_type
* The entity type to attach the default comment field to.
* @param string $bundle
* The bundle to attach the default comment field instance to.
* @param string $field_name
* (optional) Field name to use for the comment field. Defaults to 'comment'.
* @param int $default_value
* (optional) Default value, one of COMMENT_HIDDEN, COMMENT_OPEN,
* COMMENT_CLOSED. Defaults to COMMENT_OPEN.
*/
public
function
addDefaultField
(
$entity_type
,
$bundle
,
$field_name
=
'comment'
,
$default_value
=
COMMENT_OPEN
);
/**
* Creates a comment_body field instance.
*
* @param string $entity_type
* The type of the entity to which the comment field attached.
* @param string $field_name
* Name of the comment field to add comment_body field.
*/
public
function
addBodyField
(
$entity_type
,
$field_name
);
/**
* Builds human readable page title for field_ui management screens.
*
* @param string $field_name
* The comment field for which the overview is to be displayed.
*
* @return string
* The human readable field name.
*/
public
function
getFieldUIPageTitle
(
$field_name
);
}
core/modules/comment/lib/Drupal/comment/Controller/AdminController.php
View file @
389d435c
...
...
@@ -10,7 +10,7 @@
use
Drupal\Component\Utility\String
;
use
Drupal\Core\Controller\ControllerBase
;
use
Drupal\Core\DependencyInjection\ContainerInjectionInterface
;
use
Drupal\comment\CommentManager
;
use
Drupal\comment\CommentManager
Interface
;
use
Drupal\field\FieldInfo
;
use
Symfony\Component\DependencyInjection\ContainerInterface
;
...
...
@@ -29,7 +29,7 @@ class AdminController extends ControllerBase implements ContainerInjectionInterf
/**
* The comment manager service.
*
* @var \Drupal\comment\CommentManager
* @var \Drupal\comment\CommentManager
Interface
*/
protected
$commentManager
;
...
...
@@ -48,10 +48,10 @@ public static function create(ContainerInterface $container) {
*
* @param \Drupal\field\FieldInfo $field_info
* The field info service.
* @param \Drupal\comment\CommentManager $comment_manager
* @param \Drupal\comment\CommentManager
Interface
$comment_manager
* The comment manager service.
*/
public
function
__construct
(
FieldInfo
$field_info
,
CommentManager
$comment_manager
)
{
public
function
__construct
(
FieldInfo
$field_info
,
CommentManager
Interface
$comment_manager
)
{
$this
->
fieldInfo
=
$field_info
;
$this
->
commentManager
=
$comment_manager
;
}
...
...
core/modules/comment/lib/Drupal/comment/Controller/CommentController.php
View file @
389d435c
...
...
@@ -8,7 +8,7 @@
namespace
Drupal\comment\Controller
;
use
Drupal\comment\CommentInterface
;
use
Drupal\comment\CommentManager
;
use
Drupal\comment\CommentManager
Interface
;
use
Drupal\field\FieldInfo
;
use
Drupal\Core\Access\CsrfTokenGenerator
;
use
Drupal\Core\Controller\ControllerBase
;
...
...
@@ -61,7 +61,7 @@ class CommentController extends ControllerBase implements ContainerInjectionInte
/**
* The comment manager service.
*
* @var \Drupal\comment\CommentManager
* @var \Drupal\comment\CommentManager
Interface
*/
protected
$commentManager
;
...
...
@@ -76,10 +76,10 @@ class CommentController extends ControllerBase implements ContainerInjectionInte
* The current user service.
* @param \Drupal\field\FieldInfo $field_info
* Field Info service.
* @param \Drupal\comment\CommentManager $comment_manager
* @param \Drupal\comment\CommentManager
Interface
$comment_manager
* The comment manager service.
*/
public
function
__construct
(
HttpKernelInterface
$httpKernel
,
CsrfTokenGenerator
$csrf_token
,
AccountInterface
$current_user
,
FieldInfo
$field_info
,
CommentManager
$comment_manager
)
{
public
function
__construct
(
HttpKernelInterface
$httpKernel
,
CsrfTokenGenerator
$csrf_token
,
AccountInterface
$current_user
,
FieldInfo
$field_info
,
CommentManager
Interface
$comment_manager
)
{
$this
->
httpKernel
=
$httpKernel
;
$this
->
csrfToken
=
$csrf_token
;
$this
->
currentUser
=
$current_user
;
...
...
core/modules/comment/lib/Drupal/comment/Form/DeleteForm.php
View file @
389d435c
...
...
@@ -7,7 +7,7 @@
namespace
Drupal\comment\Form
;
use
Drupal\comment\CommentManager
;
use
Drupal\comment\CommentManager
Interface
;
use
Drupal\Core\Cache\Cache
;
use
Drupal\Core\Entity\ContentEntityConfirmFormBase
;
use
Symfony\Component\DependencyInjection\ContainerInterface
;
...
...
@@ -20,17 +20,17 @@ class DeleteForm extends ContentEntityConfirmFormBase {
/**
* The comment manager.
*
* @var \Drupal\comment\CommentManager
* @var \Drupal\comment\CommentManager
Interface
*/
protected
$commentManager
;
/**
* Constructs a DeleteForm object.
*
* @param \Drupal\comment\CommentManager $comment_manager
* @param \Drupal\comment\CommentManager
Interface
$comment_manager
* The comment manager service.
*/
public
function
__construct
(
CommentManager
$comment_manager
)
{
public
function
__construct
(
CommentManager
Interface
$comment_manager
)
{
$this
->
commentManager
=
$comment_manager
;
}
...
...
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