addItem($field); } } public function getFields(): array { $fields = []; foreach ($this->fields as $field) { if ($field instanceof CWidgetFieldsGroupView) { foreach ($field->getFields() as $group_field) { $fields[] = $group_field; } } else { $fields[] = $field; } } return $fields; } public function addFieldsGroup(?CWidgetFieldsGroupView $fields_group): self { return $this->addItem($fields_group); } public function addField(?CWidgetFieldView $field): self { return $this->addItem($field); } public function addItem($value): self { if ($value === null) { return $this; } if (is_string($value)) { $value = $this->encode($value, $this->getEncStrategy()); } $this->fields[] = $value; return $this; } protected function bodyToString(): string { foreach ($this->fields as &$field) { if ($field instanceof CWidgetFieldsGroupView) { $field = [$field->getLabel(), $field]; } elseif ($field instanceof CWidgetFieldView) { $field = [$field->getLabel(), (new CFormField($field->getView()))->addClass($field->getClass())]; } } unset($field); return $this->makeLegend().unpack_object($this->fields); } }