You are here

public function MerciLineItemInlineForm::entityForm in MERCI (Manage Equipment Reservations, Checkout and Inventory) 8.2

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

modules/merci_line_item/src/Form/MerciLineItemInlineForm.php, line 57

Class

MerciLineItemInlineForm
Node inline form handler.

Namespace

Drupal\merci_line_item\Form

Code

public function entityForm(array $entity_form, FormStateInterface $form_state) {
  if ($entity_form['#op'] == 'add') {

    // Set default date to first entity.
    $entities = $form_state
      ->get([
      'inline_entity_form',
      $entity_form['#ief_id'],
      'entities',
    ]);
    if (count($entities)) {
      $entity = reset($entities);
      $entity_form['#entity']->merci_reservation_date = $entity['entity']->merci_reservation_date;
    }
  }
  else {
    $entity_form['#form_mode'] = 'default';
  }
  $entity_form = parent::entityForm($entity_form, $form_state);

  // Remove the "Revision log" textarea,  it can't be disabled in the
  // form display and doesn't make sense in the inline form context.
  $entity_form['revision_log_message']['#access'] = FALSE;
  return $entity_form;
}