Download the PHP package mezcalito/sylius-file-upload-plugin without Composer

On this page you can find all versions of the php package mezcalito/sylius-file-upload-plugin. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package sylius-file-upload-plugin

Mezcalito Sylius File Upload Plugin

This plugin works almost the same as the standard Sylius images uploading (see How to add images to an entity? from the Sylius Documentation), except that it accepts any kind of file types.

Initially this was proposed as a pull request on Sylius core, but it was declined as it was not backwards compatible with Sylius 1.x (Here is the link to the initial PR), so here it is as a Sylius plugin.

Installation

First require this package with composer

Then add the bundle to your config/bundles.php file

In your config/packages/_sylius.yaml file, add the following

This file defines the gaufrette filesystem and adapter used by the plugin, which you can override.

Usage

This section is an adaptation of the official Sylius documentation about How to add images to an entity ?.

Extending entities with an files field is quite a popular use case. In this cookbook we will present how to add files to the Shipping Method entity.

you can see this sample in test/Application.

1. Create the book class with the FilesAwareInterface

Here we used the FilesAwareTrait which is provided for convenience.

2. Register your book as a resource's model class

We will use the attributes:

3. Create the BookFile class

In the App\Entity namespace place the BookFile class which should look like this:

4. Add the mapping and resource attributes for the BookFile

Your new entity will be saved in the database, therefore it needs a mapping file, where you will set the Book as the owner of the BookFile.

5. Create the book form type

It needs to have the files field as a LiveCollectionType.

Declare the form

In case you need only a single file upload, this can be done in 2 very easy steps.

First, in the code for the form provided above set allow_add and allow_delete to false

Second, in the __construct method of the Book entity you defined earlier add the following:

6. Create the book file form type

Declare the form

7. Create the BookGrid

create the file template field for the grid you can use bin/console make:grid

and the template for files

8. Create the book form twig component

9. Declare the FilesUploadListener service

In order to handle the file upload you need to attach the FilesUploadListener to the Book entity events:

10. Add Book section to menu

11. Validation

Your form so far is working fine, but don't forget about validation. The easiest way is using validation config files under the App/Resources/config/validation folder.

This could look like this for an image e.g.:

or for a PDF e.g.:

This defines the validation constraints for each file entity.

Finally, connect the validation of the ShippingMethod to the validation of each single File Entity:

12. Migration

Do the database migration


All versions of sylius-file-upload-plugin with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
sylius/sylius Version ^v2.0.2
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package mezcalito/sylius-file-upload-plugin contains the following files

Loading the files please wait ....