I have a custom entity type, and I'm defining its form, which extends ContentEntityForm
. During my save()
function, I want the form to conditionally unset fields based on the values of other fields. (example: unset the value of a list select field if a certain checkbox is checked off)
I can't seem to accomplish this with $form_state->setValue()
or $form_state->setValueForElement()
, in both cases my code is seemingly ignored and the select widget is not unset upon finishing saving (although a var_dump of $form_state->getValues()
at the end of the function shows that the values array is indeed being modified the way I want it to be).
However, the following code seems to work nicely for the title
field (defined via baseFieldDefinitions()
, is not inside a field collection):
$entity = $this->getEntity();
$entity->set('title', array(array("value" => "aaaaaaaa")));
$entity->save();
My title for the newly saved entity does indeed show up as "aaaaaaaa"
Is it possible to target fields inside field collections in this way using this $entity
object? Or is this the totally wrong approach?