Skip to main content
added 8 characters in body
Source Link
Geat
  • 463
  • 2
  • 14

Thanks to Matt's solution I was able to save a text_format element that's part of a custom field, but I also wanted to store the chosen format so I did this:

public function massageFormValues(array $values, array $form, FormStateInterface $form_state) {
    foreach($values as $index => $value) {
        $values[$index]['body'] = json_encode($value$value['body']);
    }
    return $values;
}

When re-populating the edit form, I can json_decode as applicable to get the value and text format out of the string.

Thanks to Matt's solution I was able to save a text_format element that's part of a custom field, but I also wanted to store the chosen format so I did this:

public function massageFormValues(array $values, array $form, FormStateInterface $form_state) {
    foreach($values as $index => $value) {
        $values[$index]['body'] = json_encode($value);
    }
    return $values;
}

When re-populating the edit form, I can json_decode as applicable to get the value and text format out of the string.

Thanks to Matt's solution I was able to save a text_format element that's part of a custom field, but I also wanted to store the chosen format so I did this:

public function massageFormValues(array $values, array $form, FormStateInterface $form_state) {
    foreach($values as $index => $value) {
        $values[$index]['body'] = json_encode($value['body']);
    }
    return $values;
}

When re-populating the edit form, I can json_decode as applicable to get the value and text format out of the string.

Source Link
Geat
  • 463
  • 2
  • 14

Thanks to Matt's solution I was able to save a text_format element that's part of a custom field, but I also wanted to store the chosen format so I did this:

public function massageFormValues(array $values, array $form, FormStateInterface $form_state) {
    foreach($values as $index => $value) {
        $values[$index]['body'] = json_encode($value);
    }
    return $values;
}

When re-populating the edit form, I can json_decode as applicable to get the value and text format out of the string.