Skip to content
Snippets Groups Projects
Commit 02b15f19 authored by Guillaume Duveau's avatar Guillaume Duveau Committed by Jonathan Sacksick
Browse files

#3281556 add plugin for Diff

parent 6299c024
No related branches found
No related tags found
1 merge request!8Issue #3281556: Plugin for Diff
<?php
namespace Drupal\state_machine\Plugin\diff\Field;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\diff\Plugin\diff\Field\CoreFieldBuilder;
/**
* Plugin to compare state fields.
*
* @FieldDiffBuilder(
* id = "state_diff_builder",
* label = @Translation("State Field Diff"),
* field_types = {
* "state"
* },
* )
*/
class StateFieldBuilder extends CoreFieldBuilder {
/**
* {@inheritdoc}
*/
public function build(FieldItemListInterface $field_items) {
$result = [];
foreach ($field_items as $field_key => $field_item) {
if (!$field_item->isEmpty()) {
$value = $field_item->view(['label' => 'hidden', 'type' => 'default']);
$rendered_value = $this->renderer->renderPlain($value);
$result[$field_key][] = $rendered_value;
}
}
return $result;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment