class ProductVariationInlineForm in Commerce Core 8.2
Defines the inline form for product variations.
Hierarchy
- class \Drupal\inline_entity_form\Form\EntityInlineForm implements InlineFormInterface uses StringTranslationTrait
- class \Drupal\commerce_product\Form\ProductVariationInlineForm
Expanded class hierarchy of ProductVariationInlineForm
File
- modules/
product/ src/ Form/ ProductVariationInlineForm.php, line 12
Namespace
Drupal\commerce_product\FormView source
class ProductVariationInlineForm extends EntityInlineForm {
/**
* The loaded variation types.
*
* @var \Drupal\commerce_product\Entity\ProductVariationTypeInterface[]
*/
protected $variationTypes;
/**
* {@inheritdoc}
*/
public function getEntityTypeLabels() {
$labels = [
'singular' => $this
->t('variation'),
'plural' => $this
->t('variations'),
];
return $labels;
}
/**
* {@inheritdoc}
*/
public function getTableFields($bundles) {
$fields = parent::getTableFields($bundles);
$fields['label']['label'] = $this
->t('Title');
$fields['price'] = [
'type' => 'field',
'label' => $this
->t('Price'),
'weight' => 10,
];
$fields['status'] = [
'type' => 'field',
'label' => $this
->t('Status'),
'weight' => 100,
'display_options' => [
'settings' => [
'format' => 'custom',
'format_custom_true' => $this
->t('Published'),
'format_custom_false' => $this
->t('Unpublished'),
],
],
];
return $fields;
}
/**
* {@inheritdoc}
*/
public function getEntityLabel(EntityInterface $entity) {
/** @var \Drupal\commerce_product\Entity\ProductVariationInterface $entity */
$variation_type = $this
->loadVariationType($entity
->bundle());
if (!$variation_type
->shouldGenerateTitle()) {
return $entity
->label();
}
// The generated variation title includes the product title, which isn't
// relevant in this context, the user only needs to see the attribute part.
if ($attribute_values = $entity
->getAttributeValues()) {
$attribute_labels = EntityHelper::extractLabels($attribute_values);
$label = implode(', ', $attribute_labels);
}
else {
// @todo Replace the Complex widget with the Simple one when there
// are no attributes, indicating there should only be one variation.
$label = $this
->t('N/A');
}
return $label;
}
/**
* Loads and returns a product variation type with the given ID.
*
* @param string $variation_type_id
* The variation type ID.
*
* @return \Drupal\commerce_product\Entity\ProductVariationTypeInterface
* The loaded product variation type.
*/
protected function loadVariationType($variation_type_id) {
if (!isset($this->variationTypes[$variation_type_id])) {
$storage = $this->entityTypeManager
->getStorage('commerce_product_variation_type');
$this->variationTypes[$variation_type_id] = $storage
->load($variation_type_id);
}
return $this->variationTypes[$variation_type_id];
}
}
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 |
Builds the entity form. 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 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. | |
ProductVariationInlineForm:: |
protected | property | The loaded variation types. | |
ProductVariationInlineForm:: |
public | function |
Gets the label of the given entity. Overrides EntityInlineForm:: |
|
ProductVariationInlineForm:: |
public | function |
Gets the entity type labels (singular, plural). Overrides EntityInlineForm:: |
|
ProductVariationInlineForm:: |
public | function |
Gets the columns used to represent an entity in the IEF table. Overrides EntityInlineForm:: |
|
ProductVariationInlineForm:: |
protected | function | Loads and returns a product variation type with the given ID. | |
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. |