|
@@ -8,6 +8,10 @@ use Drupal\graphql\GraphQL\Response\ResponseInterface;
|
|
use Drupal\graphql\Plugin\GraphQL\SchemaExtension\SdlSchemaExtensionPluginBase;
|
|
use Drupal\graphql\Plugin\GraphQL\SchemaExtension\SdlSchemaExtensionPluginBase;
|
|
use Drupal\materio_graphql\GraphQL\Response\MaterioResponse;
|
|
use Drupal\materio_graphql\GraphQL\Response\MaterioResponse;
|
|
use Drupal\Core\Url;
|
|
use Drupal\Core\Url;
|
|
|
|
+// use CommerceGuys\Addressing\Country\CountryRepository;
|
|
|
|
+use Symfony\Component\DependencyInjection\ContainerInterface;
|
|
|
|
+use Drupal\Core\Extension\ModuleHandlerInterface;
|
|
|
|
+use CommerceGuys\Addressing\Country\CountryRepositoryInterface;
|
|
|
|
|
|
use GraphQL\Error\Error;
|
|
use GraphQL\Error\Error;
|
|
|
|
|
|
@@ -21,6 +25,36 @@ use GraphQL\Error\Error;
|
|
*/
|
|
*/
|
|
class MaterioSchemaExtension extends SdlSchemaExtensionPluginBase {
|
|
class MaterioSchemaExtension extends SdlSchemaExtensionPluginBase {
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * The country repository.
|
|
|
|
+ *
|
|
|
|
+ * @var \CommerceGuys\Addressing\Country\CountryRepositoryInterface
|
|
|
|
+ */
|
|
|
|
+ protected $countryRepository;
|
|
|
|
+
|
|
|
|
+ public function __construct( array $configuration, $pluginId, array $pluginDefinition, ModuleHandlerInterface $moduleHandler, CountryRepositoryInterface $country_repository) {
|
|
|
|
+ parent::__construct($configuration, $pluginId, $pluginDefinition, $moduleHandler);
|
|
|
|
+ $this->countryRepository = $country_repository;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * {@inheritdoc}
|
|
|
|
+ *
|
|
|
|
+ * @codeCoverageIgnore
|
|
|
|
+ */
|
|
|
|
+ public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
|
|
|
|
+ return new static(
|
|
|
|
+ $configuration,
|
|
|
|
+ $plugin_id,
|
|
|
|
+ $plugin_definition,
|
|
|
|
+ $container->get('module_handler'),
|
|
|
|
+ $container->get('address.country_repository')
|
|
|
|
+ );
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* {@inheritdoc}
|
|
* {@inheritdoc}
|
|
*/
|
|
*/
|
|
@@ -51,6 +85,8 @@ class MaterioSchemaExtension extends SdlSchemaExtensionPluginBase {
|
|
|
|
|
|
$this->addAddress($registry, $builder);
|
|
$this->addAddress($registry, $builder);
|
|
|
|
|
|
|
|
+ $this->addCountry($registry, $builder);
|
|
|
|
+
|
|
$this->addFilefield($registry, $builder);
|
|
$this->addFilefield($registry, $builder);
|
|
|
|
|
|
$this->addFile($registry, $builder);
|
|
$this->addFile($registry, $builder);
|
|
@@ -1180,6 +1216,30 @@ class MaterioSchemaExtension extends SdlSchemaExtensionPluginBase {
|
|
);
|
|
);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// ____ _
|
|
|
|
+// / ___|___ _ _ _ __ | |_ _ __ _ _
|
|
|
|
+// | | / _ \| | | | '_ \| __| '__| | | |
|
|
|
|
+// | |__| (_) | |_| | | | | |_| | | |_| |
|
|
|
|
+// \____\___/ \__,_|_| |_|\__|_| \__, |
|
|
|
|
+// |___/
|
|
|
|
+ protected function addCountry(ResolverRegistryInterface $registry, ResolverBuilder $builder) {
|
|
|
|
+ $registry->addFieldResolver('Country', 'country_code',
|
|
|
|
+ $builder->callback(function ($parent, $args) {
|
|
|
|
+ return $parent[0]['country_code'];
|
|
|
|
+ })
|
|
|
|
+ );
|
|
|
|
+
|
|
|
|
+ $registry->addFieldResolver('Country', 'country_name',
|
|
|
|
+ $builder->callback(function ($parent, $args) {
|
|
|
|
+ $cc = $parent[0]['country_code'];
|
|
|
|
+ $countries = $this->countryRepository->getList();
|
|
|
|
+ $cn = isset($countries[$cc]) ? $countries[$cc] : $cc;
|
|
|
|
+ return $cn;
|
|
|
|
+ })
|
|
|
|
+ );
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
// ___
|
|
// ___
|
|
// / __|___ _ __ _ __ __ _ _ _ _ _
|
|
// / __|___ _ __ _ __ __ _ _ _ _ _
|
|
// | (__/ _ \ ' \| '_ \/ _` | ' \ || |
|
|
// | (__/ _ \ ' \| '_ \/ _` | ' \ || |
|
|
@@ -1280,6 +1340,13 @@ class MaterioSchemaExtension extends SdlSchemaExtensionPluginBase {
|
|
->map('path', $builder->fromValue('field_public_address'))
|
|
->map('path', $builder->fromValue('field_public_address'))
|
|
);
|
|
);
|
|
|
|
|
|
|
|
+ $registry->addFieldResolver('Company', 'country',
|
|
|
|
+ $builder->produce('property_path')
|
|
|
|
+ ->map('type', $builder->fromValue('entity:taxonomy_term'))
|
|
|
|
+ ->map('value', $builder->fromParent())
|
|
|
|
+ ->map('path', $builder->fromValue('field_public_address'))
|
|
|
|
+ );
|
|
|
|
+
|
|
$registry->addFieldResolver('Company', 'phone',
|
|
$registry->addFieldResolver('Company', 'phone',
|
|
$builder->produce('property_path')
|
|
$builder->produce('property_path')
|
|
->map('type', $builder->fromValue('entity:taxonomy_term'))
|
|
->map('type', $builder->fromValue('entity:taxonomy_term'))
|