You are here

public function ProductVariationInlineForm::getEntityLabel in Commerce Core 8.2

Gets the label of the given entity.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The given entity.

Return value

string The entity label.

Overrides EntityInlineForm::getEntityLabel

File

modules/product/src/Form/ProductVariationInlineForm.php, line 62

Class

ProductVariationInlineForm
Defines the inline form for product variations.

Namespace

Drupal\commerce_product\Form

Code

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;
}