author: Benjamin Perche bperche@openstudio.fr
This module allows you to generate all the repetitive classes and templates you have to write for a module.
Install it as a thelia module by downloading the zip archive and extracting it in thelia/local/modules
or by uploading it with the backoffice,
or by requiring it with composer:
"require": {
"thelia/thelia-studio-module": "~1.4.4"
}
This module adds two commands:
$ php Thelia module:generate:all
and
$ php Thelia module:generate:config-form
To do that, you will need to write a new file.
Create config-form.yml
in your module's Config directory,
and by respecting the following structure, TheliaStudio will generate everything for you :) :
varName: type
for simple ones.
label: My Var
to customize the name of the field displayed in the configuration pagerequired: false
if the field isn't requiredregex
a validation regex.size
an array with "min" and "max" keys.help: Help for my var
a help message for the field displayed in the configuration pageHere's an example:
config:
var_name: text
var_name2: integer
var_name3: checkbox
var_name4:
label: My Variable
help: Help for variable ...
type: text
required: false
regex: "a-z+"
size:
min: 5
max: 20
First, write your config-form.yml
Then launch $ php Thelia module:generate:config-form
Finally, adapt the generated template for your need.
If you want your table to be correctly integrated into Thelia, you have to respect some conventions.
id
and never construct the PK with two columns.visible
and give it the type BOOLEAN
or TINYINT
position
. The order argument for the loop will be called manualBOOLEAN
or a TINYINT
type, it will be used as a checkbox.Here's a typical schema that will work like a charm with TheliaStudio:
<?xml version="1.0" encoding="UTF-8"?>
<database defaultIdMethod="native" name="thelia"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../../core/vendor/propel/propel/resources/xsd/database.xsd" >
<table name="example_table" namespace="YourModule\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>
<external-schema filename="local/config/schema.xml" referenceOnly="true" />
</database>
Write your schema.xml, then if needed write your config-form.yml
You can now launch $ php Thelia module:generate:all
, your can use the --table option to specify the tables you want to generate.
Go to the Form
directory and change the form names that you want.
You can change the generated templates as you want, as the generator integrates everything, everywhere, even if it's not needed.
The module will generate the appropriate code for managing 'position' and 'visible' fields if the table has columns with these names.
The module will automaticaly generate the code for managing standard Thelia SEO fields (including a rewriten URL) if the table has the following columns :
The CRUDs are generated under /admin/module/ModuleCode/table_name
You can write a hook to access it from the Tools
dropdown or add links into your module configuration page.