You are here

public function PriceListItemInlineForm::entityForm in Commerce Pricelist 8

Builds the entity form.

Parameters

array $entity_form: The entity form, containing the following basic properties:

  • #entity: The entity for the current entity form.
  • #op: The form operation. 'add' or 'edit'.
  • #form_mode: The form mode used to display the entity form.
  • #parents: Identifies the position of the entity form in the overall parent form, and identifies the location where the field values are placed within $form_state->getValues().

\Drupal\Core\Form\FormStateInterface $form_state: The form state of the parent form.

Overrides EntityInlineForm::entityForm

File

src/Form/PriceListItemInlineForm.php, line 101

Class

PriceListItemInlineForm
Defines the inline form for product variations.

Namespace

Drupal\commerce_pricelist\Form

Code

public function entityForm(array $entity_form, FormStateInterface $form_state) {
  $entity_form = parent::entityForm($entity_form, $form_state);

  // This is for widget entity_auto_complete.
  if (isset($entity_form['purchased_entity']['widget'][0])) {
    $entity_form['purchased_entity']['widget'][0]['target_id']['#ajax'] = [
      'callback' => [
        get_class($this),
        'purchasedRefresh',
      ],
      'event' => 'autocompleteclose',
      'wrapper' => $entity_form['#ief_row_delta'] . 'purchased_entity_refresh',
    ];
  }
  else {
    $entity_form['purchased_entity']['widget']['#ajax'] = [
      'callback' => [
        get_class($this),
        'purchasedRefresh',
      ],
      'wrapper' => $entity_form['#ief_row_delta'] . 'purchased_entity_refresh',
    ];
  }
  $entity_form = $this
    ->priceForm($entity_form, $form_state);
  $entity_form['price']['#attributes']['id'] = $entity_form['#ief_row_delta'] . 'purchased_entity_refresh';
  return $entity_form;
}