I have a custom content type with a field (id is field_link_to_persona) that is multi-valued text. In my UI I have checkboxes that correspond to values in that field and if I uncheck the box and save I want to remove the value from the field.
I load the node like this:
$ nodes = \Drupal::entityTypeManager() ->getStorage('node') ->loadByProperties(['type' => 'document', 'nid' => $ docID ]); $ node = reset($ nodes);
I can add new values like this:
$ node->field_link_to_persona[] = $ newValue;
But how do I remove one? I tried
$ node->field_link_to_persona->removeItem($ id);
But I keep getting exceptions about the index not existing.
Any help would be appreciated. I’m somewhat new to drupal so no detail is too trivial π