Thelia Network
E-commerce solution

E-commerce software, useful to create and manage online stores, published under a free license. Discover our new version, based on many modern technologies !

Download Thelia
Business

A team of experts at your service.

Showcase

Over 7000 online stores powered by Thelia

Openstudio

Thelia editor.

Our Blog

A new module for Thelia developers

A module has been released for you Thelia developers. It’s called TheliaStudio and it will become your best friend during your Thelia module developments.

Be careful this module is only compatible with Thelia 2.1Visual Cage

This module generates for you all the repetitive things you had to write to create a module for Thelia.
It does two things:

The module brings two new commands:

We’re now going to see how to write correctly the configuration files for generating everything.

This file has a simple skeleton.
First, name the root config, then add your fields by giving their name as key, and their type as value like this:

config:
variable_1: text
variable_2: integer
variable_3: checkbox
variable_4: number

By default, all the fields declared here are mandatory (except the checkboxes), but you can specify more validation on the field.
Here’s an example with all the available validation:

config:
variable_1:
type: text
required: false
regex: “([a-z]+)*\/”
size:
min: 5
max: 20

Now we are done with the module configuration form. Let’s write the model !

As we said above, you have to respect some standards to get everything working.
First: your tables must ALWAYS have an id column, but don’t worry, this is always the same line:

If you already used Thelia, you may have noticed that the tables often have a visible toggle and a position management. With TheliaStudio, this is automatically handled. You just have to declare a column named visible, give it the type BOOLEAN or TINYINT, and everything will be generated for you (the toggle button on the list, the controller and the action that handles the visibility).

It is the same if you call your column position, it will generate the arrows in the list column, the controller and the action.

You have to know that TheliaStudio’s parser analyses the behaviors too, so you don’t have to worry about i18n and timestampable behaviors on the templates, forms and loops.

Here’s the complete exemple:

<table name=”example_table” namespace=”TheliaStudioTestModule\Model”>
    <column autoIncrement=”true” name=”id” primaryKey=”true” required=”true” type=”INTEGER” />
    <column defaultValue=”0″ name=”visible” required=”true” type=”TINYINT” />
    <column defaultValue=”0″ name=”position” required=”true” type=”INTEGER” />
    <column name=”title” size=”255″ type=”VARCHAR” />
    <column name=”description” type=”CLOB” />
    <column name=”chapo” type=”LONGVARCHAR” />
    <column name=”postscriptum” type=”LONGVARCHAR” />
    <behavior name=”timestampable” />
    <behavior name=”i18n”>
        <parameter name=”i18n_columns” value=”title, description, chapo, postscriptum” />
    </behavior>
    <behavior name=”versionable”>
        <parameter name=”log_created_at” value=”true” />
        <parameter name=”log_created_by” value=”true” />
    </behavior>
</table>

Once you have your two files complete, you only have to execute php Thelia module:generate:all to generate your module configuration form and tables CRUD.

Warning: The generated routes for the tables doesn’t have any link, it’s up to you to add the link where you think it’s the best. The generated routes are following the pattern: /admin/module/ModuleName/schema_table_name

Tip: if you want to generate the CRUD only for some tables, you can use the –table parameter: php Thelia module:generate:all –tables table1,table3

You can add the module with composer in your thelia-project by requiring thelia/thelia-studio-module ~1.1
or download it now from Github

1 Comment

  1. hicham
    2015/02/11 4:56:01pm

    Merci pour ce module, je vais tester, j’espère qu’il gère bien les DATE.

    Cdt,
    Hicham

Drop a comment

Your email address will not be published. Required fields are marked *