Custom field: process submitted before storing I've created custom field type and widget plugins in D8.

I am presenting an element in my widget as checkboxes, but I need to transform the resulting array into text delimited by pipes. i.e. a|b|c.

How would I approach this in the field widget?
messageFormValues in the widget class did the job.

class MyDefaultWidget extends WidgetBase {
  ...
  /**
   * {@inheritdoc}
   */
  public function massageFormValues(array $values, array $form, FormStateInterface $form_state) {
    // Change the format of $item['sections'] from array to pipe delimited string.
    foreach ($values as &amp;$item) {
      $sections = [];
      if (is_array($item['sections'])) {
        foreach ($item['sections'] as $s) {
          if ($s !== 0) {
            $sections[] = $s;
          }
        }
      }
      $item['sections'] = implode('|', $sections);
    }
    return $values;
  }
  ...
}