定制 victor-codigo/symfony-form-extended 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

victor-codigo/symfony-form-extended

最新稳定版本:v1.1.6

Composer 安装命令:

composer require victor-codigo/symfony-form-extended

包简介

Classes to extend symfony form functionality

README 文档

README

Classes to extend Symfony form functionality.
Adds:

  • Form messages translation
  • Add flash bag messages
  • Uploaded files handler

Prerequisites

  • PHP 8.1
  • Symfony 6.4
  • Doctrine\Common\Collections\Collection

Stack

Usage

  1. Install

    composer require victor-codigo/symfony-form-extended
    
  2. Classes

    • FormFactoryExtended: Its a wrapper for class FormFactoryInterface. Allows to build class FormExtended.
    • FormFactoryExtendedInterface: It is an interface for class FormFactoryExtended.
    • FormExtended: It is a wrapper that extends Form Symfony functionality.
    • FormExtendedInterface: It is an interface for FormExtended class.
    • FormTypeBase: Extends Symfony AbstractType class functionality.
    • FormTypeExtendedInterface: An interface for FormTypeBase

FormFactoryExtended methods:

Adds following methods to interface Symfony\Component\Form\FormFactoryInterface.

Method Description Params Return
__construct creates the builder 1. Symfony\Component\Form\FormFactoryInterface: Symfony form to use
2. Symfony\Contracts\Translation\TranslatorInterface: Symfony translation bundle
3. VictorCodigo\UploadFile\Adapter\UploadFileService: Upload File bundle
4. Symfony\Component\HttpFoundation\RequestStack: Request
VictorCodigo\SymfonyFormExtended\Factory
createNamedExtended creates a VictorCodigo\SymfonyFormExtended\FormFormExtended 1. string: Form name
2. string: Full qualified name form type class
3. string: Translation locale
4. mixed: Form initial data
5. array<string, mixed>: options
VictorCodigo\SymfonyFormExtended\Form\FormExtendedInterface

FormExtended methods:

Adds following methods to interface Symfony\Component\Form\FormInterface.

Method Description Params Return
__construct Creates the form 1. Symfony\Component\Form\FormInterface: Symfony form to use
2. VictorCodigo\SymfonyFormExtended\Form\FormExtendedConstraints: Class to manage form constraints
3. VictorCodigo\SymfonyFormExtended\Form\FormExtendedFields: Class to manage form fields
4. VictorCodigo\SymfonyFormExtended\Form\FormExtendedCsrfToken: Class to manage form CSRF token
5. VictorCodigo\SymfonyFormExtended\Form\FormExtendedUpload: Class to manage form file uploads
6. VictorCodigo\SymfonyFormExtended\Form\FormExtendedMessages: Class to manage form messages
7. string: locale code
VictorCodigo\SymfonyFormExtended\Form\FormExtended
getMessageErrorsTranslated Gets form message errors translated 1. bool: Whether to include errors of child forms as well
2. bool: Whether to flatten the list of errors in case $deep is set to true
Doctrine\Common\Collections\Collection<int, FormMessage>
getMessagesSuccessTranslated Gets form messages, when form validation is successful Doctrine\Common\Collections\Collection<int, FormMessage>
getFlashMessagesData Gets a type of form messages and clears flash from the stack 1. string: Messages type Doctrine\Common\Collections\Collection<int, FormMessage>
getFlashMessages Gets a type of form messages and clears flash from the stack 1. string: Messages type Doctrine\Common\Collections\Collection<int, string>
addFlashMessagesTranslated Adds flash messages to Symfony session flash bag 1. string: Key for success messages
2. string: Key for error messages
3. bool: Whether to include errors of child forms as well
void
getConstraints Gets form constraints as object object
getCsrfToken Gets form CSRF token string
getFormFields Gets form fields with the form name. Ej: form_name[field_name]. If field ends in "[]", is considered as field array 1. array<int, \BackedEnum>: Enum that contains form fields names object
getFormFieldsValues Gets form fields with the field value. 1. array<int, \BackedEnum>: Enum that contains form fields names
2. object: Form data validation class
object
getFormTemplateData Gets general info of the form, ready to use in a template 1. array<int, \BackedEnum>: Enum that contains form fields names VictorCodigo\SymfonyFormExtended\Form\FormTemplateData
uploadFiles Sets up form configuration for files uploaded, and move files to a specific path 1. Symfony\Component\HttpFoundation\Request: Symfony request
2. string: Upload path where files are moved and saved
3. array<int, string>: File names to be removed in the path in the upload path
VictorCodigo\SymfonyFormExtended\Form\FormExtended

Example

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use VictorCodigo\SymfonyFormExtended\Factory\FormFactoryExtendedInterface;

class Controller extends AbstractController
{
    public function __construct(
        private FormFactoryExtendedInterface $formFactoryExtended,
    ) {
    }

    public function __invoke(Request $request): Response
    {
        $form = $this->formFactoryExtended->createNamedExtended('form_name', FormType::class, 'en');

        $form->handleRequest($request);

        if ($form->isSubmitted() && $form->isValid()) {
            $form->uploadFiles($request, '/path/to/upload/files');
        }

        $errorsTranslated = $form->getMessageErrorsTranslated(true);
        $messageSuccess = $form->getMessagesSuccessTranslated();
        $form->addFlashMessagesTranslated('messages_success', 'messages_error', true);
    }
}

统计信息

  • 总下载量: 57
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-02-14