Skip to content
Snippets Groups Projects
Commit 772dafa6 authored by Jürgen Haas's avatar Jürgen Haas Committed by Jürgen Haas
Browse files

Issue #3502635: ECA Content - field value changed condition with base field overrides



(cherry picked from commit cd4f80d6)

a732095b Issue #3502635: Add test condition for BaseFieldOverride.
8e2100ac Issue #3502635: Replace FieldConfig with FieldConfigInterface.
e60313f1 Apply 1 suggestion(s) to 1 file(s)

Co-authored-by: default avatarRyan Apking <71161-rapking@users.noreply.drupalcode.org>
parent f02168ef
No related branches found
Tags 8.x-1.11
No related merge requests found
Pipeline #408255 passed with warnings
......@@ -4,11 +4,11 @@ namespace Drupal\eca_content\Plugin\ECA\Condition;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\Core\Field\FieldConfigInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\eca\EntityOriginalTrait;
use Drupal\eca\Plugin\ECA\Condition\ConditionBase;
use Drupal\eca\TypedData\PropertyPathTrait;
use Drupal\field\Entity\FieldConfig;
/**
* Plugin implementation of the ECA condition for changed entity field value.
......@@ -44,7 +44,7 @@ class EntityFieldValueChanged extends ConditionBase {
}
$dataDefinition = $property->getDataDefinition();
if ($dataDefinition instanceof FieldConfig || $dataDefinition instanceof BaseFieldDefinition) {
if ($dataDefinition instanceof FieldConfigInterface || $dataDefinition instanceof BaseFieldDefinition) {
$type = $dataDefinition->getFieldStorageDefinition()->getType();
if (in_array($type, ['boolean', 'entity_reference'], TRUE)) {
foreach ($value as $key => $item) {
......
......@@ -108,11 +108,15 @@ class EntityFieldValueChangedTest extends KernelTestBase {
],
])->save();
// Create a base_field_override.
\Drupal::service('entity_field.manager')->getBaseFieldDefinitions('node')['status']->getConfig('article')->save();
$this->node = Node::create([
'type' => 'article',
'uid' => 1,
'title' => 'First article',
'field_boolean_test' => 0,
'status' => 0,
]);
$this->node->save();
......@@ -167,6 +171,15 @@ class EntityFieldValueChangedTest extends KernelTestBase {
]);
$this->condition->setContextValue('entity', $this->node);
$this->assertTrue($this->condition->evaluate());
/** @var \Drupal\eca_content\Plugin\ECA\Condition\EntityFieldValueChanged $condition */
$this->condition = $this->conditionManager->createInstance('eca_entity_field_value_changed', [
'field_name' => 'status',
]);
$this->node->setUnpublished();
$this->condition->setContextValue('entity', $this->node);
$this->assertFalse($this->condition->evaluate());
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment