Commit 3b5577be authored by eshta's avatar eshta

Issue #2622292 by eshta: Update comment forms for protection to read based on comment types.

parent e5c65d2c
......@@ -17,11 +17,12 @@ use Drupal\node\Entity\NodeType;
* Implements hook_mollom_form_list().
*/
function comment_mollom_form_list() {
$forms = array();
foreach (\Drupal\node\Entity\NodeType::loadMultiple() as $type) {
$form_id = "comment_node_{$type->id()}_form";
$forms[$form_id] = array(
'title' => t('@name comment form', array('@name' => $type->id())),
$forms = [];
/* @var $type \Drupal\comment\Entity\CommentType */
foreach (\Drupal\comment\Entity\CommentType::loadMultiple() as $type) {
$form_id = 'comment_' . $type->id() . '_form';
$forms[$form_id] = [
'title' => t('@name form', array('@name' => $type->label())),
'entity' => 'comment',
'bundle' => 'comment',
'delete form' => 'comment_comment_delete_form',
......@@ -29,7 +30,7 @@ function comment_mollom_form_list() {
'report access' => array('administer comments'),
'entity delete multiple callback' => 'comment_delete_multiple',
'entity report access callback' => 'comment_mollom_entity_report_access',
);
];
}
return $forms;
}
......@@ -387,12 +388,6 @@ function mollom_form_alter(&$form, FormStateInterface $form_state, $form_id) {
}
// Retrieve a list of all protected forms once.
$forms = \Drupal\mollom\Controller\FormController::getProtectedForms();
// Remind of enabled testing mode on all protected forms.
if ($form_id == 'comment_comment_form') {
/** @var \Drupal\comment\Entity\Comment $comment */
$comment = $form_state->getFormObject()->getEntity();
$form_id = 'comment_' . $comment->getCommentedEntity()->getEntityTypeId() . '_' . $comment->getCommentedEntity()->bundle() . '_form';
}
$url = Url::fromRoute('<current>');
$current_path = $url->toString();
......
......@@ -29,7 +29,7 @@ class ActionsTest extends MollomTestBase {
$this->drupalLogin($this->adminUser);
$this->setProtectionUI('node_article_form');
$this->setProtectionUI('comment_node_article_form');
$this->setProtectionUI('comment_comment_form');
$this->drupalLogout();
// Login and submit a few nodes.
......
This diff is collapsed.
......@@ -255,7 +255,7 @@ class DataTest extends MollomTestBase {
$this->resetAll();
$this->drupalLogin($this->adminUser);
$this->setProtection('comment_node_article_form');
$this->setProtection('comment_comment_form');
// Create a node we can comment on.
$node = $this->drupalCreateNode(['type' => 'article', 'promote' => 1]);
......
......@@ -5,6 +5,9 @@
namespace Drupal\mollom\Tests;
use Drupal\comment\CommentInterface;
use Drupal\comment\Entity\CommentType;
use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
use Drupal\comment\Tests\CommentTestTrait;
use Drupal\field\Entity\FieldConfig;
......@@ -54,12 +57,40 @@ trait MollomCommentTestTrait {
*
* @param string $bundle
* The node type to add comments on.
* $param int $preview
* @param int $preview
* How to configure comment preview. Acceptable values are DRUPAL_OPTIONAL,
* DRUPAL_REQUIRED, DRUPAL_DISABLED
* @param string $comment_type_id
* The type of comment entity to add to this node.
*/
public function addCommentsToNode($bundle = 'article', $preview = DRUPAL_OPTIONAL) {
$this->addDefaultCommentField('node', $bundle);
public function addCommentsToNode($bundle = 'article', $preview = DRUPAL_OPTIONAL, $comment_type_id = 'comment') {
// While it seems wrong to add the $comment_type_id as the field name, it
// is the only way that the comment test trait uses the correct
// comment type to simulate the correct form id.
// @see https://www.drupal.org/node/2622440
$this->addDefaultCommentField('node', $bundle, $comment_type_id, CommentItemInterface::OPEN, $comment_type_id);
$this->setCommentSettings('preview', $preview);
}
/**
* Creates a comment comment type (bundle).
*
* @param string $label
* The comment type label.
*
* @return \Drupal\comment\Entity\CommentType
* Created comment type.
*
* @see \Drupal\comment\Tests\CommentTestBase
*/
public function createCommentType($label) {
$bundle = CommentType::create(array(
'id' => $label,
'label' => $label,
'description' => '',
'target_entity_type_id' => 'node',
));
$bundle->save();
return $bundle;
}
}
......@@ -39,7 +39,7 @@ class ReportingTest extends MollomTestBase {
function testReportComment() {
$comment_storage = \Drupal::entityManager()->getStorage('comment');
$this->drupalLogin($this->adminUser);
$this->setProtectionUI('comment_node_article_form');
$this->setProtectionUI('comment_comment_form');
$this->drupalLogout();
$this->node = $this->drupalCreateNode(['type' => 'article']);
......@@ -80,7 +80,7 @@ class ReportingTest extends MollomTestBase {
$comments = [];
$comment_storage = \Drupal::entityManager()->getStorage('comment');
$this->drupalLogin($this->adminUser);
$this->setProtectionUI('comment_node_article_form');
$this->setProtectionUI('comment_comment_form');
$this->drupalLogout();
$this->node = $this->drupalCreateNode(array('type' => 'article'));
......
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