updated core to 8.6.3
This commit is contained in:
+1
-1
@@ -127,7 +127,7 @@ class ModerationStateWidget extends OptionsSelectWidget implements ContainerFact
|
||||
$transitions = $this->validator->getValidTransitions($entity, $this->currentUser);
|
||||
|
||||
$transition_labels = [];
|
||||
$default_value = NULL;
|
||||
$default_value = $items->value;
|
||||
foreach ($transitions as $transition) {
|
||||
$transition_to_state = $transition->to();
|
||||
$transition_labels[$transition_to_state->id()] = $transition_to_state->label();
|
||||
|
||||
@@ -16,7 +16,6 @@ use Drupal\Core\TypedData\ComputedItemListTrait;
|
||||
class ModerationStateFieldItemList extends FieldItemList {
|
||||
|
||||
use ComputedItemListTrait {
|
||||
ensureComputedValue as traitEnsureComputedValue;
|
||||
get as traitGet;
|
||||
}
|
||||
|
||||
@@ -34,19 +33,6 @@ class ModerationStateFieldItemList extends FieldItemList {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function ensureComputedValue() {
|
||||
// If the moderation state field is set to an empty value, always recompute
|
||||
// the state. Empty is not a valid moderation state value, when none is
|
||||
// present the default state is used.
|
||||
if (!isset($this->list[0]) || $this->list[0]->isEmpty()) {
|
||||
$this->valueComputed = FALSE;
|
||||
}
|
||||
$this->traitEnsureComputedValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the moderation state ID linked to a content entity revision.
|
||||
*
|
||||
@@ -140,10 +126,8 @@ class ModerationStateFieldItemList extends FieldItemList {
|
||||
*/
|
||||
public function setValue($values, $notify = TRUE) {
|
||||
parent::setValue($values, $notify);
|
||||
$this->valueComputed = TRUE;
|
||||
|
||||
if (isset($this->list[0])) {
|
||||
$this->valueComputed = TRUE;
|
||||
}
|
||||
// If the parent created a field item and if the parent should be notified
|
||||
// about the change (e.g. this is not initialized with the current value),
|
||||
// update the moderated entity.
|
||||
|
||||
+8
@@ -9,6 +9,7 @@ use Drupal\Core\Entity\EntityInterface;
|
||||
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||
use Drupal\content_moderation\ModerationInformationInterface;
|
||||
use Drupal\Core\Session\AccountInterface;
|
||||
use Drupal\Core\Validation\Plugin\Validation\Constraint\NotNullConstraint;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
use Symfony\Component\Validator\ConstraintValidator;
|
||||
@@ -89,6 +90,13 @@ class ModerationStateConstraintValidator extends ConstraintValidator implements
|
||||
return;
|
||||
}
|
||||
|
||||
// If the entity is moderated and the item list is empty, ensure users see
|
||||
// the same required message as typical NotNull constraints.
|
||||
if ($value->isEmpty()) {
|
||||
$this->context->addViolation((new NotNullConstraint())->message);
|
||||
return;
|
||||
}
|
||||
|
||||
$workflow = $this->moderationInformation->getWorkflowForEntity($entity);
|
||||
|
||||
if (!$workflow->getTypePlugin()->hasState($entity->moderation_state->value)) {
|
||||
|
||||
+57
-6
@@ -102,20 +102,70 @@ class ModerationStateFieldItemListTest extends KernelTestBase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the computed field when it is unset or set to an empty value.
|
||||
* Tests the item list when it is emptied and appended to.
|
||||
*/
|
||||
public function testSetEmptyState() {
|
||||
public function testEmptyStateAndAppend() {
|
||||
// This test case mimics the lifecycle of an entity that is being patched in
|
||||
// a rest resource.
|
||||
$this->testNode->moderation_state->setValue([]);
|
||||
$this->assertTrue($this->testNode->moderation_state->isEmpty());
|
||||
$this->assertEmptiedModerationFieldItemList();
|
||||
|
||||
$this->testNode->moderation_state->appendItem();
|
||||
$this->assertEquals(1, $this->testNode->moderation_state->count());
|
||||
$this->assertEquals(NULL, $this->testNode->moderation_state->value);
|
||||
$this->assertEmptiedModerationFieldItemList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test an empty value assigned to the field item.
|
||||
*/
|
||||
public function testEmptyFieldItem() {
|
||||
$this->testNode->moderation_state->value = '';
|
||||
$this->assertEquals('draft', $this->testNode->moderation_state->value);
|
||||
$this->assertEquals('', $this->testNode->moderation_state->value);
|
||||
$this->assertEmptiedModerationFieldItemList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test an empty value assigned to the field item list.
|
||||
*/
|
||||
public function testEmptyFieldItemList() {
|
||||
$this->testNode->moderation_state = '';
|
||||
$this->assertEquals('draft', $this->testNode->moderation_state->value);
|
||||
$this->assertEquals('', $this->testNode->moderation_state->value);
|
||||
$this->assertEmptiedModerationFieldItemList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the field item when it is unset.
|
||||
*/
|
||||
public function testUnsetItemList() {
|
||||
unset($this->testNode->moderation_state);
|
||||
$this->assertEquals('draft', $this->testNode->moderation_state->value);
|
||||
$this->assertEquals(NULL, $this->testNode->moderation_state->value);
|
||||
$this->assertEmptiedModerationFieldItemList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the field item when it is assigned NULL.
|
||||
*/
|
||||
public function testAssignNullItemList() {
|
||||
$this->testNode->moderation_state = NULL;
|
||||
$this->assertEquals('draft', $this->testNode->moderation_state->value);
|
||||
$this->assertEquals(NULL, $this->testNode->moderation_state->value);
|
||||
$this->assertEmptiedModerationFieldItemList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert the set of expectations when the moderation state field is emptied.
|
||||
*/
|
||||
protected function assertEmptiedModerationFieldItemList() {
|
||||
$this->assertTrue($this->testNode->moderation_state->isEmpty());
|
||||
// Test the empty value causes a violation in the entity.
|
||||
$violations = $this->testNode->validate();
|
||||
$this->assertCount(1, $violations);
|
||||
$this->assertEquals('This value should not be null.', $violations->get(0)->getMessage());
|
||||
// Test that incorrectly saving the entity regardless will not produce a
|
||||
// change in the moderation state.
|
||||
$this->testNode->save();
|
||||
$this->assertEquals('draft', Node::load($this->testNode->id())->moderation_state->value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -131,6 +181,7 @@ class ModerationStateFieldItemListTest extends KernelTestBase {
|
||||
|
||||
$unmoderated_node->moderation_state = NULL;
|
||||
$this->assertEquals(0, $unmoderated_node->moderation_state->count());
|
||||
$this->assertCount(0, $unmoderated_node->validate());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user