class ShipmentInlineForm in Commerce Shipping 8.2
Defines the inline form for shipments.
Hierarchy
- class \Drupal\inline_entity_form\Form\EntityInlineForm implements InlineFormInterface uses StringTranslationTrait
- class \Drupal\commerce_shipping\Form\ShipmentInlineForm
Expanded class hierarchy of ShipmentInlineForm
File
- src/
Form/ ShipmentInlineForm.php, line 15
Namespace
Drupal\commerce_shipping\FormView source
class ShipmentInlineForm extends EntityInlineForm {
/**
* {@inheritdoc}
*/
public function getEntityTypeLabels() {
return [
'singular' => new TranslatableMarkup('shipment'),
'plural' => new TranslatableMarkup('shipments'),
];
}
/**
* {@inheritdoc}
*/
public function entityForm(array $entity_form, FormStateInterface $form_state) {
$shipment = $entity_form['#entity'];
assert($shipment instanceof ShipmentInterface);
if ($shipment
->isNew()) {
$form_object = $form_state
->getFormObject();
assert($form_object instanceof OrderForm);
$order = $form_object
->getEntity();
assert($order instanceof OrderInterface);
$shipment
->set('order_id', $order);
}
$entity_form = parent::entityForm($entity_form, $form_state);
// IEF + InlineForms (CustomerProfile) are not compatible when the IEF form
// is saved/closed. So we disable the "Update" option.
// @todo remove when IEF + InlineForms are compatible.
if (!$shipment
->isNew()) {
$entity_form['#after_build'][] = [
static::class,
'disableSaveButton',
];
}
return $entity_form;
}
/**
* Disables the save button for the IEF element.
*
* @param array $element
* The element.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The form state.
*
* @return array
* The element.
*/
public static function disableSaveButton(array $element, FormStateInterface $form_state) {
$action_button_key = 'ief_' . $element['#op'] . '_save';
if (isset($element['actions'][$action_button_key])) {
$element['actions'][$action_button_key]['#access'] = FALSE;
}
return $element;
}
}
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 |
Gets the columns used to represent an entity in the IEF table. Overrides InlineFormInterface:: |
1 |
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. | |
ShipmentInlineForm:: |
public static | function | Disables the save button for the IEF element. | |
ShipmentInlineForm:: |
public | function |
Builds the entity form. Overrides EntityInlineForm:: |
|
ShipmentInlineForm:: |
public | function |
Gets the entity type labels (singular, plural). 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. |