You are here

ComputedDefaultVariation.php in Commerce Core 8.2

File

modules/product/src/Plugin/Field/ComputedDefaultVariation.php
View source
<?php

namespace Drupal\commerce_product\Plugin\Field;

use Drupal\commerce_product\Entity\ProductInterface;
use Drupal\Core\Field\EntityReferenceFieldItemList;
use Drupal\Core\TypedData\ComputedItemListTrait;

/**
 * Computed field item list for the default_variation field.
 */
class ComputedDefaultVariation extends EntityReferenceFieldItemList {
  use ComputedItemListTrait;

  /**
   * {@inheritdoc}
   */
  protected function computeValue() {
    $product = $this
      ->getEntity();
    assert($product instanceof ProductInterface);
    $this->list[0] = $this
      ->createItem(0, $product
      ->getDefaultVariation());
  }

}

Classes

Namesort descending Description
ComputedDefaultVariation Computed field item list for the default_variation field.