You are here

abstract class InterfacePluginBase in GraphQL 8.3

Hierarchy

Expanded class hierarchy of InterfacePluginBase

10 files declare their use of InterfacePluginBase
Entity.php in modules/graphql_core/src/Plugin/GraphQL/Interfaces/Entity/Entity.php
EntityDescribable.php in modules/graphql_core/src/Plugin/GraphQL/Interfaces/Entity/EntityDescribable.php
EntityOwnable.php in modules/graphql_core/src/Plugin/GraphQL/Interfaces/Entity/EntityOwnable.php
EntityPublishable.php in modules/graphql_core/src/Plugin/GraphQL/Interfaces/Entity/EntityPublishable.php
EntityRevisionable.php in modules/graphql_core/src/Plugin/GraphQL/Interfaces/Entity/EntityRevisionable.php

... See full list

1 string reference to 'InterfacePluginBase'
graphql.services.yml in ./graphql.services.yml
graphql.services.yml

File

src/Plugin/GraphQL/Interfaces/InterfacePluginBase.php, line 14

Namespace

Drupal\graphql\Plugin\GraphQL\Interfaces
View source
abstract class InterfacePluginBase extends PluginBase implements TypePluginInterface {
  use CacheablePluginTrait;
  use DescribablePluginTrait;

  /**
   * {@inheritdoc}
   */
  public static function createInstance(SchemaBuilderInterface $builder, TypePluginManager $manager, $definition, $id) {
    return new InterfaceType([
      'name' => $definition['name'],
      'description' => $definition['description'],
      'contexts' => function () use ($builder, $definition) {
        $types = $builder
          ->getSubTypes($definition['name']);
        return array_reduce($types, function ($carry, $current) use ($builder) {
          $type = $builder
            ->getType($current);
          if (!empty($type->config['contexts'])) {
            $contexts = $type->config['contexts'];
            $contexts = is_callable($contexts) ? $contexts() : $contexts;
            return Cache::mergeContexts($carry, $contexts);
          }
          return $carry;
        }, $definition['contexts']);
      },
      'fields' => function () use ($builder, $definition) {
        $fields = $builder
          ->getFields($definition['name']);
        if (!empty($definition['interfaces'])) {
          $inherited = array_map(function ($name) use ($builder) {
            return $builder
              ->getFields($name);
          }, $definition['interfaces']);
          $inherited = call_user_func_array('array_merge', $inherited);
          return array_merge($inherited, $fields);
        }
        return $fields;
      },
      'resolveType' => function ($value, $context, $info) use ($builder, $definition) {
        return $builder
          ->resolveType($definition['name'], $value, $context, $info);
      },
    ]);
  }

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

  /**
   * Builds the list of interfaces inherited by this interface.
   *
   * @param array $definition
   *   The plugin definition array.
   *
   * @return array
   *   The list of interfaces that this interface inherits from.
   */
  protected function buildInterfaces($definition) {
    return $definition['interfaces'] ?: [];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CacheablePluginTrait::buildCacheContexts protected function
DescribablePluginTrait::buildDescription protected function
InterfacePluginBase::buildInterfaces protected function Builds the list of interfaces inherited by this interface.
InterfacePluginBase::createInstance public static function Overrides TypePluginInterface::createInstance
InterfacePluginBase::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