diff --git a/vendor/magento/module-company/Model/Company/DataProvider.php b/vendor/magento/module-company/Model/Company/DataProvider.php index 3028befba11d..7d88636c76a2 100644 --- a/vendor/magento/module-company/Model/Company/DataProvider.php +++ b/vendor/magento/module-company/Model/Company/DataProvider.php @@ -21,6 +21,9 @@ use Magento\Framework\Exception\LocalizedException; use Magento\Framework\Exception\NoSuchEntityException; use Magento\Ui\DataProvider\AbstractDataProvider; +use Magento\Ui\DataProvider\Modifier\ModifierInterface; +use Magento\Ui\DataProvider\Modifier\Pool; +use Magento\Ui\DataProvider\Modifier\PoolInterface; /** * Data provider for company. @@ -125,5 +128,10 @@ class DataProvider extends AbstractDataProvider private $fileUploaderDataResolver; + /** + * @var PoolInterface + */ + private $pool; + /** * @param string $name * @param string $primaryFieldName @@ -137,6 +145,7 @@ class DataProvider extends AbstractDataProvider * @param array $data [optional] * @param CustomerRegistry|null $customerRegistry * @param FileUploaderDataResolver|null $fileUploaderDataResolver + * @param PoolInterface|null $pool * @throws LogicException * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ @@ -152,7 +161,8 @@ public function __construct( array $meta = [], array $data = [], ?CustomerRegistry $customerRegistry = null, - ?FileUploaderDataResolver $fileUploaderDataResolver = null + ?FileUploaderDataResolver $fileUploaderDataResolver = null, + ?PoolInterface $pool = null ) { parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data); $this->collection = $companyCollectionFactory->create(); @@ -164,6 +174,7 @@ public function __construct( ObjectManager::getInstance()->get(CustomerRegistry::class); $this->fileUploaderDataResolver = $fileUploaderDataResolver ?? ObjectManager::getInstance()->get(FileUploaderDataResolver::class); + $this->pool = $pool ?? ObjectManager::getInstance()->create(Pool::class); } /** @@ -288,6 +299,11 @@ public function getData() $this->loadedData[$company->getId()] = $this->getCompanyResultData($company); } + /** @var ModifierInterface $modifier */ + foreach ($this->pool->getModifiersInstances() as $modifier) { + $this->loadedData = $modifier->modifyData($this->loadedData); + } + return $this->loadedData; } @@ -334,6 +350,11 @@ public function getMeta() $this->attributeMetadataResolver->processWebsiteMeta($customerMeta); $meta['company_admin']['children'] = $customerMeta; + /** @var ModifierInterface $modifier */ + foreach ($this->pool->getModifiersInstances() as $modifier) { + $meta = $modifier->modifyMeta($meta); + } + return $meta; } } diff --git a/vendor/magento/module-company/Model/SaveValidator/SanitizeCompanyName.php b/vendor/magento/module-company/Model/SaveValidator/SanitizeCompanyName.php new file mode 100644 index 000000000000..ee178c87c2e1 --- /dev/null +++ b/vendor/magento/module-company/Model/SaveValidator/SanitizeCompanyName.php @@ -0,0 +1,63 @@ +company->getCompanyName(); + if (empty($name)) { + return; + } + + $sanitized = trim($this->stripTags->filter($name)); + if ($sanitized === '') { + $this->exception->addError( + __('Company name is invalid.') + ); + return; + } + + $this->company->setCompanyName($sanitized); + } +} diff --git a/vendor/magento/module-company/Ui/DataProvider/Company/Form/Modifier/SanitizeFormData.php b/vendor/magento/module-company/Ui/DataProvider/Company/Form/Modifier/SanitizeFormData.php new file mode 100644 index 000000000000..087b30d3bc3a --- /dev/null +++ b/vendor/magento/module-company/Ui/DataProvider/Company/Form/Modifier/SanitizeFormData.php @@ -0,0 +1,81 @@ + $row) { + if (!is_array($row)) { + continue; + } + $data[$entityId] = $this->sanitizeRow($row); + } + + return $data; + } + + /** + * @inheritdoc + */ + public function modifyMeta(array $meta): array + { + return $meta; + } + + /** + * Sanitize details + * + * @param array $row + * @return array + */ + private function sanitizeRow(array $row): array + { + $scope = CompanyFormDataProvider::DATA_SCOPE_GENERAL; + if (!isset($row[$scope]) || !is_array($row[$scope])) { + return $row; + } + + if (isset($row[$scope][CompanyInterface::NAME]) && is_string($row[$scope][CompanyInterface::NAME])) { + $row[$scope][CompanyInterface::NAME] = trim($this->stripTags->filter($row[$scope][CompanyInterface::NAME])); + } + + return $row; + } +} diff --git a/vendor/magento/module-company/etc/adminhtml/di.xml b/vendor/magento/module-company/etc/adminhtml/di.xml index e3b413caef4f..52e3d7201240 100644 --- a/vendor/magento/module-company/etc/adminhtml/di.xml +++ b/vendor/magento/module-company/etc/adminhtml/di.xml @@ -7,5 +7,20 @@ --> + + + + + Magento\Company\Ui\DataProvider\Company\Form\Modifier\SanitizeFormData + 10 + + + + + + + Magento\Company\Ui\DataProvider\Company\Form\Modifier\Pool + + @@ -26,6 +41,7 @@ \Magento\Company\Model\SaveValidator\CompanyId \Magento\Company\Model\SaveValidator\RequiredFields + \Magento\Company\Model\SaveValidator\SanitizeCompanyName \Magento\Company\Model\SaveValidator\SalesRepresentative \Magento\Company\Model\SaveValidator\CustomerGroup \Magento\Company\Model\SaveValidator\CompanyStatus diff --git a/vendor/magento/module-company/etc/di.xml b/vendor/magento/module-company/etc/di.xml index 97cfbb9df300..85704cec9e1b 100755 --- a/vendor/magento/module-company/etc/di.xml +++ b/vendor/magento/module-company/etc/di.xml @@ -32,6 +32,7 @@ \Magento\Company\Model\SaveValidator\CompanyId \Magento\Company\Model\SaveValidator\RequiredFields + \Magento\Company\Model\SaveValidator\SanitizeCompanyName \Magento\Company\Model\SaveValidator\SalesRepresentative \Magento\Company\Model\SaveValidator\CustomerGroup \Magento\Company\Model\SaveValidator\CompanyStatus diff --git a/vendor/magento/module-company/i18n/en_US.csv b/vendor/magento/module-company/i18n/en_US.csv index 14d4ef6b2464..8a0f07cf1480 100644 --- a/vendor/magento/module-company/i18n/en_US.csv +++ b/vendor/magento/module-company/i18n/en_US.csv @@ -392,3 +392,4 @@ Team,Team Users,Users "Granting permissions does not affect which features are available for your company account. The merchant must enable features to make them available for your account.","Granting permissions does not affect which features are available for your company account. The merchant must enable features to make them available for your account." "Only admin can edit their profile.","Only admin can edit their profile." +"Company name is invalid.","Company name is invalid."