Issue #2587415 by lauriii, LoMo, hooroomoo, longwave: Comment types UI confusing and inconsistent
parent
c61d707ed4
commit
023898d3f9
|
@ -118,6 +118,8 @@ class CommentTypeForm extends EntityForm {
|
|||
'#type' => 'select',
|
||||
'#default_value' => $comment_type->getTargetEntityTypeId(),
|
||||
'#title' => $this->t('Target entity type'),
|
||||
'#required' => TRUE,
|
||||
'#empty_value' => '_none',
|
||||
'#options' => $options,
|
||||
'#description' => $this->t('The target entity type can not be changed after the comment type has been created.'),
|
||||
];
|
||||
|
|
|
@ -4,6 +4,10 @@ namespace Drupal\comment;
|
|||
|
||||
use Drupal\Core\Config\Entity\ConfigEntityListBuilder;
|
||||
use Drupal\Core\Entity\EntityInterface;
|
||||
use Drupal\Core\Entity\EntityStorageInterface;
|
||||
use Drupal\Core\Entity\EntityTypeInterface;
|
||||
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
* Defines a class to build a listing of comment type entities.
|
||||
|
@ -12,6 +16,31 @@ use Drupal\Core\Entity\EntityInterface;
|
|||
*/
|
||||
class CommentTypeListBuilder extends ConfigEntityListBuilder {
|
||||
|
||||
/**
|
||||
* Constructs a new CommentTypeListBuilder object.
|
||||
*
|
||||
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
|
||||
* The entity type definition.
|
||||
* @param \Drupal\Core\Entity\EntityStorageInterface $storage
|
||||
* The entity storage class.
|
||||
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
|
||||
* The entity type manager.
|
||||
*/
|
||||
public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage, protected EntityTypeManagerInterface $entityTypeManager) {
|
||||
parent::__construct($entity_type, $storage);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) {
|
||||
return new static(
|
||||
$entity_type,
|
||||
$container->get('entity_type.manager')->getStorage($entity_type->id()),
|
||||
$container->get('entity_type.manager'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
@ -31,6 +60,7 @@ class CommentTypeListBuilder extends ConfigEntityListBuilder {
|
|||
public function buildHeader() {
|
||||
$header['type'] = t('Comment type');
|
||||
$header['description'] = t('Description');
|
||||
$header['target'] = t('Target entity type');
|
||||
return $header + parent::buildHeader();
|
||||
}
|
||||
|
||||
|
@ -38,8 +68,11 @@ class CommentTypeListBuilder extends ConfigEntityListBuilder {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildRow(EntityInterface $entity) {
|
||||
assert($entity instanceof CommentTypeInterface);
|
||||
$entity_type = $this->entityTypeManager->getDefinition($entity->getTargetEntityTypeId());
|
||||
$row['type'] = $entity->label();
|
||||
$row['description']['data'] = ['#markup' => $entity->getDescription()];
|
||||
$row['target'] = $entity_type->getLabel();
|
||||
return $row + parent::buildRow($entity);
|
||||
}
|
||||
|
||||
|
|
|
@ -75,10 +75,17 @@ class CommentTypeTest extends CommentTestBase {
|
|||
'id' => 'foo',
|
||||
'label' => 'title for foo',
|
||||
'description' => '',
|
||||
'target_entity_type_id' => 'node',
|
||||
];
|
||||
$this->drupalGet('admin/structure/comment/types/add');
|
||||
|
||||
// Ensure that target entity type is a required field.
|
||||
$this->submitForm($edit, 'Save and manage fields');
|
||||
$this->assertSession()->pageTextContains('Target entity type field is required.');
|
||||
|
||||
// Ensure that comment type is saved when target entity type is provided.
|
||||
$edit['target_entity_type_id'] = 'node';
|
||||
$this->submitForm($edit, 'Save and manage fields');
|
||||
$this->assertSession()->pageTextContains('Comment type title for foo has been added.');
|
||||
|
||||
// Asserts that form submit redirects to the expected manage fields page.
|
||||
$this->assertSession()->addressEquals('admin/structure/comment/manage/' . $edit['id'] . '/fields');
|
||||
|
@ -103,6 +110,10 @@ class CommentTypeTest extends CommentTestBase {
|
|||
\Drupal::entityTypeManager()->getStorage('comment_type')->resetCache(['foo']);
|
||||
$comment_type = CommentType::load('foo');
|
||||
$this->assertEquals('node', $comment_type->getTargetEntityTypeId());
|
||||
|
||||
// Ensure that target type is displayed in the comment type list.
|
||||
$this->drupalGet('admin/structure/comment');
|
||||
$this->assertSession()->elementExists('xpath', '//td[text() = "Content"]');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue