Loading modules/flow_ui/src/Form/TaskForm.php +18 −0 Original line number Diff line number Diff line Loading @@ -415,6 +415,7 @@ class TaskForm implements FormInterface, ContainerInjectionInterface { foreach ($subject->getThirdPartyProviders() as $provider) { $tasks_array[$this->taskIndex]['subject']['third_party_settings'][$provider] = $subject->getThirdPartySettings($provider); } $this->filterRuntimeSettings($tasks_array); $flow->setTasks($tasks_array); $flow->save(); } Loading Loading @@ -505,4 +506,21 @@ class TaskForm implements FormInterface, ContainerInjectionInterface { $form_state->set('task_index', $this->taskIndex); } /** * Filters runtime settings from the given array. * * @param array &$array * The array. */ protected function filterRuntimeSettings(&$array) { foreach ($array as $k => $v) { if ($k === 'target_for' || $k === 'subject_for') { unset($array[$k]); } elseif (is_array($v)) { $this->filterRuntimeSettings($array[$k]); } } } } tests/src/Kernel/MergeTest.php +4 −0 Original line number Diff line number Diff line Loading @@ -4,6 +4,7 @@ namespace Drupal\Tests\flow\Kernel; use Drupal\KernelTests\KernelTestBase; use Drupal\node\Entity\Node; use Drupal\user\Entity\User; /** * Tests merging field values using Flow. Loading Loading @@ -33,6 +34,8 @@ class MergeTest extends KernelTestBase { $this->installEntitySchema('user'); $this->installEntitySchema('node'); $this->installConfig(static::$modules); User::create(['uid' => 0, 'status' => 0, 'name' => ''])->save(); User::create(['uid' => 1, 'name' => 'admin'])->save(); } /** Loading @@ -54,6 +57,7 @@ class MergeTest extends KernelTestBase { $this->assertEquals('First page!', (string) $node->label()); $this->assertEquals('The "First page" got merged.', $node->body->value); $this->assertEquals('Merged summary value.', $node->body->summary); $this->assertSame((string) $node->uid->target_id, '0', "UID must not have been changed."); } } tests/src/Kernel/RelateTest.php 0 → 100644 +151 −0 Original line number Diff line number Diff line <?php namespace Drupal\Tests\flow\Kernel; use Drupal\field\Entity\FieldConfig; use Drupal\field\Entity\FieldStorageConfig; use Drupal\flow\Entity\Flow; use Drupal\KernelTests\KernelTestBase; use Drupal\node\Entity\Node; use Drupal\node\Entity\NodeType; use Drupal\user\Entity\User; /** * Tests relating content using Flow. * * @group flow */ class RelateTest extends KernelTestBase { protected static $modules = [ 'system', 'user', 'field', 'filter', 'text', 'node', 'serialization', 'flow', ]; /** * {@inheritdoc} */ public function setUp(): void { parent::setUp(); $this->installEntitySchema('user'); $this->installEntitySchema('node'); $this->installSchema('node', ['node_access']); $this->installConfig(static::$modules); User::create(['uid' => 0, 'status' => 0, 'name' => ''])->save(); User::create(['uid' => 1, 'name' => 'admin'])->save(); $node_type = NodeType::create([ 'type' => 'article', 'name' => 'Article', 'new_revision' => TRUE, ]); $node_type->save(); } /** * Tests relating content. */ public function testRelateContent() { // Create a reference field. $field_definition = FieldStorageConfig::create([ 'field_name' => 'field_other_content', 'type' => 'entity_reference', 'entity_type' => 'node', 'settings' => [ 'target_type' => 'node', ], 'cardinality' => FieldStorageConfig::CARDINALITY_UNLIMITED, ]); $field_definition->save(); $field = FieldConfig::create([ 'field_storage' => $field_definition, 'label' => 'Other content', 'entity_type' => 'node', 'bundle' => 'article', ]); $field->save(); $node1 = Node::create([ 'type' => 'article', 'uid' => 1, 'status' => 1, 'title' => 'My first article', ]); $node1->save(); $node2 = Node::create([ 'type' => 'article', 'uid' => 1, 'status' => 1, 'title' => 'My second article', ]); $node2->save(); $this->assertNull($node1->field_other_content->target_id); $this->assertNull($node2->field_other_content->target_id); // Create a Flow configuration for relating content. Flow::create([ 'langcode' => 'en', 'status' => TRUE, 'id' => 'node.article.save', 'targetEntityType' => 'node', 'targetBundle' => 'article', 'taskMode' => 'save', 'tasks' => [ [ 'id' => 'relate:node.article::node.article', 'type' => 'relate', 'weight' => 0, 'active' => TRUE, 'execution' => ['start' => 'now'], 'subject' => [ 'id' => 'save:node.article', 'type' => 'save', 'settings' => [], 'third_party_settings' => [], ], 'settings' => [ 'field_name' => 'field_other_content', 'method' => 'set:clear', 'reverse' => [ 'field_name' => 'field_other_content', 'method' => 'set:clear', ], 'target' => [ 'id' => 'load:node.article', 'type' => 'load', 'settings' => [ 'mode' => 'id', 'entity_id' => (string) $node2->id(), 'entity_uuid' => NULL, 'view' => [ 'id' => NULL, 'display' => NULL, 'arguments' => NULL, ], 'fallback' => ['method' => 'nothing'], ], ], ], 'third_party_settings' => [], ], ], ]) ->save(); $node1->save(); $node1 = Node::load($node1->id()); $node2 = Node::load($node2->id()); $this->assertCount(1, $node1->field_other_content); $this->assertCount(1, $node2->field_other_content); $this->assertSame((string) $node2->id(), (string) $node1->field_other_content->target_id); $this->assertSame((string) $node1->id(), (string) $node2->field_other_content->target_id); } } Loading
modules/flow_ui/src/Form/TaskForm.php +18 −0 Original line number Diff line number Diff line Loading @@ -415,6 +415,7 @@ class TaskForm implements FormInterface, ContainerInjectionInterface { foreach ($subject->getThirdPartyProviders() as $provider) { $tasks_array[$this->taskIndex]['subject']['third_party_settings'][$provider] = $subject->getThirdPartySettings($provider); } $this->filterRuntimeSettings($tasks_array); $flow->setTasks($tasks_array); $flow->save(); } Loading Loading @@ -505,4 +506,21 @@ class TaskForm implements FormInterface, ContainerInjectionInterface { $form_state->set('task_index', $this->taskIndex); } /** * Filters runtime settings from the given array. * * @param array &$array * The array. */ protected function filterRuntimeSettings(&$array) { foreach ($array as $k => $v) { if ($k === 'target_for' || $k === 'subject_for') { unset($array[$k]); } elseif (is_array($v)) { $this->filterRuntimeSettings($array[$k]); } } } }
tests/src/Kernel/MergeTest.php +4 −0 Original line number Diff line number Diff line Loading @@ -4,6 +4,7 @@ namespace Drupal\Tests\flow\Kernel; use Drupal\KernelTests\KernelTestBase; use Drupal\node\Entity\Node; use Drupal\user\Entity\User; /** * Tests merging field values using Flow. Loading Loading @@ -33,6 +34,8 @@ class MergeTest extends KernelTestBase { $this->installEntitySchema('user'); $this->installEntitySchema('node'); $this->installConfig(static::$modules); User::create(['uid' => 0, 'status' => 0, 'name' => ''])->save(); User::create(['uid' => 1, 'name' => 'admin'])->save(); } /** Loading @@ -54,6 +57,7 @@ class MergeTest extends KernelTestBase { $this->assertEquals('First page!', (string) $node->label()); $this->assertEquals('The "First page" got merged.', $node->body->value); $this->assertEquals('Merged summary value.', $node->body->summary); $this->assertSame((string) $node->uid->target_id, '0', "UID must not have been changed."); } }
tests/src/Kernel/RelateTest.php 0 → 100644 +151 −0 Original line number Diff line number Diff line <?php namespace Drupal\Tests\flow\Kernel; use Drupal\field\Entity\FieldConfig; use Drupal\field\Entity\FieldStorageConfig; use Drupal\flow\Entity\Flow; use Drupal\KernelTests\KernelTestBase; use Drupal\node\Entity\Node; use Drupal\node\Entity\NodeType; use Drupal\user\Entity\User; /** * Tests relating content using Flow. * * @group flow */ class RelateTest extends KernelTestBase { protected static $modules = [ 'system', 'user', 'field', 'filter', 'text', 'node', 'serialization', 'flow', ]; /** * {@inheritdoc} */ public function setUp(): void { parent::setUp(); $this->installEntitySchema('user'); $this->installEntitySchema('node'); $this->installSchema('node', ['node_access']); $this->installConfig(static::$modules); User::create(['uid' => 0, 'status' => 0, 'name' => ''])->save(); User::create(['uid' => 1, 'name' => 'admin'])->save(); $node_type = NodeType::create([ 'type' => 'article', 'name' => 'Article', 'new_revision' => TRUE, ]); $node_type->save(); } /** * Tests relating content. */ public function testRelateContent() { // Create a reference field. $field_definition = FieldStorageConfig::create([ 'field_name' => 'field_other_content', 'type' => 'entity_reference', 'entity_type' => 'node', 'settings' => [ 'target_type' => 'node', ], 'cardinality' => FieldStorageConfig::CARDINALITY_UNLIMITED, ]); $field_definition->save(); $field = FieldConfig::create([ 'field_storage' => $field_definition, 'label' => 'Other content', 'entity_type' => 'node', 'bundle' => 'article', ]); $field->save(); $node1 = Node::create([ 'type' => 'article', 'uid' => 1, 'status' => 1, 'title' => 'My first article', ]); $node1->save(); $node2 = Node::create([ 'type' => 'article', 'uid' => 1, 'status' => 1, 'title' => 'My second article', ]); $node2->save(); $this->assertNull($node1->field_other_content->target_id); $this->assertNull($node2->field_other_content->target_id); // Create a Flow configuration for relating content. Flow::create([ 'langcode' => 'en', 'status' => TRUE, 'id' => 'node.article.save', 'targetEntityType' => 'node', 'targetBundle' => 'article', 'taskMode' => 'save', 'tasks' => [ [ 'id' => 'relate:node.article::node.article', 'type' => 'relate', 'weight' => 0, 'active' => TRUE, 'execution' => ['start' => 'now'], 'subject' => [ 'id' => 'save:node.article', 'type' => 'save', 'settings' => [], 'third_party_settings' => [], ], 'settings' => [ 'field_name' => 'field_other_content', 'method' => 'set:clear', 'reverse' => [ 'field_name' => 'field_other_content', 'method' => 'set:clear', ], 'target' => [ 'id' => 'load:node.article', 'type' => 'load', 'settings' => [ 'mode' => 'id', 'entity_id' => (string) $node2->id(), 'entity_uuid' => NULL, 'view' => [ 'id' => NULL, 'display' => NULL, 'arguments' => NULL, ], 'fallback' => ['method' => 'nothing'], ], ], ], 'third_party_settings' => [], ], ], ]) ->save(); $node1->save(); $node1 = Node::load($node1->id()); $node2 = Node::load($node2->id()); $this->assertCount(1, $node1->field_other_content); $this->assertCount(1, $node2->field_other_content); $this->assertSame((string) $node2->id(), (string) $node1->field_other_content->target_id); $this->assertSame((string) $node1->id(), (string) $node2->field_other_content->target_id); } }