JSONFieldEnhancer.php in JSON:API Extras 8.3
File
src/Plugin/jsonapi/FieldEnhancer/JSONFieldEnhancer.php
View source
<?php
namespace Drupal\jsonapi_extras\Plugin\jsonapi\FieldEnhancer;
use Drupal\Component\Serialization\Json;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\jsonapi_extras\Plugin\ResourceFieldEnhancerBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Shaper\Util\Context;
class JSONFieldEnhancer extends ResourceFieldEnhancerBase implements ContainerFactoryPluginInterface {
protected $encoder;
public function __construct(array $configuration, string $plugin_id, $plugin_definition, Json $encoder) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->encoder = $encoder;
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('serialization.json'));
}
public function defaultConfiguration() {
return [];
}
public function doUndoTransform($data, Context $context) {
return $this->encoder
->decode($data);
}
protected function doTransform($data, Context $context) {
return $this->encoder
->encode($data);
}
public function getOutputJsonSchema() {
return [
'oneOf' => [
[
'type' => 'object',
],
[
'type' => 'array',
],
[
'type' => 'null',
],
],
];
}
public function getSettingsForm(array $resource_field_info) {
return [];
}
}