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


PHP FormInterface::getAttribute方法代碼示例

本文整理匯總了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);
 }
開發者ID:nzzdev,項目名稱:SonataAdminBundle,代碼行數:32,代碼來源:FormTypeFieldExtension.php

示例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);
 }
開發者ID:norwayapp,項目名稱:Invest,代碼行數:29,代碼來源:FieldType.php

示例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'));
 }
開發者ID:rudott,項目名稱:symfony,代碼行數:29,代碼來源:FieldType.php

示例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'));
 }
開發者ID:r4cker,項目名稱:GenemuFormBundle,代碼行數:28,代碼來源:FileType.php

示例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'));
 }
開發者ID:nucleartux,項目名稱:ShtumiUsefulBundle1,代碼行數:7,代碼來源:DependentFilteredEntityType.php

示例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'));
                }
            }
        }
    }
開發者ID:regisg27,項目名稱:symfony,代碼行數:34,代碼來源:DefaultValidator.php

示例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');
     }
 }
開發者ID:nashadalam,項目名稱:symfony,代碼行數:10,代碼來源:DateTimeType.php

示例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');
 }
開發者ID:senthilkumar3282,項目名稱:LyraAdminBundle,代碼行數:7,代碼來源:DateTimePickerType.php

示例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));
     }
 }
開發者ID:realestateconz,項目名稱:symfony,代碼行數:10,代碼來源:CollectionType.php

示例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') . '[]');
     }
 }
開發者ID:rouffj,項目名稱:symfony,代碼行數:14,代碼來源:ChoiceType.php

示例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'));
 }
開發者ID:raziel057,項目名稱:GenemuFormBundle,代碼行數:14,代碼來源:DateType.php

示例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') . '[]');
     }
 }
開發者ID:rodrigopluz,項目名稱:BFOSBrasilBundle,代碼行數:15,代碼來源:AjaxChoiceType.php

示例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') . '[]');
     }
 }
開發者ID:rfc1483,項目名稱:blog,代碼行數:12,代碼來源:ChoiceType.php

示例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));
     }
 }
開發者ID:rikaix,項目名稱:symfony,代碼行數:18,代碼來源:FormTypeCsrfExtension.php

示例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());
         }
     }
 }
開發者ID:laiello,項目名稱:mediathequescrum,代碼行數:13,代碼來源:PropertyPathMapper.php


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