Custom content entity field widget. This value should not be null I've created a custom content entity in Drupal 8 and all is well in those regards. I have an issue when I go to create a new record for my entity using the entity form. "This value should not be null.". 

The error comes from a widget plugin that I've created that only replicates the functionality of a list of checkboxes that represent taxonomy terms. The field that uses this widget is not a base field, it's added through the UI. 
I've looked at the plugin documentation on drupal.org and haven't found much help in regards to my issue. 



Below, is my code for the widget form element.

namespace Drupal\my_entity\Plugin\Field\FieldWidget;

use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Field\Plugin\Field\FieldWidget\OptionsWidgetBase;
use Drupal\Core\Ajax\AjaxResponse;
use Drupal\Core\Ajax\ReplaceCommand;
use Drupal\taxonomy\Entity\Term;
use Drupal\user\Entity\User;

/**
 * A widget for displaying terms and supplying an AJAX request when a checkbox is clicked
 *
 * @FieldWidget(
 *   id = "my_entity_programme_areas_lookup_directors",
 *   module = "my_entity",
 *   label = @Translation("Programme Areas Lookup Directors Widget"),
 *   field_types = {
 *     "entity_reference"
 *   }
 * )
 */
class ProgrammeAreasLookupDirectorsWidget extends OptionsWidgetBase
{

  /**
   * {@inheritdoc}
   */
  public function formElement(FieldItemListInterface $items, $delta, array $element, array &amp;$form, FormStateInterface $form_state) {

    $value = isset($items[$delta]-&gt;value) ? $items[$delta]-&gt;value : NULL;

    $element = parent::formElement($items, $delta, $element, $form, $form_state);

    $element += [
      '#type'          =&gt; 'checkboxes',
      '#default_value' =&gt; $this-&gt;getSelectedOptions($items),
      '#options'       =&gt; $this-&gt;getOptions($items-&gt;getEntity()),
      '#multiple'      =&gt; TRUE,
      '#element_validate' =&gt; [
        [static::class, 'validate'],
      ],
      '#prefix' =&gt; '&lt;div id="programme-areas-directors-lookup"&gt;',
      '#suffix' =&gt; '&lt;/div&gt;',
    ];

    unset($element['#options']['_none']);
    return ['value' =&gt; $element];
  }

  /**
    * @inheritdoc
    */
  public static function validate($element, FormStateInterface $form_state) {

    $value = $element['#value'];
    return true;
  }


For the moment, I just want it to pass validation so then I can work on from there, but right now, it can't seem to retrieve a value, even though I can see it has the expected values in the $form_state object (field_programme_areas field).



Any help and tips would be greatly appreciated.
Thanks!
I managed to get it working by extending the OptionsButtonsWidget class instead of OptionsWidgetBase. I've also added the multiple_values annotation which I was missing and also removed the validation callback I was supplying, so now the validateElement method from OptionsWidgetBase is the validation handler used. My widget class just extends OptionsButtonsWidget and works fine. I think the missing annotation was the main reason it wouldn't validate.