I have a field defined as 'long text' that allows infinite number of values. The difficulty is that users are entering everything in one iteration of the field. So, I need to get the value they have entered, explode it and create separate multi-value field entries. But... my approach isn't working:
function builder2020_entity_presave(EntityInterface $entity){
switch ($entity->bundle()) {
case 'ec_topics':
$count = count($entity->field_ec_subtopics);//check if the user has only used one field
if ($count == 1){ //user has put everything in one field value
$values = array(explode('\n',$entity->field_ec_subtopics->value)); create array from the field value
$entity->field_subtopics->value = $values; //feed the array to the field
}
$entity->field_sub_topic_count->value = $count; //set the number of ec_topics
break;
I 'think' I'm close, but I can't seem to figure out where I'm falling down.