You are here

AssetGeometryItemList.php in farmOS 2.x

File

modules/core/location/src/Field/AssetGeometryItemList.php
View source
<?php

namespace Drupal\farm_location\Field;

use Drupal\Core\Field\FieldItemList;
use Drupal\Core\TypedData\ComputedItemListTrait;

/**
 * Computes the current geometry value for assets.
 */
class AssetGeometryItemList extends FieldItemList {
  use ComputedItemListTrait;

  /**
   * Computes the current geometry value for the asset.
   */
  protected function computeValue() {

    // Get the asset entity.
    $entity = $this
      ->getEntity();

    // Get the asset geometry.
    $geometry = \Drupal::service('asset.location')
      ->getGeometry($entity);

    // Update the assets current geometry value to match.
    // @todo Cache this field computation.
    $this->list[0] = $this
      ->createItem(0, $geometry);
  }

}

Classes

Namesort descending Description
AssetGeometryItemList Computes the current geometry value for assets.