You are here

public function Dimension::calculate in Dimension 2.0.x

Same name and namespace in other branches
  1. 8 src/Plugin/Field/FieldType/Dimension.php \Drupal\dimension\Plugin\Field\FieldType\Dimension::calculate()
  2. 2.1.x src/Plugin/Field/FieldType/Dimension.php \Drupal\dimension\Plugin\Field\FieldType\Dimension::calculate()
1 call to Dimension::calculate()
Dimension::preSave in src/Plugin/Field/FieldType/Dimension.php
Defines custom presave behavior for field values.

File

src/Plugin/Field/FieldType/Dimension.php, line 282

Class

Dimension

Namespace

Drupal\dimension\Plugin\Field\FieldType

Code

public function calculate($values) {
  $value = 1;

  /** @noinspection StaticInvocationViaThisInspection */
  foreach ($this
    ->fields() as $key => $label) {
    $settings = $this
      ->getSetting($key);
    $values[$key] = round($values[$key], $this
      ->getSetting($key . '_scale'));
    $value *= $values[$key] * $settings['factor'];
  }
  return round($value, $this
    ->getSetting('value_scale'));
}