Fix searching for segments to work with nested segments block
[MAILPOET-3297]
This commit is contained in:
committed by
Veljko V
parent
46f9860990
commit
36a7cc0b25
@ -209,27 +209,20 @@ class Forms extends APIEndpoint {
|
||||
|
||||
// check if the user gets to pick his own lists
|
||||
// or if it's selected by the admin
|
||||
$hasSegmentSelection = false;
|
||||
$formEntity = new FormEntity($name);
|
||||
$formEntity->setBody($body);
|
||||
$listSelectionBlocks = $formEntity->getBlocksByType(FormEntity::SEGMENT_SELECTION_BLOCK_TYPE);
|
||||
$listSelection = [];
|
||||
foreach ($body as $i => $block) {
|
||||
if ($block['type'] === 'segment') {
|
||||
$hasSegmentSelection = true;
|
||||
if (!empty($block['params']['values'])) {
|
||||
$listSelection = array_filter(
|
||||
array_map(function($segment) {
|
||||
return (isset($segment['id'])
|
||||
? $segment['id']
|
||||
: null
|
||||
foreach ($listSelectionBlocks as $listSelectionBlock) {
|
||||
$listSelection = array_unique(
|
||||
array_merge(
|
||||
$listSelection, array_column($listSelectionBlock['params']['values'] ?? [], 'id')
|
||||
)
|
||||
);
|
||||
}, $block['params']['values'])
|
||||
);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// check list selection
|
||||
if ($hasSegmentSelection === true) {
|
||||
if (count($listSelectionBlocks)) {
|
||||
$settings['segments_selected_by'] = 'user';
|
||||
$settings['segments'] = $listSelection;
|
||||
} else {
|
||||
|
@ -133,6 +133,36 @@ class FormsTest extends \MailPoetTest {
|
||||
expect($response->data['settings']['segments'])->equals([1, 3]);
|
||||
}
|
||||
|
||||
public function testItCanExtractListsFromNestedListSelectionBlock() {
|
||||
$response = $this->endpoint->create();
|
||||
expect($response->status)->equals(APIResponse::STATUS_OK);
|
||||
|
||||
$form = Form::findOne($response->data['id'])->asArray();
|
||||
$form['body'][] = [
|
||||
'type' => 'segment',
|
||||
'params' => [
|
||||
'values' => [['id' => 2], ['id' => 4]],
|
||||
],
|
||||
];
|
||||
|
||||
$form['body'] = [
|
||||
[
|
||||
'type' => 'columns',
|
||||
'body' => [
|
||||
[
|
||||
'type' => 'column',
|
||||
'body' => $form['body'],
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
$response = $this->endpoint->saveEditor($form);
|
||||
expect($response->status)->equals(APIResponse::STATUS_OK);
|
||||
expect($response->data['settings']['segments_selected_by'])->equals('user');
|
||||
expect($response->data['settings']['segments'])->equals([2, 4]);
|
||||
}
|
||||
|
||||
public function testItCanRestoreAForm() {
|
||||
$this->form1->trash();
|
||||
|
||||
|
Reference in New Issue
Block a user