diff --git a/src/Form/PriceListItemInlineForm.php b/src/Form/PriceListItemInlineForm.php index 05bcfb8..fe07ae5 100644 --- a/src/Form/PriceListItemInlineForm.php +++ b/src/Form/PriceListItemInlineForm.php @@ -52,6 +52,12 @@ class PriceListItemInlineForm extends EntityInlineForm { 'weight' => 4, ]; + $routeName = \Drupal::routeMatch()->getRouteName(); + switch ($routeName) { + case 'entity.price_list.add_page':unset($fields['price_list_id']);break; + case 'entity.price_list.edit_form':unset($fields['price_list_id']);break; + } + return $fields; } @@ -101,11 +107,12 @@ class PriceListItemInlineForm extends EntityInlineForm { if ($inline_entity_form) $target_id = $inline_entity_form['purchased_entity'][0]['target_id']; } if ($target_id) { - $entity_storage = \Drupal::entityManager()->getStorage($target_type); - $purchased_entity = $entity_storage->load($target_id); + $purchased_entity = $this->entityTypeManager->getStorage($target_type)->load($target_id); $price = $purchased_entity->getPrice(); if (!$price) { $entity_form['price']['#disabled'] = true; + } else { + $entity_form['price']['#default_value'] = $price->toArray(); } } return $entity_form; @@ -127,6 +134,9 @@ class PriceListItemInlineForm extends EntityInlineForm { $element = NestedArray::getValue($form, $array_parents); array_pop($array_parents); } + if ($number = $element['price']['#default_value']['number']) { + $element['price']['widget'][0]['number']['#value'] = sprintf("%.2f", $number); + } return $element['price']; }