diff --git a/vendor/magento/module-company/Model/Company/DataProvider.php b/vendor/magento/module-company/Model/Company/DataProvider.php index 483c17cbd0fc..a68c8169fe5a 100644 --- a/vendor/magento/module-company/Model/Company/DataProvider.php +++ b/vendor/magento/module-company/Model/Company/DataProvider.php @@ -32,6 +32,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. @@ -138,5 +141,10 @@ class DataProvider extends AbstractDataProvider private $fileUploaderDataResolver; + /** + * @var PoolInterface + */ + private $pool; + /** * @param string $name * @param string $primaryFieldName @@ -150,6 +158,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) */ @@ -165,7 +174,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(); @@ -177,6 +187,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); } /** @@ -303,6 +314,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; } @@ -349,6 +365,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 2d82edc2c9d9..dd9715a34bd2 100644 --- a/vendor/magento/module-company/etc/adminhtml/di.xml +++ b/vendor/magento/module-company/etc/adminhtml/di.xml @@ -18,5 +18,20 @@ --> + + + + + Magento\Company\Ui\DataProvider\Company\Form\Modifier\SanitizeFormData + 10 + + + + + + + Magento\Company\Ui\DataProvider\Company\Form\Modifier\Pool + + @@ -43,6 +58,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 old mode 100755 new mode 100644 index 3d0622db3e2e..1fe919d2e34c --- a/vendor/magento/module-company/etc/di.xml +++ b/vendor/magento/module-company/etc/di.xml @@ -45,6 +45,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 2931550eafa2..b08c342405b2 100644 --- a/vendor/magento/module-company/i18n/en_US.csv +++ b/vendor/magento/module-company/i18n/en_US.csv @@ -434,3 +434,4 @@ Users,Users "Error assigning companies to the customer.","Error assigning companies to the customer." "Cannot change an existing company for a customer.","Cannot change an existing company for a customer." "Removing a company revokes user access for that company. User data remains accessible in the Admin. Removing all companies changes the account type to Individual, disabling B2B capabilities for the account.","Removing a company revokes user access for that company. User data remains accessible in the Admin. Removing all companies changes the account type to Individual, disabling B2B capabilities for the account." +"Company name is invalid.","Company name is invalid."