You are here

class TypedDataPrimitiveFallback in GraphQL 8.3

Hierarchy

Expanded class hierarchy of TypedDataPrimitiveFallback

File

modules/graphql_core/src/Plugin/Deriver/Scalars/TypedDataPrimitiveFallback.php, line 12

Namespace

Drupal\graphql_core\Plugin\Deriver\Scalars
View source
class TypedDataPrimitiveFallback extends DeriverBase implements ContainerDeriverInterface {
  use StringTranslationTrait;

  /**
   * The typed data manager.
   *
   * @var \Drupal\Core\TypedData\TypedDataManagerInterface
   */
  protected $typedDataManager;

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, $basePluginId) {
    return new static($container
      ->get('typed_data_manager'));
  }

  /**
   * TypedDataPrimitiveFallback constructor.
   *
   * @param \Drupal\Core\TypedData\TypedDataManagerInterface $typedDataManager
   *   The typed data manager.
   */
  public function __construct(TypedDataManagerInterface $typedDataManager) {
    $this->typedDataManager = $typedDataManager;
  }

  /**
   * {@inheritdoc}
   */
  public function getDerivativeDefinitions($basePluginDefinition) {

    // Add a derivative for the actual "any" type.
    $this->derivatives['any'] = $basePluginDefinition;
    foreach ($this->typedDataManager
      ->getDefinitions() as $typeName => $typeDefinition) {
      if (in_array('Drupal\\Core\\TypedData\\PrimitiveInterface', class_implements($typeDefinition['class']))) {
        $this->derivatives[$typeName] = [
          'name' => StringHelper::camelCase($typeName),
          'description' => !empty($typeDefinition['description']) ? $typeDefinition['description'] : '',
          'provider' => isset($typeDefinition['provider']) ? $typeDefinition['provider'] : null,
          'weight' => -10,
          'type' => $typeName,
        ] + $basePluginDefinition;
      }
    }
    return parent::getDerivativeDefinitions($basePluginDefinition);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DeriverBase::$derivatives protected property List of derivative definitions. 1
DeriverBase::getDerivativeDefinition public function Gets the definition of a derivative plugin. Overrides DeriverInterface::getDerivativeDefinition
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.
TypedDataPrimitiveFallback::$typedDataManager protected property The typed data manager.
TypedDataPrimitiveFallback::create public static function Creates a new class instance. Overrides ContainerDeriverInterface::create
TypedDataPrimitiveFallback::getDerivativeDefinitions public function Gets the definition of all derivatives of a base plugin. Overrides DeriverBase::getDerivativeDefinitions
TypedDataPrimitiveFallback::__construct public function TypedDataPrimitiveFallback constructor.