Browse Source

added phone and country to company display

bach 2 years ago
parent
commit
ecf963bb62

+ 5 - 1
web/modules/custom/materio_graphql/graphql/materio_extension.base.graphqls

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

+ 67 - 0
web/modules/custom/materio_graphql/src/Plugin/GraphQL/SchemaExtension/MaterioSchemaExtension.php

@@ -8,6 +8,10 @@ use Drupal\graphql\GraphQL\Response\ResponseInterface;
 use Drupal\graphql\Plugin\GraphQL\SchemaExtension\SdlSchemaExtensionPluginBase;
 use Drupal\materio_graphql\GraphQL\Response\MaterioResponse;
 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;
 
@@ -21,6 +25,36 @@ use GraphQL\Error\Error;
  */
 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}
    */
@@ -51,6 +85,8 @@ class MaterioSchemaExtension extends SdlSchemaExtensionPluginBase {
 
     $this->addAddress($registry, $builder);
 
+    $this->addCountry($registry, $builder);
+
     $this->addFilefield($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'))
       );
 
+    $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',
       $builder->produce('property_path')
         ->map('type', $builder->fromValue('entity:taxonomy_term'))

File diff suppressed because it is too large
+ 0 - 0
web/themes/custom/materiotheme/assets/dist/main.js


BIN
web/themes/custom/materiotheme/assets/dist/main.js.gz


+ 6 - 26
web/themes/custom/materiotheme/vuejs/api/gql/materiaumodal.fragment.gql

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

+ 4 - 0
web/themes/custom/materiotheme/vuejs/components/Content/ModalCard.vue

@@ -152,6 +152,8 @@
                       <a target="_blank" :href="manu.website.url">{{shortUrl(manu.website.url)}}</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>
                 </ul>
               </section>
@@ -164,6 +166,8 @@
                       <a target="_blank" :href="distrib.website.url">{{shortUrl(distrib.website.url)}}</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>
                 </ul>
               </section>

Some files were not shown because too many files changed in this diff