本文整理汇总了PHP中Symfony\Component\Form\FormInterface::getAttribute方法的典型用法代码示例。如果您正苦于以下问题:PHP FormInterface::getAttribute方法的具体用法?PHP FormInterface::getAttribute怎么用?PHP FormInterface::getAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Form\FormInterface
的用法示例。
在下文中一共展示了FormInterface::getAttribute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: buildView
/**
* @param \Symfony\Component\Form\FormView $view
* @param \Symfony\Component\Form\FormInterface $form
*/
public function buildView(FormView $view, FormInterface $form)
{
$sonataAdmin = $form->getAttribute('sonata_admin');
// avoid to add extra information not required by non admin field
if ($form->getAttribute('sonata_admin_enabled', true)) {
$sonataAdmin['value'] = $form->getData();
// add a new block types, so the Admin Form element can be tweaked based on the admin code
$types = $view->get('types');
$baseName = str_replace('.', '_', $sonataAdmin['field_description']->getAdmin()->getCode());
$baseType = $types[count($types) - 1];
$types[] = sprintf('%s_%s', $baseName, $baseType);
$types[] = sprintf('%s_%s_%s', $baseName, $sonataAdmin['field_description']->getName(), $baseType);
if ($sonataAdmin['block_name']) {
$types[] = $sonataAdmin['block_name'];
}
$view->set('types', $types);
$view->set('sonata_admin_enabled', true);
$view->set('sonata_admin', $sonataAdmin);
$attr = $view->get('attr', array());
if (!isset($attr['class'])) {
$attr['class'] = $sonataAdmin['class'];
}
$view->set('attr', $attr);
} else {
$view->set('sonata_admin_enabled', false);
}
$view->set('sonata_admin', $sonataAdmin);
}
示例2: 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);
}
示例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
/**
* {@inheritdoc}
*/
public function buildView(FormViewInterface $view, FormInterface $form, array $options)
{
$configs = $form->getAttribute('configs');
$datas = $form->getClientData();
if (!empty($datas)) {
if ($form->getAttribute('multiple')) {
$datas = is_scalar($datas) ? explode(',', $datas) : $datas;
$value = array();
foreach ($datas as $data) {
if (!$data instanceof File) {
$data = new File($form->getAttribute('rootDir') . '/' . $data);
}
$value[] = $configs['folder'] . '/' . $data->getFilename();
}
$value = implode(',', $value);
} else {
if (!$datas instanceof File) {
$datas = new File($form->getAttribute('rootDir') . '/' . $datas);
}
$value = $configs['folder'] . '/' . $datas->getFilename();
}
$view->set('value', $value);
}
$view->set('type', 'hidden')->set('configs', $form->getAttribute('configs'));
}
示例5: buildView
public function buildView(FormView $view, FormInterface $form, array $options)
{
$view->set('parent_field', $form->getAttribute('parent_field'));
$view->set('entity_alias', $form->getAttribute('entity_alias'));
$view->set('no_result_msg', $form->getAttribute('no_result_msg'));
$view->set('empty_value', $form->getAttribute('empty_value'));
}
示例6: validate
public function validate(FormInterface $form)
{
if (!$form->isSynchronized()) {
$form->addError(new FormError(
$form->getAttribute('invalid_message_template'),
$form->getAttribute('invalid_message_parameters')
));
}
if (count($form->getExtraData()) > 0) {
$form->addError(new FormError('This form should not contain extra fields'));
}
if ($form->isRoot() && isset($_SERVER['CONTENT_LENGTH'])) {
$length = (int) $_SERVER['CONTENT_LENGTH'];
$max = trim(ini_get('post_max_size'));
if ('' !== $max) {
switch (strtolower(substr($max, -1))) {
// The 'G' modifier is available since PHP 5.1.0
case 'g':
$max *= 1024;
case 'm':
$max *= 1024;
case 'k':
$max *= 1024;
}
if ($length > $max) {
$form->addError(new FormError('The uploaded file was too large. Please try to upload a smaller file'));
}
}
}
}
示例7: buildView
/**
* {@inheritdoc}
*/
public function buildView(FormView $view, FormInterface $form)
{
$view->set('widget', $form->getAttribute('widget'));
if ('single_text' === $form->getAttribute('widget')) {
$view->set('type', 'datetime');
}
}
示例8: finishView
public function finishView(FormView $view, FormInterface $form, array $options)
{
$view->setAttribute('data-date', Util::ICUTojQueryDate($form->getAttribute('date_pattern')));
$timePattern = $form->getAttribute('time_pattern');
$view->setAttribute('data-time', Util::ICUTojQueryDate($timePattern));
$view->setAttribute('data-ampm', false !== strpos($timePattern, 'h') ? '1' : '0');
}
示例9: buildView
/**
* {@inheritdoc}
*/
public function buildView(FormView $view, FormInterface $form)
{
$view->set('allow_add', $form->getAttribute('allow_add'))->set('allow_delete', $form->getAttribute('allow_delete'));
if ($form->hasAttribute('prototype')) {
$view->set('prototype', $form->getAttribute('prototype')->createView($view));
}
}
示例10: buildView
/**
* {@inheritdoc}
*/
public function buildView(FormView $view, FormInterface $form)
{
$choiceList = $form->getAttribute('choice_list');
$view->set('multiple', $form->getAttribute('multiple'))->set('expanded', $form->getAttribute('expanded'))->set('preferred_choices', $choiceList->getPreferredViews())->set('choices', $choiceList->getRemainingViews())->set('separator', '-------------------')->set('empty_value', $form->getAttribute('empty_value'));
if ($view->get('multiple') && !$view->get('expanded')) {
// Add "[]" to the name in case a select tag with multiple options is
// displayed. Otherwise only one of the selected options is sent in the
// POST request.
$view->set('full_name', $view->get('full_name') . '[]');
}
}
示例11: buildView
/**
* {@inheritdoc}
*/
public function buildView(FormView $view, FormInterface $form)
{
$configs = $form->getAttribute('configs');
$year = $form->getAttribute('years');
$configs['dateFormat'] = 'yy-mm-dd';
if ('single_text' === $form->getAttribute('widget')) {
$formatter = $form->getAttribute('formatter');
$configs['dateFormat'] = $this->getJavascriptPattern($formatter);
}
$view->set('min_year', min($year))->set('max_year', max($year))->set('configs', $configs)->set('culture', $form->getAttribute('culture'));
}
示例12: buildView
/**
* {@inheritdoc}
*/
public function buildView(FormView $view, FormInterface $form, array $options)
{
$choiceList = $form->getAttribute('choice_list');
// We should not load anything right now when loading via ajax
$view->set('multiple', $form->getAttribute('multiple'))->set('expanded', $form->getAttribute('expanded'))->set('preferred_choices', array())->set('choices', array())->set('separator', '-------------------')->set('empty_value', $form->getAttribute('empty_value'));
if ($view->get('multiple') && !$view->get('expanded')) {
// Add "[]" to the name in case a select tag with multiple options is
// displayed. Otherwise only one of the selected options is sent in the
// POST request.
$view->set('full_name', $view->get('full_name') . '[]');
}
}
示例13: buildView
public function buildView(FormView $view, FormInterface $form)
{
$choices = $form->getAttribute('choice_list')->getChoices();
$preferred = array_flip($form->getAttribute('preferred_choices'));
$view->set('multiple', $form->getAttribute('multiple'))->set('expanded', $form->getAttribute('expanded'))->set('preferred_choices', array_intersect_key($choices, $preferred))->set('choices', array_diff_key($choices, $preferred))->set('separator', '-------------------')->set('empty_value', '');
if ($view->get('multiple') && !$view->get('expanded')) {
// Add "[]" to the name in case a select tag with multiple options is
// displayed. Otherwise only one of the selected options is sent in the
// POST request.
$view->set('full_name', $view->get('full_name') . '[]');
}
}
示例14: 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));
}
}
示例15: mapFormToData
public function mapFormToData(FormInterface $form, &$data)
{
if ($form->getAttribute('property_path') !== null && $form->isSynchronized()) {
$propertyPath = $form->getAttribute('property_path');
// If the data is identical to the value in $data, we are
// dealing with a reference
$isReference = $form->getData() === $propertyPath->getValue($data);
$byReference = $form->getAttribute('by_reference');
if (!(is_object($data) && $isReference && $byReference)) {
$propertyPath->setValue($data, $form->getData());
}
}
}