Implements \Drupal\Core\Entity\EntityFormControllerInterface::buildEntity().
Overrides EntityFormController::buildEntity
public function buildEntity(array $form, array &$form_state) {
// Change the roles array to a list of enabled roles.
// @todo: Alter the form state as the form values are directly extracted and
// set on the field, which throws an exception as the list requires
// numeric keys. Allow to override this per field. As this function is
// called twice, we have to prevent it from getting the array keys twice.
if (empty($this->roles_filtered)) {
$form_state['values']['roles'] = array_keys(array_filter($form_state['values']['roles']));
$this->roles_filtered = TRUE;
}
return parent::buildEntity($form, $form_state);
}