You are here

public function GeofieldFieldBuilder::build in Geofield 8

Builds an array of strings.

This method is responsible for transforming a FieldItemListInterface object into an array of strings. The resulted array of strings is then compared by the Diff component with another such array of strings and the result represents the difference between two entity fields.

Example of FieldItemListInterface built into an array of strings:

array(
  0 => "This is an example string",
  1 => "Field values or properties",
);

Parameters

FieldItemListInterface $field_items: Represents an entity field.

Return value

mixed An array of strings to be compared. If an empty array is returned it means that a field is either empty or no properties need to be compared for that field.

Overrides CoreFieldBuilder::build

See also

\Drupal\diff\Plugin\diff\Field\TextFieldBuilder

File

src/Plugin/diff/Field/GeofieldFieldBuilder.php, line 25

Class

GeofieldFieldBuilder
Plugin to compare the latitude and longitude for geofields.

Namespace

Drupal\geofield\Plugin\diff\Field

Code

public function build(FieldItemListInterface $field_items) {
  $result = array();
  foreach ($field_items as $field_key => $field_item) {
    if (!$field_item
      ->isEmpty()) {
      $value = $field_item
        ->view([
        'label' => 'hidden',
        'type' => 'geofield_latlon',
      ]);
      $rendered_value = $this->renderer
        ->renderPlain($value);
      $result[$field_key][] = $rendered_value;
    }
  }
  return $result;
}