/** * {@inheritdoc} */ public function extractSubmittedData(FormInterface $form) { $data = array('submitted_data' => array('norm' => $this->valueExporter->exportValue($form->getNormData())), 'errors' => array()); if ($form->getViewData() !== $form->getNormData()) { $data['submitted_data']['view'] = $this->valueExporter->exportValue($form->getViewData()); } if ($form->getData() !== $form->getNormData()) { $data['submitted_data']['model'] = $this->valueExporter->exportValue($form->getData()); } foreach ($form->getErrors() as $error) { $errorData = array('message' => $error->getMessage(), 'origin' => is_object($error->getOrigin()) ? spl_object_hash($error->getOrigin()) : null, 'trace' => array()); $cause = $error->getCause(); while (null !== $cause) { if ($cause instanceof ConstraintViolationInterface) { $errorData['trace'][] = array('class' => $this->valueExporter->exportValue(get_class($cause)), 'root' => $this->valueExporter->exportValue($cause->getRoot()), 'path' => $this->valueExporter->exportValue($cause->getPropertyPath()), 'value' => $this->valueExporter->exportValue($cause->getInvalidValue())); $cause = method_exists($cause, 'getCause') ? $cause->getCause() : null; continue; } if ($cause instanceof \Exception) { $errorData['trace'][] = array('class' => $this->valueExporter->exportValue(get_class($cause)), 'message' => $this->valueExporter->exportValue($cause->getMessage())); $cause = $cause->getPrevious(); continue; } $errorData['trace'][] = $cause; break; } $data['errors'][] = $errorData; } $data['synchronized'] = $this->valueExporter->exportValue($form->isSynchronized()); return $data; }
/** * {@inheritdoc} */ public function extractSubmittedData(FormInterface $form) { $data = array('submitted_data' => array('norm' => $this->valueExporter->exportValue($form->getNormData())), 'errors' => array()); if ($form->getViewData() !== $form->getNormData()) { $data['submitted_data']['view'] = $this->valueExporter->exportValue($form->getViewData()); } if ($form->getData() !== $form->getNormData()) { $data['submitted_data']['model'] = $this->valueExporter->exportValue($form->getData()); } foreach ($form->getErrors() as $error) { $data['errors'][] = array('message' => $error->getMessage()); } $data['synchronized'] = $this->valueExporter->exportValue($form->isSynchronized()); return $data; }
/** * {@inheritdoc} */ public function buildView(FormView $view, FormInterface $form, array $options) { $vars = ['preview' => $options['preview'], 'compound' => true, 'media_type' => $options['media_type'], 'select_label' => isset($options['select_label']) ? $options['select_label'] : "Select Media", 'change_label' => isset($options['change_label']) ? $options['change_label'] : "Change Media", 'select_multiple_label' => isset($options['select_multiple_label']) ? $options['select_multiple_label'] : "Select Media", 'change_multiple_label' => isset($options['change_multiple_label']) ? $options['change_multiple_label'] : "Change Media"]; if ($vars['preview'] && $form->getViewData()) { $repository = $this->entityManager->getRepository("HexmediaContentBundle:Media"); if ($options['multiple'] == true) { $entities = $repository->findInBy(['id' => $form->getViewData()]); $vars['entities'] = $entities; } else { $entity = $repository->find($form->getViewData()); $vars['entity'] = $entity; } } $view->vars = array_replace($view->vars, $vars); }
/** * {@inheritdoc} */ public function buildView(FormView $view, FormInterface $form, array $options) { $value = $form->getViewData(); // set string representation if (true === $value) { $value = 'true'; } elseif (false === $value) { $value = 'false'; } elseif (null === $value) { $value = 'null'; } elseif (is_array($value)) { $value = implode(', ', $value); } elseif ($value instanceof \DateTime) { $dateFormat = is_int($options['date_format']) ? $options['date_format'] : DateType::DEFAULT_FORMAT; $timeFormat = is_int($options['time_format']) ? $options['time_format'] : DateType::DEFAULT_FORMAT; $calendar = \IntlDateFormatter::GREGORIAN; $pattern = is_string($options['date_pattern']) ? $options['date_pattern'] : null; $formatter = new \IntlDateFormatter(\Locale::getDefault(), $dateFormat, $timeFormat, 'UTC', $calendar, $pattern); $formatter->setLenient(false); $value = $formatter->format($value); } elseif (is_object($value)) { if (method_exists($value, '__toString')) { $value = $value->__toString(); } else { $value = get_class($value); } } $view->vars['value'] = (string) $value; }
private function serializeForm(FormInterface $form) { if (!$form->all()) { return $form->getViewData(); } $data = null; foreach ($form->all() as $child) { $name = $child->getConfig()->getName(); $data[$name] = $this->serializeForm($child); } return $data; }
/** * {@inheritdoc} */ public function extractSubmittedData(FormInterface $form) { $data = array('submitted_data' => array('norm' => $this->valueExporter->exportValue($form->getNormData())), 'errors' => array()); if ($form->getViewData() !== $form->getNormData()) { $data['submitted_data']['view'] = $this->valueExporter->exportValue($form->getViewData()); } if ($form->getData() !== $form->getNormData()) { $data['submitted_data']['model'] = $this->valueExporter->exportValue($form->getData()); } foreach ($form->getErrors() as $error) { $errorData = array('message' => $error->getMessage(), 'origin' => is_object($error->getOrigin()) ? spl_object_hash($error->getOrigin()) : null); $cause = $error->getCause(); if ($cause instanceof ConstraintViolationInterface) { $errorData['cause'] = array('root' => $this->valueExporter->exportValue($cause->getRoot()), 'path' => $this->valueExporter->exportValue($cause->getPropertyPath()), 'value' => $this->valueExporter->exportValue($cause->getInvalidValue())); } else { $errorData['cause'] = null !== $cause ? $this->valueExporter->exportValue($cause) : null; } $data['errors'][] = $errorData; } $data['synchronized'] = $this->valueExporter->exportValue($form->isSynchronized()); return $data; }
/** * {@inheritdoc} */ public function getViewData() { if ($this->config->getInheritData()) { if (!$this->parent) { throw new RuntimeException('The form is configured to inherit its parent\'s data, but does not have a parent.'); } return $this->parent->getViewData(); } if (!$this->defaultDataSet) { $this->setData($this->config->getData()); } return $this->viewData; }
/** * {@inheritdoc} */ public function buildView(FormView $view, FormInterface $form, array $options) { $value = $form->getViewData(); // set string representation if (true === $value) { $value = 'true'; } elseif (false === $value) { $value = 'false'; } elseif (null === $value) { $value = 'null'; } elseif (is_array($value)) { $value = implode(', ', $value); } $view->vars['value'] = (string) $value; }
/** * Returns the form's data like $form->submit() expects it * * @param FormInterface $form * @return array */ protected function unbind(FormInterface $form) { if ($form->count() > 0) { $ary = array(); foreach ($form->all() as $name => $child) { $value = $this->unbind($child); if (null !== $value || (is_array($value) || $value instanceof Collection) && count($value) > 0) { $ary[$name] = $value; } } return $ary; } else { $data = $form->getViewData(); return $data instanceof Collection ? $data->toArray() : $data; } }
/** * {@inheritdoc} */ public function buildView(FormView $view, FormInterface $form, array $options) { $configs = $options['configs']; $data = $form->getViewData(); if (!empty($data)) { if (!$data instanceof Image) { $data = new Image($form->getConfig()->getAttribute('rootDir') . '/' . $data); } if ($data->hasThumbnail($this->selected)) { $thumbnail = $data->getThumbnail($this->selected); $view->vars['thumbnail'] = array('file' => $configs['folder'] . '/' . $thumbnail->getFilename(), 'width' => $thumbnail->getWidth(), 'height' => $thumbnail->getHeight()); } $value = $configs['folder'] . '/' . $data->getFilename(); $view->vars = array_replace($view->vars, array('value' => $value, 'file' => $value, 'width' => $data->getWidth(), 'height' => $data->getHeight())); } $view->vars['filters'] = $this->filters; }
/** * {@inheritdoc} */ public function buildView(FormView $view, FormInterface $form, array $options) { $datas = json_decode($form->getViewData(), true); $value = ''; if (!empty($datas)) { if ($options['multiple']) { foreach ($datas as $data) { $value .= $data['label'] . ', '; } } else { $value = $datas['label']; } } $view->vars = array_replace($view->vars, array('autocompleter_value' => $value, 'route_name' => $options['route_name'], 'free_values' => $options['free_values'])); // Adds a custom block prefix array_splice($view->vars['block_prefixes'], array_search($this->getName(), $view->vars['block_prefixes']), 0, 'genemu_jqueryautocompleter'); }
/** * {@inheritdoc} */ public function buildView(FormViewInterface $view, FormInterface $form, array $options) { $name = $form->getName(); $blockName = $options['block_name'] ?: $form->getName(); $readOnly = $options['read_only']; $translationDomain = $options['translation_domain']; if ($view->hasParent()) { if ('' === $name) { throw new FormException('Form node with empty name can be used only as root form node.'); } $parentView = $view->getParent(); if ('' !== ($parentFullName = $parentView->getVar('full_name'))) { $id = sprintf('%s_%s', $parentView->getVar('id'), $name); $fullName = sprintf('%s[%s]', $parentFullName, $name); $fullBlockName = sprintf('%s_%s', $parentView->getVar('full_block_name'), $blockName); } else { $id = $name; $fullName = $name; $fullBlockName = '_' . $blockName; } // Complex fields are read-only if they themselves or their parents are. if (!$readOnly) { $readOnly = $parentView->getVar('read_only'); } if (!$translationDomain) { $translationDomain = $parentView->getVar('translation_domain'); } } else { $id = $name; $fullName = $name; $fullBlockName = '_' . $blockName; // Strip leading underscores and digits. These are allowed in // form names, but not in HTML4 ID attributes. // http://www.w3.org/TR/html401/struct/global.html#adef-id $id = ltrim($id, '_0123456789'); } $types = array(); for ($type = $form->getConfig()->getType(); null !== $type; $type = $type->getParent()) { array_unshift($types, $type->getName()); } if (!$translationDomain) { $translationDomain = 'messages'; } $view->addVars(array('form' => $view, 'id' => $id, 'name' => $name, 'full_name' => $fullName, 'full_block_name' => $fullBlockName, 'read_only' => $readOnly, 'errors' => $form->getErrors(), 'valid' => $form->isBound() ? $form->isValid() : true, 'value' => $form->getViewData(), 'disabled' => $form->isDisabled(), 'required' => $form->isRequired(), 'max_length' => $options['max_length'], 'pattern' => $options['pattern'], 'size' => null, 'label' => $options['label'], 'multipart' => false, 'attr' => $options['attr'], 'label_attr' => $options['label_attr'], 'compound' => $form->getConfig()->getCompound(), 'types' => $types, 'translation_domain' => $translationDomain)); }
/** * {@inheritdoc} */ public function buildView(FormView $view, FormInterface $form, array $options) { $datas = json_decode($form->getViewData(), true); $value = ''; if (!empty($datas)) { if ($options['multiple']) { foreach ($datas as $data) { $value .= $data['label'] . ', '; } } else { $value = $datas['label']; } } $view->vars['tokeninput_value'] = $value; $view->vars['configs'] = $options['configs']; $view->vars['route_name'] = $form->getConfig()->getAttribute('route_name'); array_splice($view->vars['block_prefixes'], array_search($this->getName(), $view->vars['block_prefixes']), 0, 'genemu_jquerytokeninput'); }
/** * {@inheritdoc} */ public function buildView(FormViewInterface $view, FormInterface $form, array $options) { $datas = json_decode($form->getViewData(), true); $value = ''; if (!empty($datas)) { if ($options['multiple']) { foreach ($datas as $data) { $value .= $data['label'] . ', '; } } else { $value = $datas['label']; } } $choices = array(); foreach ($view->getVar('choices') as $choice) { $choices[] = array('value' => $choice->getValue(), 'label' => $choice->getLabel()); } $view->setVar('choices', $choices)->setVar('autocompleter_value', $value)->setVar('route_name', $options['route_name'])->setVar('free_values', $options['free_values'])->setVar('full_block_name', 'genemu_jqueryautocompleter'); }
public function buildView(FormView $view, FormInterface $form, array $options) { $value = $form->getViewData(); $view->vars['uniqid'] = uniqid(); $view->vars['show_add'] = $options['show_add']; $view->vars['show_edit'] = $options['show_edit']; $view->vars['list_label'] = $options['list_label']; $view->vars['add_label'] = $options['add_label']; $view->vars['edit_label'] = $options['edit_label']; $view->vars['admin'] = $options['admin']; $view->vars['admin_name'] = $options['admin_name']; if (is_numeric($value)) { $contact = $this->em->getRepository($options['entity'])->find($value); if (is_object($contact)) { $view->vars['object'] = $contact; } else { throw new \Exception('Unknown entity'); } } }
/** * {@inheritdoc} */ public function buildView(FormView $view, FormInterface $form, array $options) { $value = $form->getViewData(); // set string representation if (true === $value) { $value = 'true'; } elseif (false === $value) { $value = 'false'; } elseif (null === $value) { $value = 'null'; } elseif (is_array($value)) { $value = implode(', ', $value); } elseif ($value instanceof \DateTime) { $dateFormat = is_int($options['date_format']) ? $options['date_format'] : DateType::DEFAULT_FORMAT; $timeFormat = is_int($options['time_format']) ? $options['time_format'] : DateType::DEFAULT_FORMAT; $calendar = \IntlDateFormatter::GREGORIAN; $pattern = is_string($options['date_pattern']) ? $options['date_pattern'] : null; $formatter = new \IntlDateFormatter(\Locale::getDefault(), $dateFormat, $timeFormat, 'UTC', $calendar, $pattern); $formatter->setLenient(false); $value = $formatter->format($value); } elseif (is_object($value)) { /* if (method_exists($value, '__toString')) { $value = $value->__toString(); } else { $value = get_class($value); }*/ } $view->vars['value'] = $value; $view->vars['value_type'] = ''; if (is_object($value)) { $view->vars['value_class'] = get_class($value); if ($value instanceof Media && $this->container->has('sonata.media.twig.extension')) { $view->vars['media_helper'] = $this->container->get('sonata.media.twig.extension'); $view->vars['value_type'] = 'media'; $view->vars['media_format'] = $options['media_format'] ? $options['media_format'] : 'small'; } } }
/** * {@inheritdoc} */ public function buildView(FormViewInterface $view, FormInterface $form, array $options) { $value = $form->getViewData(); // set string representation if (true === $value) { $value = 'true'; } elseif (false === $value) { $value = 'false'; } elseif (null === $value) { $value = 'null'; } elseif (is_array($value)) { $value = implode(', ', $value); } elseif ($value instanceof \DateTime) { $value = $value->format('Y-m-d H:i:s'); } elseif (is_object($value)) { if (method_exists($value, '__toString')) { $value = $value->__toString(); } else { $value = get_class($value); } } $view->setVar('value', (string) $value); }
private function serializeForm(FormInterface $form, $isXml) { if (!$form->all()) { return $form->getViewData(); } $data = array(); $namingStrategy = $this->options->getNamingStrategy(); foreach ($form->all() as $child) { $options = $child->getConfig()->getOptions(); $name = $options['serialize_name'] ?: $namingStrategy->translateName($child); if ($isXml) { $name = !$options['serialize_xml_value'] ? $options['serialize_xml_attribute'] ? '@' . $name : $name : '#'; } if (!$options['serialize_xml_inline'] && $isXml) { $data[$name][$options['serialize_xml_name']] = $this->serializeForm($child, $isXml); } else { $data[$name] = $this->serializeForm($child, $isXml); } } return $data; }
/** * {@inheritdoc} */ public function buildView(FormView $view, FormInterface $form, array $options) { $view->vars = array_replace($view->vars, array('value' => $options['value'], 'checked' => null !== $form->getViewData())); }
/** * {@inheritdoc} */ public function buildView(FormViewInterface $view, FormInterface $form, array $options) { $view->setVar('type', 'hidden')->setVar('value', $form->getViewData())->setVar('multiple', $options['multiple'])->setVar('configs', $options['configs']); }
/** * @param FormView $view * @param FormInterface $form * @param array $options */ public function buildView(FormView $view, FormInterface $form, array $options) { $formData = $form->getViewData(); $view->vars['attr']['data-selected-data'] = $formData; }
/** End Garantie Entity **/ protected function getErrorsAsString($fields, $class, $admin, \Symfony\Component\Form\FormInterface $form, $line, $level = 0, $field = '', $message = null) { $errors = array(); if ($form->getErrors()) { $one_view = array(); foreach ($form->getErrors() as $keys => $error) { if (!isset($one_view[$field][$line])) { $one_view[$field][$line] = true; $repeat = str_repeat(' ', $level); $label = isset($fields[$field]) ? '(' . (\PHPExcel_Cell::stringFromColumnIndex($fields[$field]) . ':' . $line) . ') ' : ''; $data = $form->getViewData(); if (is_array($data)) { $data = implode('-', $data); } if ($error->getMessageParameters()) { $data = implode($error->getMessageParameters()); } $errors[] = $repeat . 'VALUE : ' . $label . ($data ?: 'empty') . "\n"; $errors[] = $repeat . 'ERROR : ' . $error->getMessage() . "\n\n"; } } } foreach ($form->getChildren() as $field => $child) { if ($field == 'client') { continue; } if ($err = $this->getErrorsAsString($fields, $class, $admin, $child, $line, $level + 4, $field, null)) { $errors[] = $admin->trans('form.' . $class . '.' . $field) . "\n"; $errors[] = $err; } } if (!empty($message)) { $errors[] = $message; } return implode($errors); }
/** * (non-PHPdoc) * @see \Symfony\Component\Form\AbstractType::buildView() */ public function buildView(FormView $view, FormInterface $form, array $options) { $view->vars['value'] = $this->transform($form->getViewData(), $options); }
/** * {@inheritdoc} */ public function buildView(FormView $view, FormInterface $form, array $options) { $name = $form->getName(); $blockName = $options['block_name'] ?: $form->getName(); $readOnly = $options['read_only']; $translationDomain = $options['translation_domain']; if ($view->parent) { if ('' === $name) { throw new Exception('Form node with empty name can be used only as root form node.'); } if ('' !== ($parentFullName = $view->parent->vars['full_name'])) { $id = sprintf('%s_%s', $view->parent->vars['id'], $name); $fullName = sprintf('%s[%s]', $parentFullName, $name); $uniqueBlockPrefix = sprintf('%s_%s', $view->parent->vars['unique_block_prefix'], $blockName); } else { $id = $name; $fullName = $name; $uniqueBlockPrefix = '_' . $blockName; } // Complex fields are read-only if they themselves or their parents are. if (!$readOnly) { $readOnly = $view->parent->vars['read_only']; } if (!$translationDomain) { $translationDomain = $view->parent->vars['translation_domain']; } } else { $id = $name; $fullName = $name; $uniqueBlockPrefix = '_' . $blockName; // Strip leading underscores and digits. These are allowed in // form names, but not in HTML4 ID attributes. // http://www.w3.org/TR/html401/struct/global.html#adef-id $id = ltrim($id, '_0123456789'); } $blockPrefixes = array(); for ($type = $form->getConfig()->getType(); null !== $type; $type = $type->getParent()) { array_unshift($blockPrefixes, $type->getName()); } $blockPrefixes[] = $uniqueBlockPrefix; if (!$translationDomain) { $translationDomain = 'messages'; } $view->vars = array_replace($view->vars, array( 'form' => $view, 'id' => $id, 'name' => $name, 'full_name' => $fullName, 'read_only' => $readOnly, 'errors' => $form->getErrors(), 'valid' => $form->isBound() ? $form->isValid() : true, 'value' => $form->getViewData(), 'data' => $form->getNormData(), 'disabled' => $form->isDisabled(), 'required' => $form->isRequired(), 'max_length' => $options['max_length'], 'pattern' => $options['pattern'], 'size' => null, 'label' => $options['label'], 'multipart' => false, 'attr' => $options['attr'], 'label_attr' => $options['label_attr'], 'compound' => $form->getConfig()->getCompound(), 'block_prefixes' => $blockPrefixes, 'unique_block_prefix' => $uniqueBlockPrefix, 'translation_domain' => $translationDomain, // Using the block name here speeds up performance in collection // forms, where each entry has the same full block name. // Including the type is important too, because if rows of a // collection form have different types (dynamically), they should // be rendered differently. // https://github.com/symfony/symfony/issues/5038 'cache_key' => $uniqueBlockPrefix . '_' . $form->getConfig()->getType()->getName(), )); }
protected function defaultValueFrom(FormInterface $form) { return $form->getViewData(); }
/** * {@inheritdoc} */ public function buildView(FormView $view, FormInterface $form, array $options) { //@TODO a renommer $view->vars['display_filter'] = $form->isValid() && count(array_filter($form->getViewData())) > 0; }
/** * {@inheritdoc} */ public function buildView(FormViewInterface $view, FormInterface $form, array $options) { $view->addVars(array('value' => $options['value'], 'checked' => null !== $form->getViewData())); }
/** * {@inheritdoc} */ public function finishView(FormView $view, FormInterface $form, array $options) { // Make sure that the view values are set properly, so that, for // example, the JSON input is updated to the data from the plain-text // input (allowing the client to switch JS on and off arbitrarily) foreach ($view->children as &$child) { $name = $child->vars['name']; // TODO: Show the old value to the user when needed to correct // errors if (isset($form->getViewData()[$name])) { $child->vars['value'] = $form->getViewData()[$name]; } } $view->vars['attr']['data-multiple'] = $this->multiple ? '1' : '0'; $view->vars['attr']['data-types'] = implode(',', $this->types); }
/** * {@inheritdoc} */ public function buildView(FormView $view, FormInterface $form, array $options) { $view->vars = array_replace($view->vars, array('type' => 'hidden', 'value' => $form->getViewData(), 'multiple' => $options['multiple'], 'configs' => $options['configs'])); }