Commit fa34234e authored by alexpott's avatar alexpott
Browse files

Issue #2824912 by Sam152, chr.fritsch, timmillwood: The moderation_state field...

Issue #2824912 by Sam152, chr.fritsch, timmillwood: The moderation_state field incorrectly reports being read-only
parent b405f348
...@@ -292,8 +292,8 @@ public function entityBaseFieldInfo(EntityTypeInterface $entity_type) { ...@@ -292,8 +292,8 @@ public function entityBaseFieldInfo(EntityTypeInterface $entity_type) {
$fields = []; $fields = [];
$fields['moderation_state'] = BaseFieldDefinition::create('entity_reference') $fields['moderation_state'] = BaseFieldDefinition::create('entity_reference')
->setLabel(t('Moderation state')) ->setLabel($this->t('Moderation state'))
->setDescription(t('The moderation state of this piece of content.')) ->setDescription($this->t('The moderation state of this piece of content.'))
->setComputed(TRUE) ->setComputed(TRUE)
->setClass(ModerationStateFieldItemList::class) ->setClass(ModerationStateFieldItemList::class)
->setSetting('target_type', 'moderation_state') ->setSetting('target_type', 'moderation_state')
...@@ -310,6 +310,7 @@ public function entityBaseFieldInfo(EntityTypeInterface $entity_type) { ...@@ -310,6 +310,7 @@ public function entityBaseFieldInfo(EntityTypeInterface $entity_type) {
->addConstraint('ModerationState', []) ->addConstraint('ModerationState', [])
->setDisplayConfigurable('form', FALSE) ->setDisplayConfigurable('form', FALSE)
->setDisplayConfigurable('view', FALSE) ->setDisplayConfigurable('view', FALSE)
->setReadOnly(FALSE)
->setTranslatable(TRUE); ->setTranslatable(TRUE);
return $fields; return $fields;
......
<?php
namespace Drupal\Tests\content_moderation\Kernel;
use Drupal\content_moderation\Entity\Handler\ModerationHandler;
use Drupal\content_moderation\EntityTypeInfo;
use Drupal\KernelTests\KernelTestBase;
/**
* @coversDefaultClass \Drupal\content_moderation\EntityTypeInfo
*
* @group content_moderation
*/
class EntityTypeInfoTest extends KernelTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = [
'content_moderation',
'entity_test',
];
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* The entity type info class.
*
* @var \Drupal\content_moderation\EntityTypeInfo
*/
protected $entityTypeInfo;
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->entityTypeInfo = $this->container->get('class_resolver')->getInstanceFromDefinition(EntityTypeInfo::class);
$this->entityTypeManager = $this->container->get('entity_type.manager');
}
/**
* @covers ::entityBaseFieldInfo
*/
public function testEntityBaseFieldInfo() {
$definition = $this->entityTypeManager->getDefinition('entity_test');
$definition->setHandlerClass('moderation', ModerationHandler::class);
$base_fields = $this->entityTypeInfo->entityBaseFieldInfo($definition);
$this->assertFalse($base_fields['moderation_state']->isReadOnly());
$this->assertTrue($base_fields['moderation_state']->isComputed());
$this->assertTrue($base_fields['moderation_state']->isTranslatable());
}
}
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