/**
  * {@inheritdoc}
  */
 public function entityValidate(\EntityDrupalWrapper $wrapper)
 {
     if (!module_exists('entity_validator')) {
         // Entity validator doesn't exist.
         return;
     }
     try {
         $validator_handler = ValidatorPluginManager::EntityValidator($wrapper->type(), $wrapper->getBundle());
     } catch (PluginNotFoundException $e) {
         // Entity validator handler doesn't exist for the entity.
         return;
     }
     if ($validator_handler->validate($wrapper->value(), TRUE)) {
         // Entity is valid.
         return;
     }
     $errors = $validator_handler->getErrors(FALSE);
     $map = array();
     foreach ($this->fieldDefinitions as $resource_field_name => $resource_field) {
         if (!($property = $resource_field->getProperty())) {
             continue;
         }
         $public_name = $resource_field->getPublicName();
         if (empty($errors[$public_name])) {
             // Field validated.
             continue;
         }
         $map[$public_name] = $resource_field_name;
         $params['@fields'][] = $resource_field_name;
     }
     if (empty($params['@fields'])) {
         // There was a validation error, but on non-public fields, so we need to
         // throw an exception, but can't say on which fields it occurred.
         throw new BadRequestException('Invalid value(s) sent with the request.');
     }
     $params['@fields'] = implode(',', $params['@fields']);
     $exception = new BadRequestException(format_plural(count($map), 'Invalid value in field @fields.', 'Invalid values in fields @fields.', $params));
     foreach ($errors as $property_name => $messages) {
         if (empty($map[$property_name])) {
             // Entity is not valid, but on a field not public.
             continue;
         }
         $resource_field_name = $map[$property_name];
         foreach ($messages as $message) {
             $message['params']['@field'] = $resource_field_name;
             $output = format_string($message['message'], $message['params']);
             $exception->addFieldError($resource_field_name, $output);
         }
     }
     // Throw the exception.
     throw $exception;
 }