class OrderItemInlineForm in Commerce Core 8.2
Defines the inline form for order items.
Hierarchy
- class \Drupal\inline_entity_form\Form\EntityInlineForm implements InlineFormInterface uses StringTranslationTrait
- class \Drupal\commerce_order\Form\OrderItemInlineForm
Expanded class hierarchy of OrderItemInlineForm
File
- modules/
order/ src/ Form/ OrderItemInlineForm.php, line 12
Namespace
Drupal\commerce_order\FormView source
class OrderItemInlineForm extends EntityInlineForm {
/**
* {@inheritdoc}
*/
public function getEntityTypeLabels() {
$labels = [
'singular' => $this
->t('order item'),
'plural' => $this
->t('order items'),
];
return $labels;
}
/**
* {@inheritdoc}
*/
public function getTableFields($bundles) {
$fields = parent::getTableFields($bundles);
$fields['unit_price'] = [
'type' => 'field',
'label' => $this
->t('Unit price'),
'weight' => 2,
];
$fields['quantity'] = [
'type' => 'field',
'label' => $this
->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),
'buildOrderItem',
];
return $entity_form;
}
/**
* Entity builder: populates the order item title from the purchased entity
* and set the reference to the order being edited.
*
* @param string $entity_type
* The entity type identifier.
* @param \Drupal\commerce_order\Entity\OrderItemInterface $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 buildOrderItem($entity_type, OrderItemInterface $order_item, array $form, FormStateInterface $form_state) {
$purchased_entity = $order_item
->getPurchasedEntity();
if ($order_item
->isNew()) {
if ($purchased_entity) {
$order_item
->setTitle($purchased_entity
->getOrderItemTitle());
}
$order_item
->set('order_id', $form_state
->getFormObject()
->getEntity());
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
EntityInlineForm:: |
protected | property | The entity field manager. | |
EntityInlineForm:: |
protected | property | The entity type managed by this handler. | |
EntityInlineForm:: |
protected | property | The entity type manager. | |
EntityInlineForm:: |
protected | property | Module handler service. | |
EntityInlineForm:: |
protected | function | Builds an updated entity object based upon the submitted form values. | |
EntityInlineForm:: |
public static | function |
Instantiates a new instance of this entity handler. Overrides EntityHandlerInterface:: |
|
EntityInlineForm:: |
public | function |
Delete permanently saved entities. Overrides InlineFormInterface:: |
|
EntityInlineForm:: |
public | function |
Handles the submission of an entity form. Overrides InlineFormInterface:: |
|
EntityInlineForm:: |
public | function |
Validates the entity form. Overrides InlineFormInterface:: |
|
EntityInlineForm:: |
public | function |
Gets the label of the given entity. Overrides InlineFormInterface:: |
|
EntityInlineForm:: |
public | function |
Gets the entity type managed by this handler. Overrides InlineFormInterface:: |
|
EntityInlineForm:: |
protected | function | Gets the form display for the given entity. | |
EntityInlineForm:: |
public | function |
Checks whether tabledrag should be enabled for the given table. Overrides InlineFormInterface:: |
|
EntityInlineForm:: |
public | function |
Saves the given entity. Overrides InlineFormInterface:: |
|
EntityInlineForm:: |
public static | function | Cleans up the form state for a submitted entity form. | |
EntityInlineForm:: |
public | function | Constructs the inline entity form controller. | |
OrderItemInlineForm:: |
public static | function | Entity builder: populates the order item title from the purchased entity and set the reference to the order being edited. | |
OrderItemInlineForm:: |
public | function |
Builds the entity form. Overrides EntityInlineForm:: |
|
OrderItemInlineForm:: |
public | function |
Gets the entity type labels (singular, plural). Overrides EntityInlineForm:: |
|
OrderItemInlineForm:: |
public | function |
Gets the columns used to represent an entity in the IEF table. Overrides EntityInlineForm:: |
|
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |