commerceguys/commerce — pull request #32 by joshuataylor (2014-08-11 12:51:10+00:00)
Title: Add Commerce Product SKU validation.

Is it better to do something like (which CommentNameConstraintValidator does):

$commerce_product = \Drupal::entityManager()->getStorage('commerce_product')->loadByProperties(array('sku' => $sku));

Or:

$sku_exists = (bool) \Drupal::entityQuery('commerce_product')
->condition("sku", $sku)
->range(0, 1)
->count()
->execute();

Which UserUniqueValidator uses?

Also, I'm getting a really weird form error:

Notice: Undefined index: in Drupal\Core\Field\WidgetBase->flagErrors() (line 427 of core/lib/Drupal/Core/Field/WidgetBase.php).
Drupal\Core\Field\WidgetBase->flagErrors(Object, Object, Array, Object)
Drupal\entity\Entity\EntityFormDisplay->validateFormValues(Object, Array, Object)
Drupal\Core\Entity\ContentEntityForm->validate(Array, Object)
call_user_func_array(Array, Array)
Drupal\Core\Form\FormValidator->executeValidateHandlers(Array, Object)
Drupal\Core\Form\FormValidator->doValidateForm(Array, Object, 'product_commerce_product_add_form')
Drupal\Core\Form\FormValidator->validateForm('product_commerce_product_add_form', Array, Object)
Drupal\Core\Form\FormBuilder->processForm('product_commerce_product_add_form', Array, Object)
Drupal\Core\Form\FormBuilder->buildForm(Object, Object)
Drupal\Core\Entity\EntityFormBuilder->getForm(Object, 'add')
Drupal\commerce_product\Controller\CommerceProductController->add(Object)
call_user_func_array(Array, Array)
Drupal\Core\Controller\HtmlPageController->getContentResult(Object, '\Drupal\commerce_product\Controller\CommerceProductController::add')
Drupal\Core\Controller\HtmlPageController->content(Object, '\Drupal\commerce_product\Controller\CommerceProductController::add')
call_user_func_array(Array, Array)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1)
Drupal\Core\DrupalKernel->handle(Object)
Notice: Undefined index: in Drupal\Core\Field\WidgetBase->flagErrors() (line 428 of core/lib/Drupal/Core/Field/WidgetBase.php).
Drupal\Core\Field\WidgetBase->flagErrors(Object, Object, Array, Object)
Drupal\entity\Entity\EntityFormDisplay->validateFormValues(Object, Array, Object)
Drupal\Core\Entity\ContentEntityForm->validate(Array, Object)
call_user_func_array(Array, Array)
Drupal\Core\Form\FormValidator->executeValidateHandlers(Array, Object)
Drupal\Core\Form\FormValidator->doValidateForm(Array, Object, 'product_commerce_product_add_form')
Drupal\Core\Form\FormValidator->validateForm('product_commerce_product_add_form', Array, Object)
Drupal\Core\Form\FormBuilder->processForm('product_commerce_product_add_form', Array, Object)
Drupal\Core\Form\FormBuilder->buildForm(Object, Object)
Drupal\Core\Entity\EntityFormBuilder->getForm(Object, 'add')
Drupal\commerce_product\Controller\CommerceProductController->add(Object)
call_user_func_array(Array, Array)
Drupal\Core\Controller\HtmlPageController->getContentResult(Object, '\Drupal\commerce_product\Controller\CommerceProductController::add')
Drupal\Core\Controller\HtmlPageController->content(Object, '\Drupal\commerce_product\Controller\CommerceProductController::add')
call_user_func_array(Array, Array)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1)
Drupal\Core\DrupalKernel->handle(Object)
Recoverable fatal error: Argument 1 passed to Drupal\Core\Field\WidgetBase::errorElement() must be of the type array, null given, called in /home/josh/www/commerce/core/lib/Drupal/Core/Field/WidgetBase.php on line 432 and defined in Drupal\Core\Field\WidgetBase->errorElement() (line 491 of core/lib/Drupal/Core/Field/WidgetBase.php).
Drupal\Core\Field\WidgetBase->errorElement(NULL, Object, Array, Object)
Drupal\Core\Field\WidgetBase->flagErrors(Object, Object, Array, Object)
Drupal\entity\Entity\EntityFormDisplay->validateFormValues(Object, Array, Object)
Drupal\Core\Entity\ContentEntityForm->validate(Array, Object)
call_user_func_array(Array, Array)
Drupal\Core\Form\FormValidator->executeValidateHandlers(Array, Object)
Drupal\Core\Form\FormValidator->doValidateForm(Array, Object, 'product_commerce_product_add_form')
Drupal\Core\Form\FormValidator->validateForm('product_commerce_product_add_form', Array, Object)
Drupal\Core\Form\FormBuilder->processForm('product_commerce_product_add_form', Array, Object)
Drupal\Core\Form\FormBuilder->buildForm(Object, Object)
Drupal\Core\Entity\EntityFormBuilder->getForm(Object, 'add')
Drupal\commerce_product\Controller\CommerceProductController->add(Object)
call_user_func_array(Array, Array)
Drupal\Core\Controller\HtmlPageController->getContentResult(Object, '\Drupal\commerce_product\Controller\CommerceProductController::add')
Drupal\Core\Controller\HtmlPageController->content(Object, '\Drupal\commerce_product\Controller\CommerceProductController::add')
call_user_func_array(Array, Array)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1)
Drupal\Core\DrupalKernel->handle(Object)

In WidgetBase.php:

// Otherwise, pass errors by delta to the corresponding sub-element.
else {
$original_delta = $field_state['original_deltas'][$delta];
$delta_element = $element[$original_delta];
}

Original delta is blank.