Download the PHP package ninsuo/symfony-collection without Composer

On this page you can find all versions of the php package ninsuo/symfony-collection. 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 symfony-collection

symfony-collection

A jQuery plugin that manages adding, deleting and moving elements from a Symfony collection

sample

This is not really difficult to manage your collections using the data-prototype Symfony provides. But after using several times collections, it appeared useful to me to create a jQuery plugin to do this job.

This is even more true when you need your elements to be moved up and down or added at a specific position: as the form will be proceeded using field names, we should swap field contents or field names instead of moving fields themselves to get the job done. That's not really friendly in javascript, so this plugin also aims to deal with that.

Live demo

Demo of this plugin is available live at: http://symfony-collection.fuz.org

Demo source code is here: https://github.com/ninsuo/symfony-collection-demo

Installation

This plugin is a set of 2 files:

Installation using Composer

To automate the plugin download and installation, edit composer.json and add:

Files will be automatically installed at:

Tips:

If you prefer to install the plugin manually, you can use:

You'll have to move:

Installation using npm

You'll have to move:

Installation using Bower

You'll have to move:

Basic usage

A simple collection

Your collection type should contain prototype, allow_add, allow_remove options (depending on which buttons you require of course). And a class that will be used as a selector to run the collection plugin.

Then, render your form after applying the given custom theme:

Finally, put the following code at the bottom of your page.

Using a form theme

Most of the time, you will need to create a form theme that will help you render your collection and its children in a fancy way.

Then, use both form themes using:

There are many examples using form themes in the Advanced menu of the demo website, don't hesitate to look at them.

Always put jquery.collection.html.twig form theme below the other you use, to avoid the settings getting overwritten.

Using Doctrine, and a position explicitly stored in a field

A collection is no more than an array of objects, so by default, this plugin move element positions in this array. For example, if you have A, B and C in your collection and move B up, it will contain B, A, C.

But when Doctrine persists your collection, it will keep existing entities, and simply update their content. For example, if you have a collection containing A, B, C with ids 1, 2 and 3, you will end up with a collection containing B, A, C, but still ids 1, 2 and 3.

In most cases, that's not a problem. But, if you have other relations attached to each of your collection elements, you should never unlink id and value. You'll use a position field on your database table, and it will manage the position.

Something like:

This plugin supports this case; you need to create a position field in your form (with hidden type), mapped to your entity, and give it a class that will serve as a selector:

Then, use the position_field_selector option to provide it to the plugin:

Several collections on the same page

If you wish to create several collections on the same page, you'll need to change the collection prefix in order for the plugin to trigger the right actions for the right collection.

For example:

Then if you want to edit those collections form theme, you'll need to replace collection-add by first-collection-add on your add buttons for example.

See this sample for a working example.

Options

Customize rendered links (demo)

You can customize displayed links by setting up, down, add, remove and duplicate options.

Default values are:

You can also use the following classes:

And:

Note that collection prefix can be changed using the prefix option.

Disable links (demo)

You can disable some buttons by using allow_up, allow_down, allow_add, allow_remove and allow_duplicate options. By default, all buttons except duplicate are enabled.

For example, if you do not want your elements to be moved up and down, use:

If you are using the given form theme, allow_add, allow_remove and allow_duplicate are automatically set following your form type configuration.

Set minimum and maximum of elements in the collection (demo)

You can set the minimum of elements allowed in the collection by using the min option. By default, it is disabled (set to 0).

You can set the maximum of elements allowed in the collection by using the max option. By default, it is set to 100.

You can initialize your collection with a minimum of elements created (even if they do not exist on the data object) (demo).

Only one add button at the bottom (demo)

If you prefer having only one add button at the bottom of the collection instead of one add button per collection element, use the add_at_the_end option:

Customise add button location (demo)

If you want to set a specific location for your add button (not close to each collection element, nor at the bottom of the collection), you can use the custom_add_location option.

JS:

HTML:

Hide useless buttons (demo)

By default, move up button is hidden on the first item, and move down button on the last one. You can make them appear anyway by setting hide_useless_buttons to false. This can be useful if you want to beautify them using CSS, for example.

Events (demo)

There are before_* and after_* options that let you put callbacks before and after adding, deleting or moving elements in the collection.

Callback functions receive two arguments:

Using the plugin without form theme (demo)

The form theme aims to reduce the number of options required when activating the plugin. This is really useful when you are dealing with collections of form collections. But you can still do it manually if you want, using the following equivalents:

Note that only name_prefix option is mandatory, all other ones have default values.

Fade in & Fade out support (demo)

By default, when adding or removing an element, fade animation will make element movements smoother. You can still disable this option by using fade_in and fade_out options.

Drag & drop support (demo)

If you are using Jquery UI and have the sortable component available in your application, the drag_drop option is automatically enabled and let you change your element positions using drag & drop. You can disable this behaviour by explicitly setting drag_drop option to false.

If required, you can customize sortable by overloading options given to jQuery.ui.sortable using the drag_drop_options option.

By default, your collection is initialized with the following options:

Note that you should not overload start and update callbacks as they are used by this plugin, see drag_drop_start and drag_drop_update options in advanced usage below for more details.

Change the children selector

By default, Symfony writes each element of a collection in a div below the collection itself. So this plugin considers > div as a default value to get collection elements. But, you may need to display each element of your collection in a table, so you can change this value.

You may use > tr, thead > tr or more specifically tr.item or just .item if you set class="item" at the top of your item's form theme. The goal is to reference each item in the collection whatever the markup.

Change the parent selector

To be able to add elements to the collection, this plugin should be aware of the dom object that will contain them.

By default, your collection elements will be located just below your collection, for example:

But you may need to put elements deeper in the dom, for example when you put elements in a table:

In that example, a parent selector should be table.collection tbody.

Note that you can use %id% inside elements_parent_selector, it will be automatically replaced by the collection's id. This is particularly useful when you're dealing with nested collections.

Example:

Default value:

Do not change field names

Symfony uses field names to order the collection, not the position of each element on the dom. So by default, if you delete an element in the middle, all following elements will have their index decreased of 1 (field[3] will become field[2] and so on) and if you add some elements in the middle, all subsequent elements will see their index increase to leave the space for the new one.

With this implementation, you're sure to keep the right positions when clicking "move up" and "move down" for example. But in some situations, you may not want to overwrite indexes, most probably to maintain Doctrine relationships.

Set the preserve_names option to true to never touch field names. But be aware that this option will disable allow_up, allow_down, drag_drop options and will enforce add_at_the_end to true.

Default value:

Changing the action container tag

By default, without form theme, all actions are put inside a <div>. You can overwrite this by setting the action_container_tag option, for example if you want to put actions in a <td> instead.

Default value:

Advanced usage

Changing action's positions (demo)

By default :

You can change those button's positions by creating them manually anywhere in your form theme.

You can use any custom clickable element as soon has it has one action class:

Warning: collection is taken from the prefix option: if you change the plugin's prefix, you should change this class too.

Example:

If we have a collection of text fields and want to display actions at the right side of each value instead of below, we will use something like this:

Note : do not forget to set the add option when enabling the plugin, because if your collection is emptied, the plugin will generate an add button based on the plugin's configuration.

Tip: when add buttons are put inside the collection's elements, a new element is created next to the clicked element instead of at the end of the collection.

Advanced drag & drop support (demo)

If you need to listen for start and/or update events from jQuery.ui.sortable in your collection, you should not overload the start and update options in drag_drop_options, but use the built-in drag_drop_start and drag_drop_update options instead:

Notes:

Collection of collections (demo)

This plugin has the ability to manage a collection of form collections, but to avoid collisions, you should:

In your form type:

In the plugin options:


All versions of symfony-collection with dependencies

PHP Build Version
Package Version
No informations.
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 ninsuo/symfony-collection contains the following files

Loading the files please wait ....