Skip to content

Commit

Permalink
Issue #3029423 by drugan: Stop disabling attributes on the add to car…
Browse files Browse the repository at this point in the history
…t form when they only have 1 value
  • Loading branch information
drugan committed Jan 30, 2019
1 parent 30f9838 commit 5b1d870
Showing 1 changed file with 1 addition and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -222,25 +222,9 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen
unset($element['attributes'][$field_name]['#options']['_none']);
}
// 1 required value -> Disable the element to skip unneeded ajax calls.
if ($attribute['required'] && count($attribute['values']) === 1) {
$element['attributes'][$field_name]['#disabled'] = TRUE;
// Support for option values keyed by just one optgroup label which may
// have multiple values.
$count = 1;
foreach ($attribute['values'] as $value) {
$counted = count($value);
if (($counted > 1) || ($count > 1)) {
$element['attributes'][$field_name]['#disabled'] = FALSE;
break;
}
elseif ($counted === 1) {
$count++;
}
}
}
// REMOVED: @see https://www.drupal.org/project/commerce/issues/3020173
// Optimize the UX of optional attributes:
// - Hide attributes that have no values.
// - Require attributes that have a value on each variation.
if (empty($element['attributes'][$field_name]['#options'])) {
$element['attributes'][$field_name]['#access'] = FALSE;
}
Expand Down

0 comments on commit 5b1d870

Please sign in to comment.