From 8b5818df65ad4ab7ed33fe5933782151f9b0d2cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Corr=C3=AAa=20Gomes?= Date: Thu, 7 Nov 2019 22:55:40 -0300 Subject: [PATCH] Contact form > Adding ViewModel --- .../Contact/ViewModel/UserDataProvider.php | 72 +++++++++++++++++++ .../frontend/layout/contact_index_index.xml | 3 + .../view/frontend/templates/form.phtml | 11 +-- 3 files changed, 82 insertions(+), 4 deletions(-) create mode 100644 app/code/Magento/Contact/ViewModel/UserDataProvider.php diff --git a/app/code/Magento/Contact/ViewModel/UserDataProvider.php b/app/code/Magento/Contact/ViewModel/UserDataProvider.php new file mode 100644 index 0000000000000..678f4349b0e88 --- /dev/null +++ b/app/code/Magento/Contact/ViewModel/UserDataProvider.php @@ -0,0 +1,72 @@ +helper = $helper; + } + + /** + * Get user name + * + * @return string + */ + public function getUserName() + { + return $this->helper->getPostValue('name') ?: $this->helper->getUserName(); + } + + /** + * Get user email + * + * @return string + */ + public function getUserEmail() + { + return $this->helper->getPostValue('email') ?: $this->helper->getUserEmail(); + } + + /** + * Get user telephone + * + * @return string + */ + public function getUserTelephone() + { + return $this->helper->getPostValue('telephone'); + } + + /** + * Get user comment + * + * @return string + */ + public function getUserComment() + { + return $this->helper->getPostValue('comment'); + } +} diff --git a/app/code/Magento/Contact/view/frontend/layout/contact_index_index.xml b/app/code/Magento/Contact/view/frontend/layout/contact_index_index.xml index 078c1a4ff5621..c7009831d4642 100644 --- a/app/code/Magento/Contact/view/frontend/layout/contact_index_index.xml +++ b/app/code/Magento/Contact/view/frontend/layout/contact_index_index.xml @@ -13,6 +13,9 @@ + + Magento\Contact\ViewModel\UserDataProvider + diff --git a/app/code/Magento/Contact/view/frontend/templates/form.phtml b/app/code/Magento/Contact/view/frontend/templates/form.phtml index d64a991bcafad..74708bf276a78 100644 --- a/app/code/Magento/Contact/view/frontend/templates/form.phtml +++ b/app/code/Magento/Contact/view/frontend/templates/form.phtml @@ -6,6 +6,9 @@ // @codingStandardsIgnoreFile /** @var \Magento\Contact\Block\ContactForm $block */ +/** @var \Magento\Contact\ViewModel\UserDataProvider $viewModel */ + +$viewModel = $block->getViewModel(); ?>
- +
- +
- +
getChildHtml('form.additional.info') ?>