1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* TechDivision\Import\Attribute\Callbacks\FrontendInputAttributeOptionsValidatorCallback |
5
|
|
|
* |
6
|
|
|
* NOTICE OF LICENSE |
7
|
|
|
* |
8
|
|
|
* This source file is subject to the Open Software License (OSL 3.0) |
9
|
|
|
* that is available through the world-wide-web at this URL: |
10
|
|
|
* http://opensource.org/licenses/osl-3.0.php |
11
|
|
|
* |
12
|
|
|
* PHP version 5 |
13
|
|
|
* |
14
|
|
|
* @author Martin Eisenführer <[email protected]> |
15
|
|
|
* @copyright 2021 TechDivision GmbH <[email protected]> |
16
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
17
|
|
|
* @link https://github.com/techdivision/import-attribute |
18
|
|
|
* @link http://www.techdivision.com |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
namespace TechDivision\Import\Attribute\Callbacks; |
22
|
|
|
|
23
|
|
|
use TechDivision\Import\Attribute\Utils\ColumnKeys; |
24
|
|
|
use TechDivision\Import\Callbacks\AbstractValidatorCallback; |
25
|
|
|
use TechDivision\Import\Utils\FrontendInputTypes; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* A callback implementation that validates the a list of attribute set names. |
29
|
|
|
* |
30
|
|
|
* @author Martin Eisenführer <[email protected]> |
31
|
|
|
* @copyright 2021 TechDivision GmbH <[email protected]> |
32
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
33
|
|
|
* @link https://github.com/techdivision/import-attribute |
34
|
|
|
* @link http://www.techdivision.com |
35
|
|
|
*/ |
36
|
|
|
class FrontendInputAttributeOptionsValidatorCallback extends AbstractValidatorCallback |
37
|
|
|
{ |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Will be invoked by the observer it has been registered for. |
41
|
|
|
* |
42
|
|
|
* @param string|null $attributeCode The code of the attribute that has to be validated |
43
|
|
|
* @param string|null $attributeValue The attribute value to be validated |
44
|
|
|
* |
45
|
|
|
* @return mixed The modified value |
46
|
|
|
*/ |
47
|
|
|
public function handle($attributeCode = null, $attributeValue = null) |
48
|
|
|
{ |
49
|
|
|
|
50
|
|
|
// load the atribute options |
51
|
|
|
$optionsValues = $this->getSubject() |
52
|
|
|
->getValue(ColumnKeys::ATTRIBUTE_OPTION_VALUES, null, array($this->getSubject(), 'explode')); |
53
|
|
|
|
54
|
|
|
// query whether or not the passed value IS empty |
55
|
|
|
if ($optionsValues === '' || $optionsValues === null) { |
56
|
|
|
return; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
if (!in_array($attributeValue, [FrontendInputTypes::SELECT, FrontendInputTypes::MULTISELECT])) { |
60
|
|
|
// throw an exception if the value is NOT in the array |
61
|
|
|
throw new \InvalidArgumentException( |
62
|
|
|
sprintf( |
63
|
|
|
'Found invalid value "%s" for attribute code "%s". "select" or "multiselect" required', |
64
|
|
|
$attributeValue, |
65
|
|
|
$this->getSubject()->getValue(ColumnKeys::ATTRIBUTE_CODE) |
66
|
|
|
) |
67
|
|
|
); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|