function TestFieldPrepareViewFormatter::prepareView

Same name in other branches
  1. 8.9.x core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldFormatter/TestFieldPrepareViewFormatter.php \Drupal\field_test\Plugin\Field\FieldFormatter\TestFieldPrepareViewFormatter::prepareView()
  2. 10 core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldFormatter/TestFieldPrepareViewFormatter.php \Drupal\field_test\Plugin\Field\FieldFormatter\TestFieldPrepareViewFormatter::prepareView()
  3. 11.x core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldFormatter/TestFieldPrepareViewFormatter.php \Drupal\field_test\Plugin\Field\FieldFormatter\TestFieldPrepareViewFormatter::prepareView()

Overrides FormatterBase::prepareView

File

core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldFormatter/TestFieldPrepareViewFormatter.php, line 59

Class

TestFieldPrepareViewFormatter
Plugin implementation of the 'field_test_with_prepare_view' formatter.

Namespace

Drupal\field_test\Plugin\Field\FieldFormatter

Code

public function prepareView(array $entities_items) {
    foreach ($entities_items as $items) {
        foreach ($items as $item) {
            // Don't add anything on empty values.
            if (!$item->isEmpty()) {
                $item->additional_formatter_value = $item->value + 1;
            }
        }
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.