* @copyright Since 2007 PrestaShop SA and Contributors * @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0) */ namespace PrestaShop\Module\AutoUpgrade\Twig\Form; use Configuration; use PrestaShop\Module\AutoUpgrade\Parameters\UpgradeConfiguration; use PrestaShop\Module\AutoUpgrade\UpgradeContainer; use PrestaShop\Module\AutoUpgrade\UpgradeTools\Translator; use Twig_Environment; class FormRenderer { /** * @var UpgradeConfiguration */ private $config; /** * @var Translator */ private $translator; /** * @var Twig_Environment|\Twig\Environment */ private $twig; public function __construct( UpgradeConfiguration $configuration, $twig, Translator $translator ) { $this->config = $configuration; $this->twig = $twig; $this->translator = $translator; } public function render($name, $fields, $tabname, $size, $icon) { $required = false; $formFields = []; foreach ($fields as $key => $field) { $html = ''; $required = !empty($field['required']); $disabled = !empty($field['disabled']); if (in_array($key, UpgradeContainer::DB_CONFIG_KEYS)) { // values fetched from configuration in database $val = Configuration::get($key); } else { // other conf values are fetched from config file $val = $this->config->get($key); } if ($val === null) { $val = isset($field['defaultValue']) ? $field['defaultValue'] : false; } if (!in_array($field['type'], ['image', 'radio', 'select', 'container', 'bool', 'container_end']) || isset($field['show'])) { $html .= '
'; if (!empty($field['thumb']) && $field['thumb']['pos'] == 'after') { $html .= $this->renderThumb($field); } $html .= $field['desc'] . '
'; } if (!in_array($field['type'], ['image', 'radio', 'select', 'container', 'bool', 'container_end']) || isset($field['show'])) { $html .= '