summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathaniel Catchpole2017-08-14 10:38:26 +0900
committerNathaniel Catchpole2017-08-14 10:38:30 +0900
commit7c87acfe5d0ee6c3e765a22241389bbd8812e27b (patch)
treed2ca06187ffe8ffe03bb8cf0aab186d296ccbf00
parent7feedc23c9c9c86c5d95efa4383606c936389b49 (diff)
Issue #2848775 by Sam152, eyilmaz, D34dMan, DuneBL, huzooka: BaseFieldOverride entities created by content_translation break content_moderation because they don't support computed fields
(cherry picked from commit 82f1a1ca6cdc4c41fe399914dedd226a8250294d)
-rw-r--r--core/lib/Drupal/Core/Field/Entity/BaseFieldOverride.php7
-rw-r--r--core/modules/content_moderation/tests/src/Kernel/ContentModerationStateTest.php31
-rw-r--r--core/tests/Drupal/KernelTests/Core/Field/Entity/BaseFieldOverrideTest.php65
3 files changed, 103 insertions, 0 deletions
diff --git a/core/lib/Drupal/Core/Field/Entity/BaseFieldOverride.php b/core/lib/Drupal/Core/Field/Entity/BaseFieldOverride.php
index f20f3a5..b31833a 100644
--- a/core/lib/Drupal/Core/Field/Entity/BaseFieldOverride.php
+++ b/core/lib/Drupal/Core/Field/Entity/BaseFieldOverride.php
@@ -143,6 +143,13 @@ class BaseFieldOverride extends FieldConfigBase {
}
/**
+ * {@inheritdoc}
+ */
+ public function getClass() {
+ return $this->getBaseFieldDefinition()->getClass();
+ }
+
+ /**
* Gets the base field definition.
*
* @return \Drupal\Core\Field\BaseFieldDefinition
diff --git a/core/modules/content_moderation/tests/src/Kernel/ContentModerationStateTest.php b/core/modules/content_moderation/tests/src/Kernel/ContentModerationStateTest.php
index db80eea..e52bf96 100644
--- a/core/modules/content_moderation/tests/src/Kernel/ContentModerationStateTest.php
+++ b/core/modules/content_moderation/tests/src/Kernel/ContentModerationStateTest.php
@@ -399,6 +399,37 @@ class ContentModerationStateTest extends KernelTestBase {
}
/**
+ * 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.
*/
public function testModerationWithSpecialLanguages() {
diff --git a/core/tests/Drupal/KernelTests/Core/Field/Entity/BaseFieldOverrideTest.php b/core/tests/Drupal/KernelTests/Core/Field/Entity/BaseFieldOverrideTest.php
new file mode 100644
index 0000000..404c2f0
--- /dev/null
+++ b/core/tests/Drupal/KernelTests/Core/Field/Entity/BaseFieldOverrideTest.php
@@ -0,0 +1,65 @@
+<?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,
+ ],
+ ];
+ }
+
+}