Skip to content

Commit 98f3f6f

Browse files
authored
Merge branch 'main' into PWA-2140
2 parents 4810d5c + aa0d946 commit 98f3f6f

29 files changed

+798
-3
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
.idea
1+
.idea
2+
**/.DS_Store

CODE_OF_CONDUCT.md

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Contributor Covenant Code of Conduct
2+
3+
## Our Pledge
4+
5+
In the interest of fostering an open and welcoming environment, we as
6+
contributors and maintainers pledge to making participation in our project and
7+
our community a harassment-free experience for everyone, regardless of age, body
8+
size, disability, ethnicity, sex characteristics, gender identity and expression,
9+
level of experience, education, socio-economic status, nationality, personal
10+
appearance, race, religion, or sexual identity and orientation.
11+
12+
## Our Standards
13+
14+
Examples of behavior that contributes to creating a positive environment
15+
include:
16+
17+
* Using welcoming and inclusive language
18+
* Being respectful of differing viewpoints and experiences
19+
* Gracefully accepting constructive criticism
20+
* Focusing on what is best for the community
21+
* Showing empathy towards other community members
22+
23+
Examples of unacceptable behavior by participants include:
24+
25+
* The use of sexualized language or imagery and unwelcome sexual attention or
26+
advances
27+
* Trolling, insulting/derogatory comments, and personal or political attacks
28+
* Public or private harassment
29+
* Publishing others' private information, such as a physical or electronic
30+
address, without explicit permission
31+
* Other conduct which could reasonably be considered inappropriate in a
32+
professional setting
33+
34+
## Our Responsibilities
35+
36+
Project maintainers are responsible for clarifying the standards of acceptable
37+
behavior and are expected to take appropriate and fair corrective action in
38+
response to any instances of unacceptable behavior.
39+
40+
Project maintainers have the right and responsibility to remove, edit, or
41+
reject comments, commits, code, wiki edits, issues, and other contributions
42+
that are not aligned to this Code of Conduct, or to ban temporarily or
43+
permanently any contributor for other behaviors that they deem inappropriate,
44+
threatening, offensive, or harmful.
45+
46+
## Scope
47+
48+
This Code of Conduct applies both within project spaces and in public spaces
49+
when an individual is representing the project or its community. Examples of
50+
representing a project or community include using an official project e-mail
51+
address, posting via an official social media account, or acting as an appointed
52+
representative at an online or offline event. Representation of a project may be
53+
further defined and clarified by project maintainers.
54+
55+
## Enforcement
56+
57+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
58+
reported by contacting the project team at [email protected]. All
59+
complaints will be reviewed and investigated and will result in a response that
60+
is deemed necessary and appropriate to the circumstances. The project team is
61+
obligated to maintain confidentiality with regard to the reporter of an incident.
62+
Further details of specific enforcement policies may be posted separately.
63+
64+
Project maintainers who do not follow or enforce the Code of Conduct in good
65+
faith may face temporary or permanent repercussions as determined by other
66+
members of the project's leadership.
67+
68+
## Attribution
69+
70+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71+
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
72+
73+
[homepage]: https://www.contributor-covenant.org
74+
75+
For answers to common questions about this code of conduct, see
76+
https://www.contributor-covenant.org/faq

COPYRIGHT.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Copyright © 2019-present Magento, Inc. All rights reserved.
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\ContactGraphQlPwa\Model\Resolver;
9+
10+
use Magento\Contact\Model\ConfigInterface;
11+
use Magento\Contact\Model\MailInterface;
12+
use Magento\Framework\GraphQl\Config\Element\Field;
13+
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
14+
use Magento\Framework\GraphQl\Query\ResolverInterface;
15+
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
16+
use Magento\Framework\Validator\EmailAddress;
17+
use Psr\Log\LoggerInterface;
18+
19+
class ContactUs implements ResolverInterface
20+
{
21+
public const DEFAULT_VALUES = [
22+
'telephone' => '-'
23+
];
24+
25+
/** @var \Magento\Contact\Model\MailInterface */
26+
private $mail;
27+
28+
/** @var \Magento\Contact\Model\ConfigInterface */
29+
private $contactConfig;
30+
31+
/** @var \Psr\Log\LoggerInterface */
32+
private $logger;
33+
34+
/** @var \Magento\Framework\Validator\EmailAddress */
35+
private $emailValidator;
36+
37+
/**
38+
* @param \Magento\Contact\Model\MailInterface $mail
39+
* @param \Magento\Contact\Model\ConfigInterface $contactConfig
40+
* @param \Psr\Log\LoggerInterface $logger
41+
* @param \Magento\Framework\Validator\EmailAddress $emailValidator
42+
*/
43+
public function __construct(
44+
MailInterface $mail,
45+
ConfigInterface $contactConfig,
46+
LoggerInterface $logger,
47+
EmailAddress $emailValidator
48+
) {
49+
$this->mail = $mail;
50+
$this->contactConfig = $contactConfig;
51+
$this->logger = $logger;
52+
$this->emailValidator = $emailValidator;
53+
}
54+
55+
/**
56+
* @inheritDoc
57+
*/
58+
public function resolve(
59+
Field $field,
60+
$context,
61+
ResolveInfo $info,
62+
array $value = null,
63+
array $args = null
64+
) {
65+
if (!$this->contactConfig->isEnabled()) {
66+
throw new GraphQlInputException(
67+
__('The contact form is unavailable.')
68+
);
69+
}
70+
71+
$input = $this->cleanInput($args['input']);
72+
$this->validateInput($input);
73+
74+
$variables = ['data' => $input];
75+
try {
76+
$this->mail->send($input['email'], $variables);
77+
} catch (\Exception $e) {
78+
$this->logger->critical($e);
79+
80+
throw new GraphQlInputException(
81+
__('An error occurred while processing your form. Please try again later.')
82+
);
83+
}
84+
85+
return [
86+
'status' => true
87+
];
88+
}
89+
90+
/**
91+
* Get default values map
92+
*
93+
* @return string[]
94+
*/
95+
public function getDefaultValues(): array
96+
{
97+
return self::DEFAULT_VALUES;
98+
}
99+
100+
/**
101+
* Clean input values and set default values
102+
*
103+
* @param array<string, string> $input
104+
*
105+
* @return array<string, string>
106+
*/
107+
public function cleanInput(array $input): array
108+
{
109+
$values = [];
110+
$defaults = $this->getDefaultValues();
111+
foreach ($input as $field => $value) {
112+
$cleanValue = $value === null ? '' : trim($value);
113+
114+
if ($cleanValue === '' && isset($defaults[$field])) {
115+
$cleanValue = $defaults[$field];
116+
}
117+
118+
$values[$field] = $cleanValue;
119+
}
120+
121+
foreach ($defaults as $field => $value) {
122+
if (!isset($values[$field])) {
123+
$values[$field] = $value;
124+
}
125+
}
126+
127+
return $values;
128+
}
129+
130+
/**
131+
* Validate input data
132+
*
133+
* @param array<string, string> $input
134+
*
135+
* @return void
136+
* @throws \Magento\Framework\GraphQl\Exception\GraphQlInputException
137+
*/
138+
public function validateInput(array $input): void
139+
{
140+
if (!$this->emailValidator->isValid($input['email'])) {
141+
throw new GraphQlInputException(
142+
__('The email address is invalid. Verify the email address and try again.')
143+
);
144+
}
145+
146+
if ($input['name'] === '') {
147+
throw new GraphQlInputException(__('Enter the Name and try again.'));
148+
}
149+
150+
if ($input['comment'] === '') {
151+
throw new GraphQlInputException(__('Enter the comment and try again.'));
152+
}
153+
}
154+
}

ContactGraphQlPwa/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# ContactGraphQlPwa
2+
3+
**ContactGraphQlPwa** provides GraphQL support for `magento/module-contact`.

ContactGraphQlPwa/composer.json

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"name": "magento/module-contact-graph-ql-pwa",
3+
"description": "Provides GraphQl functionality for the contact-us form.",
4+
"type": "magento2-module",
5+
"license": [
6+
"OSL-3.0",
7+
"AFL-3.0"
8+
],
9+
"config": {
10+
"sort-packages": true
11+
},
12+
"require": {
13+
"php": "~7.3.0||~7.4.0",
14+
"magento/framework": "*",
15+
"magento/module-contact": "*"
16+
},
17+
"suggest": {
18+
"magento/module-graph-ql": "*"
19+
},
20+
"autoload": {
21+
"files": [
22+
"registration.php"
23+
],
24+
"psr-4": {
25+
"Magento\\ContactGraphQlPwa\\": ""
26+
}
27+
}
28+
}
29+

ContactGraphQlPwa/etc/graphql/di.xml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
9+
<type name="Magento\StoreGraphQl\Model\Resolver\Store\StoreConfigDataProvider">
10+
<arguments>
11+
<argument name="extendedConfigData" xsi:type="array">
12+
<item name="contact_enabled" xsi:type="string">contact/contact/enabled</item>
13+
</argument>
14+
</arguments>
15+
</type>
16+
</config>

ContactGraphQlPwa/etc/module.xml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
9+
<module name="Magento_ContactGraphQlPwa">
10+
<sequence>
11+
<module name="Magento_Contact"/>
12+
<module name="Magento_GraphQl"/>
13+
</sequence>
14+
</module>
15+
</config>

ContactGraphQlPwa/etc/schema.graphqls

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Copyright © Magento, Inc. All rights reserved.
2+
# See COPYING.txt for license details.
3+
4+
type Mutation {
5+
contactUs(
6+
input: ContactUsInput! @doc(description: "An input object that defines shopper information.")
7+
): ContactUsOutput @doc(description: "Send a 'Contact Us' email to the merchant.") @resolver(class: "Magento\\ContactGraphQlPwa\\Model\\Resolver\\ContactUs")
8+
}
9+
10+
input ContactUsInput {
11+
email: String! @doc(description: "The email address of the shopper.")
12+
name: String! @doc(description: "The full name of the shopper.")
13+
telephone: String @doc(description: "The shopper's telephone number.")
14+
comment: String! @doc(description: "The shopper's comment to the merchant.")
15+
}
16+
17+
type ContactUsOutput @doc(description: "Contains the status of the request."){
18+
status: Boolean! @doc(description: "Indicates whether the request was successful.")
19+
}
20+
21+
type StoreConfig {
22+
contact_enabled: Boolean! @doc(description: "Indicates whether the Contact Us form in enabled.")
23+
}

ContactGraphQlPwa/registration.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
use Magento\Framework\Component\ComponentRegistrar;
9+
10+
ComponentRegistrar::register(ComponentRegistrar::MODULE, 'Magento_ContactGraphQlPwa', __DIR__);

0 commit comments

Comments
 (0)