diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module index 4dff2e2140d6..abc63b4f3d5b 100644 --- a/core/modules/comment/comment.module +++ b/core/modules/comment/comment.module @@ -10,9 +10,10 @@ * book page, user etc. */ -use Drupal\Core\Entity\EntityInterface; -use Drupal\Core\Entity\EntityChangedInterface; use Drupal\comment\CommentInterface; +use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface; +use Drupal\Core\Entity\EntityChangedInterface; +use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\Display\EntityViewDisplayInterface; use Drupal\field\FieldInstanceConfigInterface; use Drupal\field\FieldConfigInterface; @@ -55,21 +56,6 @@ const COMMENT_FORM_SEPARATE_PAGE = 0; */ const COMMENT_FORM_BELOW = 1; -/** - * Comments for this entity are hidden. - */ -const COMMENT_HIDDEN = 0; - -/** - * Comments for this entity are closed. - */ -const COMMENT_CLOSED = 1; - -/** - * Comments for this entity are open. - */ -const COMMENT_OPEN = 2; - /** * The time cutoff for comments marked as read for entity types other node. * @@ -240,7 +226,7 @@ function comment_field_instance_config_create(FieldInstanceConfigInterface $inst } $instance->default_value += array(array()); $instance->default_value[0] += array( - 'status' => COMMENT_OPEN, + 'status' => CommentItemInterface::OPEN, 'cid' => 0, 'last_comment_timestamp' => 0, 'last_comment_name' => '', @@ -474,7 +460,7 @@ function comment_node_links_alter(array &$node_links, NodeInterface $node, array } } // Provide a link to new comment form. - if ($commenting_status == COMMENT_OPEN) { + if ($commenting_status == CommentItemInterface::OPEN) { $comment_form_location = $instance->getSetting('form_location'); if (user_access('post comments')) { $links['comment-add'] = array( @@ -505,7 +491,7 @@ function comment_node_links_alter(array &$node_links, NodeInterface $node, array else { // Node in other view modes: add a "post comment" link if the user is // allowed to post comments and if this node is allowing new comments. - if ($commenting_status == COMMENT_OPEN) { + if ($commenting_status == CommentItemInterface::OPEN) { $comment_form_location = $instance->getSetting('form_location'); if (user_access('post comments')) { // Show the "post comment" link if the form is on another page, or @@ -1054,8 +1040,8 @@ function comment_node_search_result(EntityInterface $node) { } // Do not make a string if comments are hidden. $status = $node->get($field_name)->status; - if (\Drupal::currentUser()->hasPermission('access comments') && $status != COMMENT_HIDDEN) { - if ($status == COMMENT_OPEN) { + if (\Drupal::currentUser()->hasPermission('access comments') && $status != CommentItemInterface::HIDDEN) { + if ($status == CommentItemInterface::OPEN) { // At least one comment field is open. $open = TRUE; } @@ -1320,7 +1306,7 @@ function comment_preview(CommentInterface $comment, array &$form_state) { // the value back to its original state after the call to entity_view(). $field_name = $comment->getFieldName(); $original_status = $entity->get($field_name)->status; - $entity->get($field_name)->status = COMMENT_HIDDEN; + $entity->get($field_name)->status = CommentItemInterface::HIDDEN; $build = entity_view($entity, 'full'); $entity->get($field_name)->status = $original_status; } diff --git a/core/modules/comment/lib/Drupal/comment/CommentFormController.php b/core/modules/comment/lib/Drupal/comment/CommentFormController.php index 74c147d38d19..ef7c7fd982c5 100644 --- a/core/modules/comment/lib/Drupal/comment/CommentFormController.php +++ b/core/modules/comment/lib/Drupal/comment/CommentFormController.php @@ -7,6 +7,7 @@ namespace Drupal\comment; +use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface; use Drupal\Component\Utility\String; use Drupal\Component\Utility\Unicode; use Drupal\Core\Cache\Cache; @@ -380,7 +381,7 @@ class CommentFormController extends ContentEntityFormController { $field_name = $comment->getFieldName(); $uri = $entity->urlInfo(); - if ($this->currentUser->hasPermission('post comments') && ($this->currentUser->hasPermission('administer comments') || $entity->{$field_name}->status == COMMENT_OPEN)) { + if ($this->currentUser->hasPermission('post comments') && ($this->currentUser->hasPermission('administer comments') || $entity->{$field_name}->status == CommentItemInterface::OPEN)) { // Save the anonymous user information to a cookie for reuse. if ($this->currentUser->isAnonymous()) { user_cookie_save(array_intersect_key($form_state['values'], array_flip(array('name', 'mail', 'homepage')))); diff --git a/core/modules/comment/lib/Drupal/comment/CommentManager.php b/core/modules/comment/lib/Drupal/comment/CommentManager.php index 126d6b44d30d..6976e42eef19 100644 --- a/core/modules/comment/lib/Drupal/comment/CommentManager.php +++ b/core/modules/comment/lib/Drupal/comment/CommentManager.php @@ -7,6 +7,7 @@ namespace Drupal\comment; +use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface; use Drupal\Component\Utility\String; use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Entity\EntityInterface; @@ -138,7 +139,7 @@ class CommentManager implements CommentManagerInterface { /** * {@inheritdoc} */ - public function addDefaultField($entity_type, $bundle, $field_name = 'comment', $default_value = COMMENT_OPEN) { + public function addDefaultField($entity_type, $bundle, $field_name = 'comment', $default_value = CommentItemInterface::OPEN) { // Make sure the field doesn't already exist. if (!$this->fieldInfo->getField($entity_type, $field_name)) { // Add a default comment field for existing node comments. diff --git a/core/modules/comment/lib/Drupal/comment/CommentManagerInterface.php b/core/modules/comment/lib/Drupal/comment/CommentManagerInterface.php index b6024e9b067f..723d173145e2 100644 --- a/core/modules/comment/lib/Drupal/comment/CommentManagerInterface.php +++ b/core/modules/comment/lib/Drupal/comment/CommentManagerInterface.php @@ -8,6 +8,8 @@ namespace Drupal\comment; use Drupal\Core\Entity\EntityInterface; +use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface; + /** * Comment manager contains common functions to manage comment fields. */ @@ -59,10 +61,11 @@ interface CommentManagerInterface { * @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. + * (optional) Default value, one of CommentItemInterface::HIDDEN, + * CommentItemInterface::OPEN, CommentItemInterface::CLOSED. Defaults to + * CommentItemInterface::OPEN. */ - public function addDefaultField($entity_type, $bundle, $field_name = 'comment', $default_value = COMMENT_OPEN); + public function addDefaultField($entity_type, $bundle, $field_name = 'comment', $default_value = CommentItemInterface::OPEN); /** * Creates a comment_body field instance. diff --git a/core/modules/comment/lib/Drupal/comment/CommentViewBuilder.php b/core/modules/comment/lib/Drupal/comment/CommentViewBuilder.php index 69ccb67657d6..bd93abb20976 100644 --- a/core/modules/comment/lib/Drupal/comment/CommentViewBuilder.php +++ b/core/modules/comment/lib/Drupal/comment/CommentViewBuilder.php @@ -7,6 +7,7 @@ namespace Drupal\comment; +use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface; use Drupal\Core\Access\CsrfTokenGenerator; use Drupal\Core\Entity\Display\EntityViewDisplayInterface; use Drupal\Core\Entity\EntityInterface; @@ -209,7 +210,7 @@ class CommentViewBuilder extends EntityViewBuilder { $container = \Drupal::getContainer(); - if ($status == COMMENT_OPEN) { + if ($status == CommentItemInterface::OPEN) { if ($entity->access('delete')) { $links['comment-delete'] = array( 'title' => t('Delete'), diff --git a/core/modules/comment/lib/Drupal/comment/Controller/CommentController.php b/core/modules/comment/lib/Drupal/comment/Controller/CommentController.php index a302724b5ee5..7a4115fef6ae 100644 --- a/core/modules/comment/lib/Drupal/comment/Controller/CommentController.php +++ b/core/modules/comment/lib/Drupal/comment/Controller/CommentController.php @@ -9,6 +9,7 @@ namespace Drupal\comment\Controller; use Drupal\comment\CommentInterface; use Drupal\comment\CommentManagerInterface; +use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface; use Drupal\field\FieldInfo; use Drupal\Core\Controller\ControllerBase; use Drupal\Core\Entity\EntityInterface; @@ -225,7 +226,7 @@ class CommentController extends ControllerBase { // The user is not just previewing a comment. if ($request->request->get('op') != $this->t('Preview')) { $status = $entity->{$field_name}->status; - if ($status != COMMENT_OPEN) { + if ($status != CommentItemInterface::OPEN) { drupal_set_message($this->t("This discussion is closed: you can't post new comments."), 'error'); return $this->redirect($uri['route_name'], $uri['route_parameters']); } @@ -252,7 +253,7 @@ class CommentController extends ControllerBase { elseif ($entity->access('view', $account)) { // We make sure the field value isn't set so we don't end up with a // redirect loop. - $entity->{$field_name}->status = COMMENT_HIDDEN; + $entity->{$field_name}->status = CommentItemInterface::HIDDEN; // Render array of the entity full view mode. $build['commented_entity'] = $this->entityManager()->getViewBuilder($entity->getEntityTypeId())->view($entity, 'full'); unset($build['commented_entity']['#cache']); diff --git a/core/modules/comment/lib/Drupal/comment/Plugin/Field/FieldFormatter/CommentDefaultFormatter.php b/core/modules/comment/lib/Drupal/comment/Plugin/Field/FieldFormatter/CommentDefaultFormatter.php index a0b1ed9d29bb..bf4979bfc55c 100644 --- a/core/modules/comment/lib/Drupal/comment/Plugin/Field/FieldFormatter/CommentDefaultFormatter.php +++ b/core/modules/comment/lib/Drupal/comment/Plugin/Field/FieldFormatter/CommentDefaultFormatter.php @@ -8,6 +8,7 @@ namespace Drupal\comment\Plugin\Field\FieldFormatter; use Drupal\comment\CommentStorageControllerInterface; +use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface; use Drupal\Core\Entity\EntityViewBuilderInterface; use Drupal\Core\Field\FieldItemListInterface; use Drupal\Core\Session\AccountInterface; @@ -115,7 +116,7 @@ class CommentDefaultFormatter extends FormatterBase implements ContainerFactoryP $status = $items->status; - if ($status != COMMENT_HIDDEN && empty($entity->in_preview) && + if ($status != CommentItemInterface::HIDDEN && empty($entity->in_preview) && // Comments are added to the search results and search index by // comment_node_update_index() instead of by this formatter, so don't // return anything if the view mode is search_index or search_result. @@ -144,7 +145,7 @@ class CommentDefaultFormatter extends FormatterBase implements ContainerFactoryP // Append comment form if the comments are open and the form is set to // display below the entity. Do not show the form for the print view mode. - if ($status == COMMENT_OPEN && $comment_settings['form_location'] == COMMENT_FORM_BELOW && $this->viewMode != 'print') { + if ($status == CommentItemInterface::OPEN && $comment_settings['form_location'] == COMMENT_FORM_BELOW && $this->viewMode != 'print') { // Only show the add comment form if the user has permission. if ($this->currentUser->hasPermission('post comments')) { // All users in the "anonymous" role can use the same form: it is fine diff --git a/core/modules/comment/lib/Drupal/comment/Plugin/Field/FieldType/CommentItem.php b/core/modules/comment/lib/Drupal/comment/Plugin/Field/FieldType/CommentItem.php index 93dc61cc3c0f..10a978862a32 100644 --- a/core/modules/comment/lib/Drupal/comment/Plugin/Field/FieldType/CommentItem.php +++ b/core/modules/comment/lib/Drupal/comment/Plugin/Field/FieldType/CommentItem.php @@ -33,7 +33,7 @@ use Drupal\Core\Field\ConfigFieldItemBase; * default_formatter = "comment_default" * ) */ -class CommentItem extends ConfigFieldItemBase { +class CommentItem extends ConfigFieldItemBase implements CommentItemInterface { /** * {@inheritdoc} @@ -170,8 +170,9 @@ class CommentItem extends ConfigFieldItemBase { * {@inheritdoc} */ public function isEmpty() { - // There is always a value for this field, it is one of COMMENT_OPEN, - // COMMENT_CLOSED or COMMENT_HIDDEN. + // There is always a value for this field, it is one of + // CommentItemInterface::OPEN, CommentItemInterface::CLOSED or + // CommentItemInterface::HIDDEN. return FALSE; } diff --git a/core/modules/comment/lib/Drupal/comment/Plugin/Field/FieldType/CommentItemInterface.php b/core/modules/comment/lib/Drupal/comment/Plugin/Field/FieldType/CommentItemInterface.php new file mode 100644 index 000000000000..17db9163ee38 --- /dev/null +++ b/core/modules/comment/lib/Drupal/comment/Plugin/Field/FieldType/CommentItemInterface.php @@ -0,0 +1,32 @@ + 'invisible', '#default_value' => $status, '#options' => array( - COMMENT_OPEN => t('Open'), - COMMENT_CLOSED => t('Closed'), - COMMENT_HIDDEN => t('Hidden'), + CommentItemInterface::OPEN => t('Open'), + CommentItemInterface::CLOSED => t('Closed'), + CommentItemInterface::HIDDEN => t('Hidden'), ), - COMMENT_OPEN => array( + CommentItemInterface::OPEN => array( '#description' => t('Users with the "Post comments" permission can post comments.'), ), - COMMENT_CLOSED => array( + CommentItemInterface::CLOSED => array( '#description' => t('Users cannot post comments, but existing comments will be displayed.'), ), - COMMENT_HIDDEN => array( + CommentItemInterface::HIDDEN => array( '#description' => t('Comments are hidden from view.'), ), ); @@ -58,9 +59,9 @@ class CommentWidget extends WidgetBase { // sense, so don't even bother presenting it to the user unless this is the // default value widget on the field settings form. if ($element['#field_parents'] != array('default_value_input') && !$entity->get($field->getName())->comment_count) { - $element['status'][COMMENT_HIDDEN]['#access'] = FALSE; + $element['status'][CommentItemInterface::HIDDEN]['#access'] = FALSE; // Also adjust the description of the "closed" option. - $element['status'][COMMENT_CLOSED]['#description'] = t('Users cannot post comments.'); + $element['status'][CommentItemInterface::CLOSED]['#description'] = t('Users cannot post comments.'); } // If the advanced settings tabs-set is available (normally rendered in the // second column on wide-resolutions), place the field as a details element diff --git a/core/modules/comment/lib/Drupal/comment/Plugin/views/field/NodeComment.php b/core/modules/comment/lib/Drupal/comment/Plugin/views/field/NodeComment.php index 7d152795d4ad..e2d1b3130bea 100644 --- a/core/modules/comment/lib/Drupal/comment/Plugin/views/field/NodeComment.php +++ b/core/modules/comment/lib/Drupal/comment/Plugin/views/field/NodeComment.php @@ -7,6 +7,7 @@ namespace Drupal\comment\Plugin\views\field; +use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface; use Drupal\views\Plugin\views\field\FieldPluginBase; use Drupal\views\ResultRow; @@ -25,12 +26,12 @@ class NodeComment extends FieldPluginBase { public function render(ResultRow $values) { $value = $this->getValue($values); switch ($value) { - case COMMENT_HIDDEN: + case CommentItemInterface::HIDDEN: default: return t('Hidden'); - case COMMENT_CLOSED: + case CommentItemInterface::CLOSED: return t('Closed'); - case COMMENT_OPEN: + case CommentItemInterface::OPEN: return t('Open'); } } diff --git a/core/modules/comment/lib/Drupal/comment/Plugin/views/filter/NodeComment.php b/core/modules/comment/lib/Drupal/comment/Plugin/views/filter/NodeComment.php index 1f3e3cacb27a..94e68ce1c227 100644 --- a/core/modules/comment/lib/Drupal/comment/Plugin/views/filter/NodeComment.php +++ b/core/modules/comment/lib/Drupal/comment/Plugin/views/filter/NodeComment.php @@ -7,6 +7,7 @@ namespace Drupal\comment\Plugin\views\filter; +use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface; use Drupal\views\Plugin\views\filter\InOperator; /** @@ -20,9 +21,9 @@ class NodeComment extends InOperator { public function getValueOptions() { $this->value_options = array( - COMMENT_HIDDEN => t('Hidden'), - COMMENT_CLOSED => t('Closed'), - COMMENT_OPEN => t('Open'), + CommentItemInterface::HIDDEN => t('Hidden'), + CommentItemInterface::CLOSED => t('Closed'), + CommentItemInterface::OPEN => t('Open'), ); } diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentFieldsTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentFieldsTest.php index 10c8f80651c8..86172a1e4fea 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentFieldsTest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentFieldsTest.php @@ -7,6 +7,8 @@ namespace Drupal\comment\Tests; +use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface; + /** * Tests fields on comments. */ @@ -58,10 +60,10 @@ class CommentFieldsTest extends CommentTestBase { $instances = $this->container->get('field.info')->getInstances('comment'); $this->assertTrue(isset($instances['node__comment']['comment_body']), format_string('The comment_body field is present for comments on type @type', array('@type' => $type_name))); - // Test adding a field that defaults to COMMENT_CLOSED. - $this->container->get('comment.manager')->addDefaultField('node', 'test_node_type', 'who_likes_ponies', COMMENT_CLOSED); + // Test adding a field that defaults to CommentItemInterface::CLOSED. + $this->container->get('comment.manager')->addDefaultField('node', 'test_node_type', 'who_likes_ponies', CommentItemInterface::CLOSED); $field = entity_load('field_instance_config', 'node.test_node_type.who_likes_ponies'); - $this->assertEqual($field->default_value[0]['status'], COMMENT_CLOSED); + $this->assertEqual($field->default_value[0]['status'], CommentItemInterface::CLOSED); } /** diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentInterfaceTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentInterfaceTest.php index 65c5f265819e..42157e1e6d45 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentInterfaceTest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentInterfaceTest.php @@ -8,6 +8,7 @@ namespace Drupal\comment\Tests; use Drupal\comment\CommentInterface; +use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface; /** * Tests the comment module administrative and end-user-facing interfaces. @@ -154,21 +155,21 @@ class CommentInterfaceTest extends CommentTestBase { $this->assertText(t('The comment you are replying to does not exist.'), 'Replying to an unpublished comment'); // Attempt to post to node with comments disabled. - $this->node = $this->drupalCreateNode(array('type' => 'article', 'promote' => 1, 'comment' => array(array('status' => COMMENT_HIDDEN)))); + $this->node = $this->drupalCreateNode(array('type' => 'article', 'promote' => 1, 'comment' => array(array('status' => CommentItemInterface::HIDDEN)))); $this->assertTrue($this->node, 'Article node created.'); $this->drupalGet('comment/reply/node/' . $this->node->id() . '/comment'); $this->assertText('This discussion is closed', 'Posting to node with comments disabled'); $this->assertNoField('edit-comment', 'Comment body field found.'); // Attempt to post to node with read-only comments. - $this->node = $this->drupalCreateNode(array('type' => 'article', 'promote' => 1, 'comment' => array(array('status' => COMMENT_CLOSED)))); + $this->node = $this->drupalCreateNode(array('type' => 'article', 'promote' => 1, 'comment' => array(array('status' => CommentItemInterface::CLOSED)))); $this->assertTrue($this->node, 'Article node created.'); $this->drupalGet('comment/reply/node/' . $this->node->id() . '/comment'); $this->assertText('This discussion is closed', 'Posting to node with comments read-only'); $this->assertNoField('edit-comment', 'Comment body field found.'); // Attempt to post to node with comments enabled (check field names etc). - $this->node = $this->drupalCreateNode(array('type' => 'article', 'promote' => 1, 'comment' => array(array('status' => COMMENT_OPEN)))); + $this->node = $this->drupalCreateNode(array('type' => 'article', 'promote' => 1, 'comment' => array(array('status' => CommentItemInterface::OPEN)))); $this->assertTrue($this->node, 'Article node created.'); $this->drupalGet('comment/reply/node/' . $this->node->id() . '/comment'); $this->assertNoText('This discussion is closed', 'Posting to node with comments enabled'); diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentLanguageTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentLanguageTest.php index 15a389c7ef23..56444a9f5bbb 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentLanguageTest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentLanguageTest.php @@ -7,6 +7,7 @@ namespace Drupal\comment\Tests; +use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface; use Drupal\simpletest\WebTestBase; /** @@ -97,7 +98,7 @@ class CommentLanguageTest extends WebTestBase { 'title[0][value]' => $title, 'body[0][value]' => $this->randomName(), 'langcode' => $node_langcode, - 'comment[0][status]' => COMMENT_OPEN, + 'comment[0][status]' => CommentItemInterface::OPEN, ); $this->drupalPostForm("node/add/article", $edit, t('Save')); $node = $this->drupalGetNodeByTitle($title); diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentLinksTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentLinksTest.php index 78f81f9ab0e0..cf7af825e9b6 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentLinksTest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentLinksTest.php @@ -7,6 +7,7 @@ namespace Drupal\comment\Tests; +use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface; use Drupal\Core\Language\Language; use Drupal\comment\CommentInterface; @@ -68,7 +69,7 @@ class CommentLinksTest extends CommentTestBase { // test; there is only a difference between open and closed registration. 'user_register' => array(USER_REGISTER_VISITORS, USER_REGISTER_ADMINISTRATORS_ONLY), // @todo Complete test coverage for: - //'comments' => array(COMMENT_OPEN, COMMENT_CLOSED, COMMENT_HIDDEN), + //'comments' => array(CommentItemInterface::OPEN, CommentItemInterface::CLOSED, CommentInterface::_HIDDEN), //// COMMENT_ANONYMOUS_MUST_CONTACT is irrelevant for this test. //'contact ' => array(COMMENT_ANONYMOUS_MAY_CONTACT, COMMENT_ANONYMOUS_MAYNOT_CONTACT), ); @@ -95,7 +96,8 @@ class CommentLinksTest extends CommentTestBase { * USER_REGISTER_VISITORS. * - contact: COMMENT_ANONYMOUS_MAY_CONTACT or * COMMENT_ANONYMOUS_MAYNOT_CONTACT. - * - comments: COMMENT_OPEN, COMMENT_CLOSED, or COMMENT_HIDDEN. + * - comments: CommentItemInterface::OPEN, CommentItemInterface::CLOSED or + * CommentItemInterface::HIDDEN. * - User permissions: * These are granted or revoked for the user, according to the * 'authenticated' flag above. Pass 0 or 1 as parameter values. See @@ -116,7 +118,7 @@ class CommentLinksTest extends CommentTestBase { 'form' => COMMENT_FORM_BELOW, 'user_register' => USER_REGISTER_VISITORS, 'contact' => COMMENT_ANONYMOUS_MAY_CONTACT, - 'comments' => COMMENT_OPEN, + 'comments' => CommentItemInterface::OPEN, 'access comments' => 0, 'post comments' => 0, // Enabled by default, because it's irrelevant for this test. @@ -191,9 +193,9 @@ class CommentLinksTest extends CommentTestBase { COMMENT_ANONYMOUS_MUST_CONTACT => 'required', ); $t_comments = array( - COMMENT_OPEN => 'open', - COMMENT_CLOSED => 'closed', - COMMENT_HIDDEN => 'hidden', + CommentItemInterface::OPEN => 'open', + CommentItemInterface::CLOSED => 'closed', + CommentItemInterface::HIDDEN => 'hidden', ); $verbose = $info; $verbose['form'] = $t_form[$info['form']]; diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentNonNodeTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentNonNodeTest.php index 82338b1570ef..d4af65e22102 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentNonNodeTest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentNonNodeTest.php @@ -8,6 +8,7 @@ namespace Drupal\comment\Tests; use Drupal\comment\CommentInterface; +use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface; use Drupal\simpletest\WebTestBase; use Drupal\Core\Entity\EntityInterface; @@ -342,7 +343,7 @@ class CommentNonNodeTest extends WebTestBase { $this->assertNoFieldChecked('edit-default-value-input-comment-0-status-1'); $this->assertFieldChecked('edit-default-value-input-comment-0-status-2'); // Test comment option change in field settings. - $edit = array('default_value_input[comment][0][status]' => COMMENT_CLOSED); + $edit = array('default_value_input[comment][0][status]' => CommentItemInterface::CLOSED); $this->drupalPostForm(NULL, $edit, t('Save settings')); $this->drupalGet('entity_test/structure/entity_test/fields/entity_test.entity_test.comment'); $this->assertNoFieldChecked('edit-default-value-input-comment-0-status-0'); diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentRssTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentRssTest.php index b7d44c85bf27..c58ada7bcef4 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentRssTest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentRssTest.php @@ -7,6 +7,8 @@ namespace Drupal\comment\Tests; +use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface; + /** * Tests for Comment module integration with RSS feeds. */ @@ -39,7 +41,7 @@ class CommentRssTest extends CommentTestBase { $this->assertRaw($raw, 'Comments as part of RSS feed.'); // Hide comments from RSS feed and check presence. - $this->node->set('comment', COMMENT_HIDDEN); + $this->node->set('comment', CommentItemInterface::HIDDEN); $this->node->save(); $this->drupalGet('rss.xml'); $this->assertNoRaw($raw, 'Hidden comments is not a part of RSS feed.'); diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentTranslationUITest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentTranslationUITest.php index 2e9226d2362d..ce52ee2bc4ea 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentTranslationUITest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentTranslationUITest.php @@ -7,6 +7,7 @@ namespace Drupal\comment\Tests; +use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface; use Drupal\content_translation\Tests\ContentTranslationUITest; /** @@ -102,7 +103,7 @@ class CommentTranslationUITest extends ContentTranslationUITest { $node = $this->drupalCreateNode(array( 'type' => $node_type, $field_name => array( - array('status' => COMMENT_OPEN) + array('status' => CommentItemInterface::OPEN) ), )); $values['entity_id'] = $node->id(); diff --git a/core/modules/forum/forum.install b/core/modules/forum/forum.install index 847dfeea23b3..e9f012e4e105 100644 --- a/core/modules/forum/forum.install +++ b/core/modules/forum/forum.install @@ -5,8 +5,6 @@ * Install, update, and uninstall functions for the Forum module. */ -use Drupal\Core\Language\Language; - /** * Implements hook_install(). */ @@ -83,7 +81,7 @@ function forum_install() { 'include_deleted' => FALSE, )); if (empty($fields)) { - Drupal::service('comment.manager')->addDefaultField('node', 'forum', 'comment_forum', COMMENT_OPEN); + Drupal::service('comment.manager')->addDefaultField('node', 'forum', 'comment_forum'); } } diff --git a/core/modules/forum/forum.module b/core/modules/forum/forum.module index c44cffe1dd5c..c728ad1fe375 100644 --- a/core/modules/forum/forum.module +++ b/core/modules/forum/forum.module @@ -5,6 +5,7 @@ * Provides discussion forums. */ +use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface; use Drupal\Core\Entity\EntityInterface; use Drupal\Component\Utility\String; use Drupal\field\Field; @@ -805,7 +806,7 @@ function template_preprocess_forum_icon(&$variables) { $variables['icon_title'] = $variables['new_posts'] ? t('New comments') : t('Normal topic'); } - if ($variables['comment_mode'] == COMMENT_CLOSED || $variables['comment_mode'] == COMMENT_HIDDEN) { + if ($variables['comment_mode'] == CommentItemInterface::CLOSED || $variables['comment_mode'] == CommentItemInterface::HIDDEN) { $icon_status_class = 'closed'; $variables['icon_title'] = t('Closed topic'); } diff --git a/core/modules/forum/lib/Drupal/forum/Tests/ForumUninstallTest.php b/core/modules/forum/lib/Drupal/forum/Tests/ForumUninstallTest.php index fed13531063f..c9bbcff71141 100644 --- a/core/modules/forum/lib/Drupal/forum/Tests/ForumUninstallTest.php +++ b/core/modules/forum/lib/Drupal/forum/Tests/ForumUninstallTest.php @@ -8,6 +8,7 @@ namespace Drupal\forum\Tests; use Drupal\comment\CommentInterface; +use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface; use Drupal\simpletest\WebTestBase; /** @@ -75,7 +76,7 @@ class ForumUninstallTest extends WebTestBase { // We want to test the handling of removing the forum comment field, so we // ensure there is at least one other comment field attached to a node type // so that comment_entity_load() runs for nodes. - \Drupal::service('comment.manager')->addDefaultField('node', 'forum', 'another_comment_field', COMMENT_OPEN); + \Drupal::service('comment.manager')->addDefaultField('node', 'forum', 'another_comment_field', CommentItemInterface::OPEN); $this->drupalGet('node/' . $node->nid->value); $this->assertResponse(200); diff --git a/core/modules/search/lib/Drupal/search/Tests/SearchCommentCountToggleTest.php b/core/modules/search/lib/Drupal/search/Tests/SearchCommentCountToggleTest.php index cb07d81ce279..5f77bd0b34f1 100644 --- a/core/modules/search/lib/Drupal/search/Tests/SearchCommentCountToggleTest.php +++ b/core/modules/search/lib/Drupal/search/Tests/SearchCommentCountToggleTest.php @@ -7,6 +7,8 @@ namespace Drupal\search\Tests; +use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface; + /** * Tests that comment count display toggles properly on comment status of node * @@ -89,9 +91,9 @@ class SearchCommentCountToggleTest extends SearchTestBase { $this->assertText(t('1 comment'), 'Non-empty comment count displays for nodes with comment status set to Open'); // Test comment count display for nodes with comment status set to Closed - $this->searchable_nodes['0 comments']->set('comment', COMMENT_CLOSED); + $this->searchable_nodes['0 comments']->set('comment', CommentItemInterface::CLOSED); $this->searchable_nodes['0 comments']->save(); - $this->searchable_nodes['1 comment']->set('comment', COMMENT_CLOSED); + $this->searchable_nodes['1 comment']->set('comment', CommentItemInterface::CLOSED); $this->searchable_nodes['1 comment']->save(); $this->drupalPostForm('', $edit, t('Search')); @@ -99,9 +101,9 @@ class SearchCommentCountToggleTest extends SearchTestBase { $this->assertText(t('1 comment'), 'Non-empty comment count displays for nodes with comment status set to Closed'); // Test comment count display for nodes with comment status set to Hidden - $this->searchable_nodes['0 comments']->set('comment', COMMENT_HIDDEN); + $this->searchable_nodes['0 comments']->set('comment', CommentItemInterface::HIDDEN); $this->searchable_nodes['0 comments']->save(); - $this->searchable_nodes['1 comment']->set('comment', COMMENT_HIDDEN); + $this->searchable_nodes['1 comment']->set('comment', CommentItemInterface::HIDDEN); $this->searchable_nodes['1 comment']->save(); $this->drupalPostForm('', $edit, t('Search')); diff --git a/core/modules/search/lib/Drupal/search/Tests/SearchCommentTest.php b/core/modules/search/lib/Drupal/search/Tests/SearchCommentTest.php index e3977cb4d466..b470ae69a950 100644 --- a/core/modules/search/lib/Drupal/search/Tests/SearchCommentTest.php +++ b/core/modules/search/lib/Drupal/search/Tests/SearchCommentTest.php @@ -7,6 +7,7 @@ namespace Drupal\search\Tests; +use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface; use Drupal\field\Field; /** @@ -114,7 +115,7 @@ class SearchCommentTest extends SearchTestBase { // Hide comments. $this->drupalLogin($this->admin_user); - $node->set('comment', COMMENT_HIDDEN); + $node->set('comment', CommentItemInterface::HIDDEN); $node->save(); // Invoke search index update. diff --git a/core/modules/search/lib/Drupal/search/Tests/SearchRankingTest.php b/core/modules/search/lib/Drupal/search/Tests/SearchRankingTest.php index 25b8ff2963d5..5d16f801953e 100644 --- a/core/modules/search/lib/Drupal/search/Tests/SearchRankingTest.php +++ b/core/modules/search/lib/Drupal/search/Tests/SearchRankingTest.php @@ -7,6 +7,8 @@ namespace Drupal\search\Tests; +use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface; + /** * Indexes content and tests ranking factors. */ @@ -56,7 +58,7 @@ class SearchRankingTest extends SearchTestBase { $settings = array( 'type' => 'page', 'comment' => array(array( - 'status' => COMMENT_HIDDEN, + 'status' => CommentItemInterface::HIDDEN, )), 'title' => 'Drupal rocks', 'body' => array(array('value' => "Drupal's search rocks")), @@ -75,7 +77,7 @@ class SearchRankingTest extends SearchTestBase { $settings['created'] = REQUEST_TIME + 3600; break; case 'comments': - $settings['comment'][0]['status'] = COMMENT_OPEN; + $settings['comment'][0]['status'] = CommentItemInterface::OPEN; break; } } diff --git a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php index 2bd20a26bbf3..08146973c21e 100644 --- a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php +++ b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php @@ -236,7 +236,7 @@ abstract class WebTestBase extends TestBase { * ); * @endcode * - title: Random string. - * - comment: COMMENT_OPEN. + * - comment: CommentItemInterface::OPEN. * - changed: REQUEST_TIME. * - promote: NODE_NOT_PROMOTED. * - log: Empty string. diff --git a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityCrudHookTest.php b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityCrudHookTest.php index 592830447518..b7dd9addd1be 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityCrudHookTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityCrudHookTest.php @@ -7,6 +7,7 @@ namespace Drupal\system\Tests\Entity; +use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface; use Drupal\Core\Language\Language; use Drupal\Core\Database\Database; @@ -133,7 +134,7 @@ class EntityCrudHookTest extends EntityUnitTestBase { public function testCommentHooks() { $account = $this->createUser(); $this->enableModules(array('entity', 'filter')); - $this->container->get('comment.manager')->addDefaultField('node', 'article', 'comment', COMMENT_OPEN); + $this->container->get('comment.manager')->addDefaultField('node', 'article', 'comment', CommentItemInterface::OPEN); $node = entity_create('node', array( 'uid' => $account->id(), diff --git a/core/modules/system/lib/Drupal/system/Tests/Theme/EntityFilteringThemeTest.php b/core/modules/system/lib/Drupal/system/Tests/Theme/EntityFilteringThemeTest.php index dda6fb063b15..b2816aa6828a 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Theme/EntityFilteringThemeTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Theme/EntityFilteringThemeTest.php @@ -9,6 +9,7 @@ namespace Drupal\system\Tests\Theme; use Drupal\Core\Extension\ExtensionDiscovery; use Drupal\comment\CommentInterface; +use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface; use Drupal\simpletest\WebTestBase; /** @@ -101,7 +102,7 @@ class EntityFilteringThemeTest extends WebTestBase { $this->term->save(); // Add a comment field. - $this->container->get('comment.manager')->addDefaultField('node', 'article', 'comment', COMMENT_OPEN); + $this->container->get('comment.manager')->addDefaultField('node', 'article', 'comment', CommentItemInterface::OPEN); // Create a test node tagged with the test term. $this->node = $this->drupalCreateNode(array( 'title' => $this->xss_label, diff --git a/core/modules/tracker/lib/Drupal/tracker/Tests/TrackerNodeAccessTest.php b/core/modules/tracker/lib/Drupal/tracker/Tests/TrackerNodeAccessTest.php index 57828bf55d02..207becc867a6 100644 --- a/core/modules/tracker/lib/Drupal/tracker/Tests/TrackerNodeAccessTest.php +++ b/core/modules/tracker/lib/Drupal/tracker/Tests/TrackerNodeAccessTest.php @@ -7,6 +7,7 @@ namespace Drupal\tracker\Tests; +use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface; use Drupal\simpletest\WebTestBase; /** @@ -32,7 +33,7 @@ class TrackerNodeAccessTest extends WebTestBase { public function setUp() { parent::setUp(); node_access_rebuild(); - $this->container->get('comment.manager')->addDefaultField('node', 'page', 'comment', COMMENT_OPEN); + $this->container->get('comment.manager')->addDefaultField('node', 'page', 'comment', CommentItemInterface::OPEN); \Drupal::state()->set('node_access_test.private', TRUE); } diff --git a/core/profiles/standard/standard.install b/core/profiles/standard/standard.install index aa0cb4a839e5..bec11078785e 100644 --- a/core/profiles/standard/standard.install +++ b/core/profiles/standard/standard.install @@ -4,6 +4,8 @@ * Install, update and uninstall functions for the standard installation profile. */ +use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface; + /** * Implements hook_install(). * @@ -25,7 +27,7 @@ function standard_install() { \Drupal::config('system.site')->set('page.front', 'node')->save(); // Add comment field to article node type. - \Drupal::service('comment.manager')->addDefaultField('node', 'article', 'comment', COMMENT_OPEN); + \Drupal::service('comment.manager')->addDefaultField('node', 'article', 'comment', CommentItemInterface::OPEN); // Allow visitor account creation with administrative approval. $user_settings = \Drupal::config('user.settings');