public function buildForm(FormBuilderInterface $builder, array $options) { // Options Headings $headings = []; foreach ($this->_optionLoader->getAllOptionNames() as $name => $value) { $headings[$value] = ucfirst($value); } $builder->add('sku', 'text', ['attr' => ['list' => 'option_value', 'placeholder' => 'ms.commerce.product.units.sku.placeholder', 'data-help-key' => 'ms.commerce.product.image.option.units.sku.help']])->add('weight', 'number', ['attr' => ['data-help-key' => 'ms.commerce.product.details.weight-grams.help']]); $optionType = new OptionType($headings, ['attr' => ['data-help-key' => ['name' => 'ms.commerce.product.units.option.name.help', 'value' => 'ms.commerce.product.units.option.value.help']]]); $optionType->setNameLabel('ms.commerce.product.units.option.name.label')->setValueLabel('ms.commerce.product.units.option.value.label'); $builder->add('options', 'collection', ['type' => $optionType, 'label' => 'Options', 'allow_add' => true, 'allow_delete' => true, 'constraints' => [new UnitHasOptions()]]); $builder->add('prices', 'price_form'); }
protected function _getImageForm() { $files = (array) $this->get('file_manager.file.loader')->getAll(); $choices = array(); $allowedTypes = array(File\Type::IMAGE); foreach ($files as $file) { if ($allowedTypes) { if (!in_array($file->typeID, $allowedTypes)) { continue; } } $choices[$file->id] = $file->name; } uasort($choices, function ($a, $b) { return strcmp($a, $b); }); $form = $this->get('form')->setName('images')->setAction($this->generateUrl('ms.commerce.product.edit.images', array('productID' => $this->_product->id))); $imageTypes = $this->get('product.image.types')->all(); $form->add('image', 'ms_file', $this->trans('ms.commerce.product.image.file.label'), array('choices' => $choices, 'empty_value' => 'Please select…', 'attr' => array('data-help-key' => 'ms.commerce.product.image.file.help'))); $form->add('type', 'choice', $this->trans('ms.commerce.product.image.type.label'), array('choices' => $imageTypes, 'attr' => array('data-help-key' => 'ms.commerce.product.image.type.help'))); $optionType = new Field\OptionType($this->get('option.loader')->getOptionNamesByProduct($this->_product), array('attr' => array('data-help-key' => array('name' => 'ms.commerce.product.units.option.name.help', 'value' => 'ms.commerce.product.units.option.value.help')))); $optionType->setValueChoice($this->get('option.loader')->getOptionValuesByProduct($this->_product))->setNameLabel($this->trans('ms.commerce.product.image.option.name.label'))->setValueLabel($this->trans('ms.commerce.product.image.option.value.label')); $form->add('options', 'collection', 'Options', array('type' => $optionType, 'label' => 'Options', 'allow_add' => true, 'allow_delete' => true))->val()->optional(); return $form; }