You are here

class BundleItemOrderItemInlineForm in Commerce Product Bundle 8

Defines the inline form for order items.

Hierarchy

Expanded class hierarchy of BundleItemOrderItemInlineForm

File

src/Form/BundleItemOrderItemInlineForm.php, line 12

Namespace

Drupal\commerce_product_bundle\Form
View source
class BundleItemOrderItemInlineForm extends EntityInlineForm {

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

  /**
   * {@inheritdoc}
   */
  public function getTableFields($bundles) {
    $fields = parent::getTableFields($bundles);
    $fields['purchased_entity'] = [
      'type' => 'field',
      'label' => t('Purchased Entity'),
      'weight' => 2,
    ];
    $fields['unit_price'] = [
      'type' => 'field',
      'label' => t('Unit price'),
      'weight' => 2,
    ];
    $fields['quantity'] = [
      'type' => 'field',
      'label' => t('Quantity'),
      'weight' => 3,
    ];
    return $fields;
  }

  /**
   * {@inheritdoc}
   */
  public function entityForm(array $entity_form, FormStateInterface $form_state) {
    $entity_form = parent::entityForm($entity_form, $form_state);
    $entity_form['#entity_builders'][] = [
      get_class($this),
      'populateTitle',
    ];
    return $entity_form;
  }

  /**
   * Entity builder: populates the bundle item order item title from the bundle item.
   *
   * @param string $entity_type
   *   The entity type identifier.
   * @param \Drupal\commerce_product_bundle\Entity\BundleItemOrderItemInterface $order_item
   *   The order item.
   * @param array $form
   *   The complete form array.
   * @param \Drupal\Core\Form\FormStateInterface $form_state
   *   The current state of the form.
   */
  public static function populateTitle($entity_type, BundleItemOrderItemInterface $order_item, array $form, FormStateInterface $form_state) {

    /** @var \Drupal\commerce_product_bundle\Entity\BundleItemInterface $bundle_item */
    $bundle_item = $order_item
      ->getBundleItem();
    $bundle_item
      ->setCurrentVariation($order_item
      ->getPurchasedEntity());
    if ($order_item
      ->isNew()) {
      $order_item
        ->setTitle($bundle_item
        ->getTitle());
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
BundleItemOrderItemInlineForm::entityForm public function Builds the entity form. Overrides EntityInlineForm::entityForm
BundleItemOrderItemInlineForm::getEntityTypeLabels public function Gets the entity type labels (singular, plural). Overrides EntityInlineForm::getEntityTypeLabels
BundleItemOrderItemInlineForm::getTableFields public function Gets the columns used to represent an entity in the IEF table. Overrides EntityInlineForm::getTableFields
BundleItemOrderItemInlineForm::populateTitle public static function Entity builder: populates the bundle item order item title from the bundle item.
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.
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.