You are here

class JSONFieldEnhancer in JSON:API Extras 8.3

Same name and namespace in other branches
  1. 8.2 src/Plugin/jsonapi/FieldEnhancer/JSONFieldEnhancer.php \Drupal\jsonapi_extras\Plugin\jsonapi\FieldEnhancer\JSONFieldEnhancer

Perform additional manipulations to JSON fields.

Plugin annotation


@ResourceFieldEnhancer(
  id = "json",
  label = @Translation("JSON Field"),
  description = @Translation("Render JSON Field has real json")
)

Hierarchy

Expanded class hierarchy of JSONFieldEnhancer

File

src/Plugin/jsonapi/FieldEnhancer/JSONFieldEnhancer.php, line 20

Namespace

Drupal\jsonapi_extras\Plugin\jsonapi\FieldEnhancer
View source
class JSONFieldEnhancer extends ResourceFieldEnhancerBase implements ContainerFactoryPluginInterface {

  /**
   * The serialization json.
   *
   * @var Drupal\Component\serialization\Json
   */
  protected $encoder;

  /**
   * Constructs a new JSONFieldEnhancer.
   *
   * @param array $configuration
   *   A configuration array containing information about the plugin instance.
   * @param string $plugin_id
   *   The plugin_id for the plugin instance.
   * @param mixed $plugin_definition
   *   The plugin implementation definition.
   * @param \Drupal\Component\Serialization\Json $encoder
   *   The serialization json.
   */
  public function __construct(array $configuration, string $plugin_id, $plugin_definition, Json $encoder) {
    parent::__construct($configuration, $plugin_id, $plugin_definition);
    $this->encoder = $encoder;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
    return new static($configuration, $plugin_id, $plugin_definition, $container
      ->get('serialization.json'));
  }

  /**
   * {@inheritdoc}
   */
  public function defaultConfiguration() {
    return [];
  }

  /**
   * {@inheritdoc}
   */
  public function doUndoTransform($data, Context $context) {
    return $this->encoder
      ->decode($data);
  }

  /**
   * {@inheritdoc}
   */
  protected function doTransform($data, Context $context) {
    return $this->encoder
      ->encode($data);
  }

  /**
   * {@inheritdoc}
   */
  public function getOutputJsonSchema() {
    return [
      'oneOf' => [
        [
          'type' => 'object',
        ],
        [
          'type' => 'array',
        ],
        [
          'type' => 'null',
        ],
      ],
    ];
  }

  /**
   * {@inheritdoc}
   */
  public function getSettingsForm(array $resource_field_info) {
    return [];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function 1
DependencySerializationTrait::__wakeup public function 2
JSONFieldEnhancer::$encoder protected property The serialization json.
JSONFieldEnhancer::create public static function Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface::create
JSONFieldEnhancer::defaultConfiguration public function Overrides ResourceFieldEnhancerBase::defaultConfiguration
JSONFieldEnhancer::doTransform protected function
JSONFieldEnhancer::doUndoTransform public function
JSONFieldEnhancer::getOutputJsonSchema public function Get the JSON Schema for the new output. Overrides ResourceFieldEnhancerInterface::getOutputJsonSchema
JSONFieldEnhancer::getSettingsForm public function Get a form element to render the settings. Overrides ResourceFieldEnhancerBase::getSettingsForm
JSONFieldEnhancer::__construct public function Constructs a new JSONFieldEnhancer. Overrides PluginBase::__construct
MessengerTrait::$messenger protected property The messenger. 29
MessengerTrait::messenger public function Gets the messenger. 29
MessengerTrait::setMessenger public function Sets the messenger.
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin_id.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 3
PluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable public function Determines if the plugin is configurable.
ResourceFieldEnhancerBase::$configuration protected property Holds the plugin configuration. Overrides PluginBase::$configuration
ResourceFieldEnhancerBase::calculateDependencies public function
ResourceFieldEnhancerBase::getConfiguration public function
ResourceFieldEnhancerBase::getInputValidator public function
ResourceFieldEnhancerBase::getInternalValidator public function
ResourceFieldEnhancerBase::getOutputValidator public function
ResourceFieldEnhancerBase::setConfiguration public function
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.