I was saving poll choices Programmatically in Drupal 8. I have used Drupal8 Poll choices module.
$node_poll = Poll::load($pollid);
//print_r($node_poll);exit;
$i = array(13,14,15);
foreach($i as $key => $value){
$node_poll->choice->setValue(
[
['target_id' => $value]
]
);
// But I want to save multiple target ids. now this is saving 15 all the time.
}
$node_poll->question->setValue([
'value' => 'test',
]);
$node_poll->save();
The following snippet is working fine.
$node_poll->choice->setValue(
[
['target_id' => 13]
],
[
['target_id' => 14]
],
[
['target_id' => 15]
]
);
How can I, make target ids to be saved dynamically?