public function PriceListItemForm::setFormDisplay in Commerce Pricelist 8.2
Sets the form display.
Sets the form display which will be used for populating form element defaults.
Parameters
\Drupal\Core\Entity\Display\EntityFormDisplayInterface $form_display: The form display that the current form operates with.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
$this
Overrides ContentEntityForm::setFormDisplay
File
- src/
Form/ PriceListItemForm.php, line 69
Class
Namespace
Drupal\commerce_pricelist\FormCode
public function setFormDisplay(EntityFormDisplayInterface $form_display, FormStateInterface $form_state) {
/** @var \Drupal\commerce_pricelist\Entity\PriceListItemInterface $price_list_item */
$price_list_item = $this->entity;
// When adding a price from the variation add price route, the price list
// item is new, the product variation is already known but the price list
// isn't, so we need to expose the price list field but remove the
// "purchasable_entity" one.
if ($price_list_item
->isNew() && is_null($price_list_item
->getPriceListId()) && $price_list_item
->getPurchasableEntityId()) {
$form_display
->setComponent('price_list_id', [
'type' => 'entity_reference_autocomplete',
'weight' => -10,
'settings' => [
'match_operator' => 'CONTAINS',
'size' => '60',
'placeholder' => '',
],
]);
$form_display
->removeComponent('purchasable_entity');
}
$form_state
->set('form_display', $form_display);
return $this;
}