Commit 82f1a1ca authored by catch's avatar catch

Issue #2848775 by Sam152, eyilmaz, D34dMan, DuneBL, huzooka: BaseFieldOverride...

Issue #2848775 by Sam152, eyilmaz, D34dMan, DuneBL, huzooka: BaseFieldOverride entities created by content_translation break content_moderation because they don't support computed fields
parent 48339450
......@@ -142,6 +142,13 @@ public function isComputed() {
return $this->getBaseFieldDefinition()->isComputed();
}
/**
* {@inheritdoc}
*/
public function getClass() {
return $this->getBaseFieldDefinition()->getClass();
}
/**
* Gets the base field definition.
*
......
......@@ -398,6 +398,37 @@ public function testMultilingualModeration() {
$this->assertEquals(6, $english_node->getRevisionId());
}
/**
* Tests moderation when the moderation_state field has a config override.
*/
public function testModerationWithFieldConfigOverride() {
NodeType::create([
'type' => 'test_type',
])->save();
$workflow = Workflow::load('editorial');
$workflow->getTypePlugin()->addEntityTypeAndBundle('node', 'test_type');
$workflow->save();
$fields = $this->container->get('entity_field.manager')->getFieldDefinitions('node', 'test_type');
$field_config = $fields['moderation_state']->getConfig('test_type');
$field_config->setLabel('Field Override!');
$field_config->save();
$node = Node::create([
'title' => 'Test node',
'type' => 'test_type',
]);
$node->save();
$this->assertFalse($node->isPublished());
$this->assertEquals('draft', $node->moderation_state->value);
$node->moderation_state = 'published';
$node->save();
$this->assertTrue($node->isPublished());
$this->assertEquals('published', $node->moderation_state->value);
}
/**
* Tests that entities with special languages can be moderated.
*/
......
<?php
namespace Drupal\KernelTests\Core\Field\Entity;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\Core\Field\Entity\BaseFieldOverride;
use Drupal\Core\Field\FieldItemList;
use Drupal\KernelTests\KernelTestBase;
/**
* @coversDefaultClass \Drupal\Core\Field\Entity\BaseFieldOverride
* @group Field
*/
class BaseFieldOverrideTest extends KernelTestBase {
/**
* Modules to install.
*
* @var array
*/
public static $modules = ['system'];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installEntitySchema('base_field_override');
}
/**
* @covers ::getClass
*
* @dataProvider getClassTestCases
*/
public function testGetClass($field_type, $base_field_class, $expected_override_class) {
$base_field = BaseFieldDefinition::create($field_type)
->setName('Test Field')
->setTargetEntityTypeId('entity_test');
if ($base_field_class) {
$base_field->setClass($base_field_class);
}
$override = BaseFieldOverride::createFromBaseFieldDefinition($base_field, 'test_bundle');
$this->assertEquals($expected_override_class, ltrim($override->getClass(), '\\'));
}
/**
* Test cases for ::testGetClass.
*/
public function getClassTestCases() {
return [
'String (default class)' => [
'string',
FALSE,
FieldItemList::class,
],
'String (overriden class)' => [
'string',
static::class,
static::class,
],
];
}
}
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