32fd267dfbaae1846dbbbb6c7c8dca2a2475e21f
[yaffs-website] / web / modules / contrib / diff / tests / modules / diff_test / src / Plugin / diff / Field / TestLighterTextPlugin.php
1 <?php
2
3 namespace Drupal\diff_test\Plugin\diff\Field;
4
5 use Drupal\Core\Field\FieldStorageDefinitionInterface;
6 use Drupal\diff\FieldDiffBuilderBase;
7 use Drupal\Core\Field\FieldItemListInterface;
8
9 /**
10  * Test diff builder with light weight.
11  *
12  * @FieldDiffBuilder(
13  *   id = "test_lighter_text_plugin",
14  *   label = @Translation("Test Lighter Text Plugin"),
15  *   field_types = {
16  *     "text",
17  *   },
18  *   weight = -20,
19  * )
20  */
21 class TestLighterTextPlugin extends FieldDiffBuilderBase {
22
23   /**
24    * {@inheritdoc}
25    */
26   public function build(FieldItemListInterface $field_items) {
27     $result = [];
28
29     // Every item from $field_items is of type FieldItemInterface.
30     foreach ($field_items as $field_key => $field_item) {
31       if (!$field_item->isEmpty()) {
32         $values = $field_item->getValue();
33         if (isset($values['value'])) {
34           $result[$field_key][] = str_replace('applicable', 'lighter_test_plugin', $values['value']);
35         }
36       }
37     }
38     return $result;
39   }
40
41   /**
42    * {@inheritdoc}
43    */
44   public static function isApplicable(FieldStorageDefinitionInterface $field_definition) {
45     return ($field_definition->getName() == 'test_field_lighter');
46   }
47
48 }