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
|
// check if the user gets to pick his own lists
|
||||||
// or if it's selected by the admin
|
// 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 = [];
|
$listSelection = [];
|
||||||
foreach ($body as $i => $block) {
|
foreach ($listSelectionBlocks as $listSelectionBlock) {
|
||||||
if ($block['type'] === 'segment') {
|
$listSelection = array_unique(
|
||||||
$hasSegmentSelection = true;
|
array_merge(
|
||||||
if (!empty($block['params']['values'])) {
|
$listSelection, array_column($listSelectionBlock['params']['values'] ?? [], 'id')
|
||||||
$listSelection = array_filter(
|
)
|
||||||
array_map(function($segment) {
|
);
|
||||||
return (isset($segment['id'])
|
|
||||||
? $segment['id']
|
|
||||||
: null
|
|
||||||
);
|
|
||||||
}, $block['params']['values'])
|
|
||||||
);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// check list selection
|
// check list selection
|
||||||
if ($hasSegmentSelection === true) {
|
if (count($listSelectionBlocks)) {
|
||||||
$settings['segments_selected_by'] = 'user';
|
$settings['segments_selected_by'] = 'user';
|
||||||
$settings['segments'] = $listSelection;
|
$settings['segments'] = $listSelection;
|
||||||
} else {
|
} else {
|
||||||
|
@ -133,6 +133,36 @@ class FormsTest extends \MailPoetTest {
|
|||||||
expect($response->data['settings']['segments'])->equals([1, 3]);
|
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() {
|
public function testItCanRestoreAForm() {
|
||||||
$this->form1->trash();
|
$this->form1->trash();
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user