本文整理汇总了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;
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
}
示例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;
}
示例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');
}
示例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));
}
示例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');
}
示例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');
}
示例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');
}
}
}