Download the PHP package bugo/smf-bricks without Composer
On this page you can find all versions of the php package bugo/smf-bricks. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download bugo/smf-bricks
More information about bugo/smf-bricks
Files in bugo/smf-bricks
Package smf-bricks
Short Description Collection of some building blocks for SMF
License MIT
Homepage https://github.com/dragomano/SMF-Bricks
Informations about the package smf-bricks
SMF Bricks
По-русски
These helpers will be useful for simplifying the code of tables and forms when creating modifications to Simple Machines Forum.
Installing
In the root directory of your modification, run the command:
Then, include autoload.php
in your code:
Tables
The simple table builder TableBuilder::make()
— you just need to provide the data, and you'll get a table styled like on the forum:
Anyone who has ever set up a table structure in SMF 2.1 knows that you first create an array called $listOptions
with the key settings. This array looks bigger the more columns you need to include in it:
So how can you create such a structure using TableBuilder
? Thanks to the fluent interface
, it's very elegant and simple:
We build with the builder, and with the presenter, we display what we've built:
Instead of the universal method withParams
, there are also more specific ones: paginate
, setNoItemsLabel
, setFormAction
, and setDefaultSortColumn
.
Columns are created using Column::make()
:
There are also several child methods that inherit from Column
: IdColumn
, CheckboxColumn
. You can easily create similar ones for your projects. For example, IdColumn
is just a wrapper for a structure like:
When adding multiple columns, you can use the method addColumns([Column::make(), Column::make(), ...])
, which accepts an array of Column
instances.
You can also add buttons ABOVE or BELOW the table using the methods addRows([Row::make($button1), Row::make($button2)])
or addRow(Row::make($button))
, where Row::make
accepts text or HTML. The position of the buttons can be changed using the setPosition
method, which takes one of the values from the RowPosition
enumeration. By default, the buttons are displayed below the table.
Forms
What could be more interesting than building all sorts of forms, especially in SMF? Of course, creating and using a FormBuilder
for such forms:
You can add form fields in a container (by specifying the block class as the second parameter):
Or without it:
You can add your own buttons at the bottom of the form, specifying a class for the container as well as a class for all buttons inside the container:
You can also add hidden fields:
Of course, there is a dedicated presenter for FormBuilder
— FormPresenter
, designed to display the built forms in the browser:
Settings
We’re excited to share some good news for those who find working with arrays while creating settings a bit tedious. For instance, the Light Portal settings block on the "Miscellaneous" tab was previously built like this:
Now, thanks to ConfigBuilder
and a set of child classes from AbstractConfig
, everything looks much more interesting:
More usage examples can be found in the tests, as well as in the Light Portal project.