當前位置: 首頁>>代碼示例>>PHP>>正文


PHP FormInterface::getViewData方法代碼示例

本文整理匯總了PHP中Symfony\Component\Form\FormInterface::getViewData方法的典型用法代碼示例。如果您正苦於以下問題:PHP FormInterface::getViewData方法的具體用法?PHP FormInterface::getViewData怎麽用?PHP FormInterface::getViewData使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Symfony\Component\Form\FormInterface的用法示例。


在下文中一共展示了FormInterface::getViewData方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: extractSubmittedData

 /**
  * {@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;
 }
開發者ID:xingshanghe,項目名稱:symfony,代碼行數:34,代碼來源:FormDataExtractor.php

示例2: extractSubmittedData

 /**
  * {@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;
 }
開發者ID:TuxCoffeeCorner,項目名稱:tcc,代碼行數:18,代碼來源:FormDataExtractor.php

示例3: buildView

 /**
  * {@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);
 }
開發者ID:hexmedia,項目名稱:content-bundle,代碼行數:18,代碼來源:MediaType.php

示例4: buildView

 /**
  * {@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;
 }
開發者ID:GeneralMediaCH,項目名稱:GenemuFormBundle,代碼行數:32,代碼來源:PlainType.php

示例5: serializeForm

 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;
 }
開發者ID:enhavo,項目名稱:enhavo,代碼行數:12,代碼來源:FormSerializer.php

示例6: extractSubmittedData

 /**
  * {@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;
 }
開發者ID:NivalM,項目名稱:VacantesJannaMotors,代碼行數:25,代碼來源:FormDataExtractor.php

示例7: getViewData

 /**
  * {@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;
 }
開發者ID:ayoah,項目名稱:symfony,代碼行數:16,代碼來源:Form.php

示例8: buildView

 /**
  * {@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;
 }
開發者ID:sasedev,項目名稱:alluco,代碼行數:18,代碼來源:PlainTextType.php

示例9: unbind

 /**
  * 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;
     }
 }
開發者ID:noglitchyo,項目名稱:pim-community-dev,代碼行數:22,代碼來源:PatchSubscriber.php

示例10: buildView

 /**
  * {@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;
 }
開發者ID:Imatic,項目名稱:GenemuFormBundle,代碼行數:20,代碼來源:ImageType.php

示例11: buildView

 /**
  * {@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');
 }
開發者ID:GeneralMediaCH,項目名稱:GenemuFormBundle,代碼行數:20,代碼來源:AutocompleterType.php

示例12: buildView

 /**
  * {@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));
 }
開發者ID:nathanlon,項目名稱:symfony,代碼行數:48,代碼來源:FormType.php

示例13: buildView

 /**
  * {@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');
 }
開發者ID:GeneralMediaCH,項目名稱:GenemuFormBundle,代碼行數:21,代碼來源:TokeninputType.php

示例14: buildView

 /**
  * {@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');
 }
開發者ID:ruipenso,項目名稱:GenemuFormBundle,代碼行數:22,代碼來源:AutocompleterType.php

示例15: buildView

 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');
         }
     }
 }
開發者ID:sgh1986915,項目名稱:symfony-tsk,代碼行數:20,代碼來源:ContactSearchType.php


注:本文中的Symfony\Component\Form\FormInterface::getViewData方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。