public function PreparedAttribute::__construct in Commerce Core 8.2
Constructs a new PreparedAttribute instance.
Parameters
array $definition: The definition.
File
- modules/
product/ src/ PreparedAttribute.php, line 53
Class
- PreparedAttribute
- Represents a prepared attribute.
Namespace
Drupal\commerce_productCode
public function __construct(array $definition) {
foreach ([
'id',
'label',
'element_type',
'values',
] as $required_property) {
if (empty($definition[$required_property])) {
throw new \InvalidArgumentException(sprintf('Missing required property "%s".', $required_property));
}
}
if (!is_array($definition['values'])) {
throw new \InvalidArgumentException(sprintf('The property "values" must be an array.'));
}
$this->id = $definition['id'];
$this->label = $definition['label'];
$this->elementType = $definition['element_type'];
$this->required = isset($definition['required']) ? $definition['required'] : TRUE;
$this->values = $definition['values'];
}