Commit 389d435c authored by webchick's avatar webchick

Issue #2101155 by andypost: Add CommentManagerInterface.

parent 122b0719
......@@ -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);
......
<?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);
}
......@@ -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\CommentManagerInterface;
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\CommentManagerInterface
*/
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\CommentManagerInterface $comment_manager
* The comment manager service.
*/
public function __construct(FieldInfo $field_info, CommentManager $comment_manager) {
public function __construct(FieldInfo $field_info, CommentManagerInterface $comment_manager) {
$this->fieldInfo = $field_info;
$this->commentManager = $comment_manager;
}
......
......@@ -8,7 +8,7 @@
namespace Drupal\comment\Controller;
use Drupal\comment\CommentInterface;
use Drupal\comment\CommentManager;
use Drupal\comment\CommentManagerInterface;
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\CommentManagerInterface
*/
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\CommentManagerInterface $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, CommentManagerInterface $comment_manager) {
$this->httpKernel = $httpKernel;
$this->csrfToken = $csrf_token;
$this->currentUser = $current_user;
......
......@@ -7,7 +7,7 @@
namespace Drupal\comment\Form;
use Drupal\comment\CommentManager;
use Drupal\comment\CommentManagerInterface;
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\CommentManagerInterface
*/
protected $commentManager;
/**
* Constructs a DeleteForm object.
*
* @param \Drupal\comment\CommentManager $comment_manager
* @param \Drupal\comment\CommentManagerInterface $comment_manager
* The comment manager service.
*/
public function __construct(CommentManager $comment_manager) {
public function __construct(CommentManagerInterface $comment_manager) {
$this->commentManager = $comment_manager;
}
......
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