/** * {@inheritdoc} */ public function setValue($value) { switch (gettype($value)) { case 'array': $this->attribute_type = AttributeTypes::ARRAY_TYPE; $this->string_value = serialize($value); break; case 'object': $this->attribute_type = Yii::$app->get('typesRegister')->getEntityType($value); $this->relatedValueEntity = $value; break; default: if ($this->getType() === 'value') { $this->value_id = (int) $value; } elseif (in_array($this->getType(), AttributeTypes::getTypes())) { $this->string_value = $value; } else { $this->value_entity_id = $value; } } }
echo $form->field($model, 'name')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model, 'presentation')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model, 'type')->dropDownList(AttributeTypes::getChoices(), ['prompt' => '']); ?> <?php echo $form->field($model, 'fieldConfig[fieldType]')->dropDownList(AttributeTypes::getFieldTypeChoices(), ['prompt' => '']); ?> <?php echo $form->field($model, 'rulesConfig')->dropDownList(AttributeTypes::getValidatorChoices(), ['multiple' => true, 'prompt' => '']); ?> <div class="form-group"> <?php echo Html::submitButton($model->isNewRecord ? Module::t('module', 'Create') : Module::t('module', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-primary' : 'btn btn-success']); ?> </div> <?php ActiveForm::end(); ?> </div>
/** * @param AttributeValueInterface[] $attributes * @param string $column * @return AttributeValueInterface[] */ protected function groupEAttributesBy($attributes, $column) { /** @var AttributeValue[] $grouped */ $grouped = []; foreach ($attributes as $attribute) { if (isset($grouped[$attribute->{$column}])) { $grouped[$attribute->{$column}] = clone $grouped[$attribute->{$column}]; if (!in_array($grouped[$attribute->{$column}]->getType(), AttributeTypes::getTypes())) { $v = $grouped[$attribute->{$column}]->getValue(); $grouped[$attribute->{$column}]->setValue($v); } $v1 = $grouped[$attribute->{$column}]->getValue(); $v2 = $attribute->getValue(); $v1 = is_array($v1) ? $v1 : [$v1]; $v2 = is_array($v2) ? $v2 : [$v2]; $value = array_merge($v1, $v2); if (!in_array($grouped[$attribute->{$column}]->getType(), AttributeTypes::getTypes())) { $grouped[$attribute->{$column}]->populateRelation('relatedValueEntity', $value); } else { $grouped[$attribute->{$column}]->string_value = $value; } } else { $grouped[$attribute->{$column}] = $attribute; } } return $grouped; }