Browse Source

Added String normalizer

main
astanley 2 years ago
parent
commit
0c1d76aec0
  1. 6
      citation_type_selector.services.yml
  2. 33
      src/Normalizer/StringItemNormalizer.php

6
citation_type_selector.services.yml

@ -3,5 +3,9 @@ services:
class: Drupal\citation_type_selector\Normalizer\FieldItemListNormalizer
arguments: ['@config.factory']
tags:
- { name: normalizer, priority: 100 }
- { name: normalizer, priority: 14 }
serializer.citation_style_selector.string_item:
class: Drupal\citation_type_selector\Normalizer\StringItemNormalizer
tags:
- { name: normalizer, priority: 12 }

33
src/Normalizer/StringItemNormalizer.php

@ -0,0 +1,33 @@
<?php
namespace Drupal\citation_type_selector\Normalizer;
use Drupal\islandora_citations\Normalizer\NormalizerBase;
/**
* Converts StringItem fields to an array including computed values.
*/
class StringItemNormalizer extends NormalizerBase {
/**
* The interface or class that this Normalizer supports.
*
* @var string
*/
protected $supportedInterfaceOrClass = 'Drupal\Core\Field\Plugin\Field\FieldType\StringItemBase';
/**
* {@inheritdoc}
*/
public function normalize($object, $format = NULL, array $context = []) {
$value = NULL;
foreach ($object->getProperties(TRUE) as $field) {
$value = $this->serializer->normalize($field, $format, $context);
if (is_object($value)) {
$value = $this->serializer->normalize($value, $format, $context);
}
}
return strip_tags($value);
}
}
Loading…
Cancel
Save