Skip to content

Commit

Permalink
Issue #2884849: UsageLimitWidget should not load usage for unsaved en…
Browse files Browse the repository at this point in the history
…tities
  • Loading branch information
bojanz committed Jun 9, 2017
1 parent 2fd5fd7 commit 9897285
Showing 1 changed file with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,16 @@ public static function create(ContainerInterface $container, array $configuratio
*/
public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) {
$value = isset($items[$delta]->value) ? $items[$delta]->value : NULL;
$entity = $items[$delta]->getEntity();
$usage = 0;
if ($entity instanceof PromotionInterface) {
$usage = $this->usage->getUsage($entity);
}
elseif ($entity instanceof CouponInterface) {
$usage = $this->usage->getUsage($entity->getPromotion(), $entity);
/** @var \Drupal\Core\Entity\EntityInterface $entity */
$entity = $items[$delta]->getEntity();
if (!$entity->isNew()) {
if ($entity instanceof PromotionInterface) {
$usage = $this->usage->getUsage($entity);
}
elseif ($entity instanceof CouponInterface) {
$usage = $this->usage->getUsage($entity->getPromotion(), $entity);
}
}
$formatted_usage = $this->formatPlural($usage, '1 use', '@count uses');
$radio_parents = array_merge($form['#parents'], [$this->fieldDefinition->getName(), 0, 'limit']);
Expand Down

0 comments on commit 9897285

Please sign in to comment.