/** * {@inheritdoc} */ public function getDefaultValueFormParameters(Attribute $attribute) { if ($attribute->isLocalized()) { return ['type' => LocalizedSelectCollectionType::NAME]; } else { return ['type' => NotLocalizedSelectCollectionType::NAME]; } }
/** * @param Attribute $attribute * @param AttributeTypeInterface $attributeType * @param mixed $value */ public function setDefaultValue(Attribute $attribute, AttributeTypeInterface $attributeType, $value) { $isLocalizedValue = is_array($value) && array_key_exists(null, $value); // normalize value if ($isLocalizedValue && !$attribute->isLocalized()) { $value = $value[null]; } elseif (!$isLocalizedValue && $attribute->isLocalized()) { $value = [null => $value]; } // set value if ($attribute->isLocalized()) { foreach ($value as $localeId => $itemValue) { $this->setDefaultValueByField($attribute, $attributeType, $localeId, $itemValue); } } else { $this->setDefaultValueByField($attribute, $attributeType, null, $value); } }