You are here

abstract class InputTypePluginBase in GraphQL 8.3

Hierarchy

Expanded class hierarchy of InputTypePluginBase

5 files declare their use of InputTypePluginBase
CarInput.php in tests/modules/graphql_plugin_test/src/Plugin/GraphQL/InputTypes/CarInput.php
EntityQueryFilterConditionInput.php in modules/graphql_core/src/Plugin/GraphQL/InputTypes/EntityQuery/EntityQueryFilterConditionInput.php
EntityQueryFilterInput.php in modules/graphql_core/src/Plugin/GraphQL/InputTypes/EntityQuery/EntityQueryFilterInput.php
EntityQuerySortInput.php in modules/graphql_core/src/Plugin/GraphQL/InputTypes/EntityQuery/EntityQuerySortInput.php
MockGraphQLPluginTrait.php in tests/src/Traits/MockGraphQLPluginTrait.php
1 string reference to 'InputTypePluginBase'
graphql.services.yml in ./graphql.services.yml
graphql.services.yml

File

src/Plugin/GraphQL/InputTypes/InputTypePluginBase.php, line 15

Namespace

Drupal\graphql\Plugin\GraphQL\InputTypes
View source
abstract class InputTypePluginBase extends PluginBase implements TypePluginInterface {
  use CacheablePluginTrait;
  use DescribablePluginTrait;
  use TypedPluginTrait;

  /**
   * {@inheritdoc}
   */
  public static function createInstance(SchemaBuilderInterface $builder, TypePluginManager $manager, $definition, $id) {
    return new InputObjectType([
      'name' => $definition['name'],
      'description' => $definition['description'],
      'contexts' => $definition['contexts'],
      'fields' => function () use ($builder, $definition) {
        return $builder
          ->processArguments($definition['fields']);
      },
    ]);
  }

  /**
   * {@inheritdoc}
   */
  public function getDefinition() {
    $definition = $this
      ->getPluginDefinition();
    return [
      'name' => $definition['name'],
      'description' => $this
        ->buildDescription($definition),
      'fields' => $this
        ->buildFields($definition),
      'contexts' => $this
        ->buildCacheContexts($definition),
    ];
  }

  /**
   * Builds the fields of the type definition.
   *
   * @param $definition
   *   The plugin definition array.
   *
   * @return array
   *   The list of fields for the input type.
   */
  protected function buildFields($definition) {
    return array_map(function ($field) use ($definition) {
      return [
        'type' => $this
          ->buildFieldType($field, $definition),
        'description' => $this
          ->buildFieldDescription($field, $definition),
        'default' => $this
          ->buildFieldDefault($field, $definition),
      ];
    }, $definition['fields']);
  }

  /**
   * Builds a field's type.
   *
   * @param array $field
   *   The field definition array.
   *
   * @return array
   *   The parsed type definition array.
   */
  protected function buildFieldType($field) {
    $type = is_array($field) ? $field['type'] : $field;
    return StringHelper::parseType($type);
  }

  /**
   * Builds a field's description.
   *
   * @param array $field
   *   The field definition array.
   * @param array $definition
   *   The plugin definition array.
   *
   * @return string
   *   The field's description.
   */
  protected function buildFieldDescription($field, $definition) {
    return (string) (isset($field['description']) ? $field['description'] : '');
  }

  /**
   * Builds a field's default value.
   *
   * @param array $field
   *   The field definition array.
   * @param array $definition
   *   The plugin definition array.
   *
   * @return mixed
   *   The field's default value.
   */
  protected function buildFieldDefault($field, $definition) {
    return isset($field['default']) ? $field['default'] : NULL;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CacheablePluginTrait::buildCacheContexts protected function
DescribablePluginTrait::buildDescription protected function
InputTypePluginBase::buildFieldDefault protected function Builds a field's default value.
InputTypePluginBase::buildFieldDescription protected function Builds a field's description.
InputTypePluginBase::buildFields protected function Builds the fields of the type definition.
InputTypePluginBase::buildFieldType protected function Builds a field's type.
InputTypePluginBase::createInstance public static function Overrides TypePluginInterface::createInstance
InputTypePluginBase::getDefinition public function Returns the plugin's type or field definition for the schema. Overrides TypePluginInterface::getDefinition
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
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.
PluginBase::__construct public function Constructs a \Drupal\Component\Plugin\PluginBase object. 92
TypedPluginTrait::buildType protected function