You are here

class MerciLineItemInlineForm in MERCI (Manage Equipment Reservations, Checkout and Inventory) 8.2

Node inline form handler.

Hierarchy

Expanded class hierarchy of MerciLineItemInlineForm

File

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

Namespace

Drupal\merci_line_item\Form
View source
class MerciLineItemInlineForm extends EntityInlineForm {
  use StringTranslationTrait;

  /**
   * {@inheritdoc}
   */
  public function getEntityTypeLabels() {
    $labels = [
      'singular' => $this
        ->t('item'),
      'plural' => $this
        ->t('items'),
    ];
    return $labels;
  }

  /**
   * {@inheritdoc}
   */
  public function getTableFields($bundles) {
    $display = entity_get_display('merci_line_item', 'merci_reservation', 'inline_entity_form');
    $fields = [];
    $bundle = reset($bundles);
    $definitions = $this->entityFieldManager
      ->getFieldDefinitions($this->entityType
      ->id(), $bundle);
    if ($display) {
      foreach ($display
        ->getComponents() as $name => $component) {
        if (array_key_exists($name, $definitions) and $field_config = $definitions[$name]) {
          $label = $definitions[$name]
            ->getLabel();
          $fields[$name] = [
            'type' => 'field',
            'label' => $label,
            'weight' => $component['weight'],
          ];
        }
      }
    }
    else {
      return parent::getTableFields($bundles);
    }
    return $fields;
  }

  /**
   * {@inheritdoc}
   */
  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;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
EntityInlineForm::$entityFieldManager protected property The entity field manager.
EntityInlineForm::$entityType protected property The entity type managed by this handler.
EntityInlineForm::$entityTypeManager protected property The entity type manager.
EntityInlineForm::$moduleHandler protected property Module handler service.
EntityInlineForm::buildEntity protected function Builds an updated entity object based upon the submitted form values.
EntityInlineForm::createInstance public static function Instantiates a new instance of this entity handler. Overrides EntityHandlerInterface::createInstance
EntityInlineForm::delete public function Delete permanently saved entities. Overrides InlineFormInterface::delete
EntityInlineForm::entityFormSubmit public function Handles the submission of an entity form. Overrides InlineFormInterface::entityFormSubmit
EntityInlineForm::entityFormValidate public function Validates the entity form. Overrides InlineFormInterface::entityFormValidate
EntityInlineForm::getEntityLabel public function Gets the label of the given entity. Overrides InlineFormInterface::getEntityLabel
EntityInlineForm::getEntityType public function Gets the entity type managed by this handler. Overrides InlineFormInterface::getEntityType
EntityInlineForm::getFormDisplay protected function Gets the form display for the given entity.
EntityInlineForm::isTableDragEnabled public function Checks whether tabledrag should be enabled for the given table. Overrides InlineFormInterface::isTableDragEnabled
EntityInlineForm::save public function Saves the given entity. Overrides InlineFormInterface::save
EntityInlineForm::submitCleanFormState public static function Cleans up the form state for a submitted entity form.
EntityInlineForm::__construct public function Constructs the inline entity form controller.
MerciLineItemInlineForm::entityForm public function Builds the entity form. Overrides EntityInlineForm::entityForm
MerciLineItemInlineForm::getEntityTypeLabels public function Gets the entity type labels (singular, plural). Overrides EntityInlineForm::getEntityTypeLabels
MerciLineItemInlineForm::getTableFields public function Gets the columns used to represent an entity in the IEF table. Overrides EntityInlineForm::getTableFields
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.