added phone and country to company display

This commit is contained in:
Bachir Soussi Chiadmi 2022-03-07 14:28:04 +01:00
parent 220b558cdf
commit ecf963bb62
6 changed files with 84 additions and 29 deletions

View File

@ -184,7 +184,7 @@ type Company {
website: Link website: Link
departement: String departement: String
email: String email: String
address: Address country: Country
phone: String phone: String
infos: String infos: String
} }
@ -217,6 +217,10 @@ type Address {
family_name: String family_name: String
} }
type Country {
country_code: String
country_name: String
}
type Date { type Date {
start: String start: String

View File

@ -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'))

File diff suppressed because one or more lines are too long

View File

@ -28,20 +28,10 @@ fragment MateriauModalFields on Materiau {
url url
} }
infos infos
address { phone
langcode country {
country_code country_code
administrative_area country_name
locality
dependent_locality
postal_code
sorting_code
address_line1
address_line2
organization
given_name
additional_name
family_name
} }
} }
manufacturer{ manufacturer{
@ -54,20 +44,10 @@ fragment MateriauModalFields on Materiau {
url url
} }
infos infos
address { phone
langcode country {
country_code country_code
administrative_area country_name
locality
dependent_locality
postal_code
sorting_code
address_line1
address_line2
organization
given_name
additional_name
family_name
} }
} }
samples{ samples{

View File

@ -152,6 +152,8 @@
<a target="_blank" :href="manu.website.url">{{shortUrl(manu.website.url)}}</a> <a target="_blank" :href="manu.website.url">{{shortUrl(manu.website.url)}}</a>
</p> </p>
<p v-if="manu.email"><a :href="'mailto:'+manu.email">{{ manu.email }}</a></p> <p v-if="manu.email"><a :href="'mailto:'+manu.email">{{ manu.email }}</a></p>
<p v-if="manu.phone"><a :href="'tel:'+manu.phone">{{ manu.phone }}</a></p>
<p v-if="manu.country.country_name">{{ manu.country.country_name }}</p>
</li> </li>
</ul> </ul>
</section> </section>
@ -164,6 +166,8 @@
<a target="_blank" :href="distrib.website.url">{{shortUrl(distrib.website.url)}}</a> <a target="_blank" :href="distrib.website.url">{{shortUrl(distrib.website.url)}}</a>
</p> </p>
<p v-if="distrib.email"><a :href="'mailto:'+distrib.email">{{ distrib.email }}</a></p> <p v-if="distrib.email"><a :href="'mailto:'+distrib.email">{{ distrib.email }}</a></p>
<p v-if="distrib.phone"><a :href="'tel:'+distrib.phone">{{ distrib.phone }}</a></p>
<p v-if="distrib.country.country_name">{{ distrib.country.country_name }}</p>
</li> </li>
</ul> </ul>
</section> </section>