custom_field-1.0.x-dev/modules/custom_field_graphql/src/Plugin/GraphQLCompose/FieldType/CustomFieldText.php

modules/custom_field_graphql/src/Plugin/GraphQLCompose/FieldType/CustomFieldText.php
<?php

declare(strict_types=1);

namespace Drupal\custom_field_graphql\Plugin\GraphQLCompose\FieldType;

use Drupal\Core\Field\FieldItemInterface;
use Drupal\graphql\GraphQL\Execution\FieldContext;
use Drupal\graphql_compose\Plugin\GraphQL\DataProducer\FieldProducerItemInterface;
use Drupal\graphql_compose\Plugin\GraphQL\DataProducer\FieldProducerTrait;
use Drupal\graphql_compose\Plugin\GraphQLCompose\GraphQLComposeFieldTypeBase;

/**
 * {@inheritdoc}
 *
 * @GraphQLComposeFieldType(
 *   id = "custom_field_text",
 *   type_sdl = "Text",
 * )
 */
class CustomFieldText extends GraphQLComposeFieldTypeBase implements FieldProducerItemInterface {

  use FieldProducerTrait;

  /**
   * {@inheritdoc}
   */
  public function resolveFieldItem(FieldItemInterface $item, FieldContext $context) {
    $property = (string) $context->getContextValue('property_name');
    $settings = $context->getContextValue('settings');
    $format = $settings['default_format'] ?? filter_fallback_format();
    $processed = check_markup($item->{$property}, $format);
    return [
      'format' => $format,
      'value' => $item->{$property},
      'processed' => $processed,
    ];
  }

}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc