本文整理汇总了PHP中Symfony\Component\Form\FormView::hasParent方法的典型用法代码示例。如果您正苦于以下问题:PHP FormView::hasParent方法的具体用法?PHP FormView::hasParent怎么用?PHP FormView::hasParent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Form\FormView
的用法示例。
在下文中一共展示了FormView::hasParent方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: buildView
/**
* {@inheritdoc}
*/
public function buildView(FormView $view, FormInterface $form)
{
$view->set('value', $form->getAttribute('value'))->set('checked', (bool) $form->getClientData());
if ($view->hasParent()) {
$view->set('full_name', $view->getParent()->get('full_name'));
}
}
示例2: buildView
/**
* {@inheritdoc}
*/
public function buildView(FormView $view, FormInterface $form)
{
$name = $form->getName();
$readOnly = $form->getAttribute('read_only');
if ($view->hasParent()) {
if ('' === $name) {
throw new FormException('Form node with empty name can be used only as root form node.');
}
if ('' !== ($parentFullName = $view->getParent()->get('full_name'))) {
$id = sprintf('%s_%s', $view->getParent()->get('id'), $name);
$fullName = sprintf('%s[%s]', $parentFullName, $name);
} else {
$id = $name;
$fullName = $name;
}
// Complex fields are read-only if themselves or their parent is.
$readOnly = $readOnly || $view->getParent()->get('read_only');
} else {
$id = $name;
$fullName = $name;
// 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();
foreach ($form->getTypes() as $type) {
$types[] = $type->getName();
}
$view->set('form', $view)->set('id', $id)->set('name', $name)->set('full_name', $fullName)->set('read_only', $readOnly)->set('errors', $form->getErrors())->set('value', $form->getClientData())->set('disabled', $form->isDisabled())->set('required', $form->isRequired())->set('max_length', $form->getAttribute('max_length'))->set('pattern', $form->getAttribute('pattern'))->set('size', null)->set('label', $form->getAttribute('label'))->set('multipart', false)->set('attr', $form->getAttribute('attr'))->set('types', $types)->set('translation_domain', $form->getAttribute('translation_domain'));
}
示例3: buildView
/**
* {@inheritdoc}
*/
public function buildView(FormView $view, FormInterface $form)
{
$name = $form->getName();
if ($view->hasParent()) {
if ('' === $name) {
throw new FormException('Form node with empty name can be used only as root form node.');
}
if ('' !== ($parentFullName = $view->getParent()->get('full_name'))) {
$id = sprintf('%s_%s', $view->getParent()->get('id'), $name);
$fullName = sprintf('%s[%s]', $parentFullName, $name);
} else {
$id = $name;
$fullName = $name;
}
} else {
// If this form node have empty name, set id to `form`
// to avoid rendering `id=""` in html structure
$id = $name ?: 'form';
$fullName = $name;
}
$types = array();
foreach ($form->getTypes() as $type) {
$types[] = $type->getName();
}
$view->set('form', $view)->set('id', $id)->set('name', $name)->set('full_name', $fullName)->set('errors', $form->getErrors())->set('value', $form->getClientData())->set('read_only', $form->isReadOnly())->set('required', $form->isRequired())->set('max_length', $form->getAttribute('max_length'))->set('pattern', $form->getAttribute('pattern'))->set('size', null)->set('label', $form->getAttribute('label'))->set('multipart', false)->set('attr', $form->getAttribute('attr'))->set('types', $types)->set('translation_domain', $form->getAttribute('translation_domain'));
}
示例4: buildView
public function buildView(FormView $view, FormInterface $form)
{
if ($view->hasParent()) {
$parentId = $view->getParent()->get('id');
$parentName = $view->getParent()->get('name');
$id = sprintf('%s_%s', $parentId, $form->getName());
$name = sprintf('%s[%s]', $parentName, $form->getName());
} else {
$id = $form->getName();
$name = $form->getName();
}
$view->set('form', $view);
$view->set('id', $id);
$view->set('name', $name);
$view->set('errors', $form->getErrors());
$view->set('value', $form->getClientData());
$view->set('read_only', $form->isReadOnly());
$view->set('required', $form->isRequired());
$view->set('max_length', $form->getAttribute('max_length'));
$view->set('size', null);
$view->set('label', $form->getAttribute('label'));
$view->set('multipart', false);
$view->set('attr', array());
$types = array();
foreach (array_reverse((array) $form->getTypes()) as $type) {
$types[] = $type->getName();
}
$view->set('types', $types);
}
示例5: buildViewBottomUp
/**
* Removes CSRF fields from all the form views except the root one.
*
* @param FormView $view The form view
* @param FormInterface $form The form
*/
public function buildViewBottomUp(FormView $view, FormInterface $form)
{
if ($view->hasParent() && $form->hasAttribute('csrf_field_name')) {
$name = $form->getAttribute('csrf_field_name');
if (isset($view[$name])) {
unset($view[$name]);
}
}
}
示例6: buildViewBottomUp
/**
* Adds a CSRF field to the root form view.
*
* @param FormView $view The form view
* @param FormInterface $form The form
*/
public function buildViewBottomUp(FormView $view, FormInterface $form)
{
if (!$view->hasParent() && !$form->getAttribute('single_control') && $form->hasAttribute('csrf_field_name')) {
$name = $form->getAttribute('csrf_field_name');
$csrfProvider = $form->getAttribute('csrf_provider');
$intention = $form->getAttribute('csrf_intention');
$factory = $form->getAttribute('csrf_factory');
$data = $csrfProvider->generateCsrfToken($intention);
$csrfForm = $factory->createNamed('hidden', $name, $data, array('property_path' => false));
$view->addChild($csrfForm->createView($view));
}
}
示例7: lookupTemplate
/**
* Returns the name of the template to use to render the block
*
* @param FormView $view The form view
* @param string $block The name of the block
*
* @return string|Boolean The template logical name or false when no template is found
*/
protected function lookupTemplate(FormView $view, $block)
{
$file = $block . '.html.php';
$id = $view->get('id');
if (!isset($this->templates[$id][$block])) {
$template = false;
$themes = $view->hasParent() ? array() : $this->resources;
if (isset($this->themes[$id])) {
$themes = array_merge($themes, $this->themes[$id]);
}
for ($i = count($themes) - 1; $i >= 0; --$i) {
if ($this->engine->exists($templateName = $themes[$i] . ':' . $file)) {
$template = $templateName;
break;
}
}
if (false === $template && $view->hasParent()) {
$template = $this->lookupTemplate($view->getParent(), $block);
}
$this->templates[$id][$block] = $template;
}
return $this->templates[$id][$block];
}
示例8: getMaximumParent
/**
* Get maximum parent.
*
* @param \Symfony\Component\Form\FormView $view
* @return \Symfony\Component\Form\FormView
*/
public function getMaximumParent(FormView $view)
{
while (false !== $view->hasParent()) {
$view = $view->getParent();
}
return $view;
}
示例9: buildView
/**
* {@inheritdoc}
*/
public function buildView(FormView $view, FormInterface $form)
{
if ($view->hasParent()) {
$view->set('full_name', $view->getParent()->get('full_name'));
}
}