You are here

protected function AssetGroupItemList::computeValue in farmOS 2.x

Computes the current group value for the asset.

Overrides ComputedItemListTrait::computeValue

File

modules/asset/group/src/Field/AssetGroupItemList.php, line 18

Class

AssetGroupItemList
Computes the current group value for assets.

Namespace

Drupal\farm_group\Field

Code

protected function computeValue() {

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

  // Get the asset's current groups.
  $groups = \Drupal::service('group.membership')
    ->getGroup($entity);

  // Update the assets current group values to match.
  // @todo Cache this field computation.
  foreach ($groups as $delta => $group) {
    if (!empty($group
      ->id())) {
      $value = [
        'target_id' => $group
          ->id(),
      ];
      $this->list[$delta] = $this
        ->createItem($delta, $value);
    }
  }
}