thelia-modules / TheliaStudio

Module that adds tools for Thelia developpers
3 stars 3 forks source link

Thelia Studio

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.

  1. Installation

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"
}
  1. Usage

This module adds two commands: $ php Thelia module:generate:all and $ php Thelia module:generate:config-form

  1. Generating your module configuration 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 :) :

Here'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
  1. How to use it ?

 4.1 Generate the configuration form only

First, write your config-form.yml Then launch $ php Thelia module:generate:config-form Finally, adapt the generated template for your need.

4.2 Generate table CRUD and configuration form

4.2.1 Writing the schema.xml

If you want your table to be correctly integrated into Thelia, you have to respect some conventions.

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>

4.2.2 Generating everything

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.

4.2.3 Automatic support for some standard Thelia features

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 :

  1. Access to the generated pages

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.