<?php
/**
 * Class HalfPageCustomCosSection
 * User: ThurData
 * Date: 2019-10-07
 * Time: 15:22
 * @package ThurData\Servers\KerioEmail\App\UI\Admin\Custom\Sections
 */

namespace ThurData\Servers\KerioEmail\App\UI\Admin\Custom\Sections;


use ThurData\Servers\KerioEmail\Core\UI\Widget\Forms\Sections\HalfPageSection;

class HalfPageCustomCosSection extends HalfPageSection
{
        public function loadDataToForm(&$dataProvider)
        {
            foreach($this->fields as &$field)
            {
                /**
                 * update for cos fields
                 */
                $cos = $dataProvider->getValueById('cos');
                $value = $cos[$field->getId()] ? $cos[$field->getId()] : $dataProvider->getValueById($field->getId());
                $field->setValue($value);


                $avValues = $dataProvider->getAvailableValuesById($field->getId());
                if ($avValues && method_exists($field, 'setAvailableValues'))
                {
                    $field->setAvailableValues($avValues);
                }
            }

            foreach ($this->sections as &$section)
            {
                $section->loadDataToForm($dataProvider);
            }
        }
}