Typo3: Inserting data during installation of the extension (after creating the table)

For the user extension that I am writing, I have an ext_tables.sql file that loads during installation.

I would like to insert some dynamic data into tables created from ext_tables.sql during the installation procedure using PHP code. Is it possible? If so, what should I do and where should I do it?

Alternatively, is it possible for the PHP code to create tables (using the database interface) during installation, rather than relying on ext_tables.sql? Again, if so, what do I need to do for this and where should I do it.

+4
source share
2 answers

Of course you can (with litte trick):

  • Add ext_conf_template.txt to the extension
  • Add custom type record to ext_conf_template.txt

    # cat=basic; type=user[EXT:<EXTNAME>/Path/To/Class.php:Tx_Path_To_Class->postInstall]; label= postInstallAction=0 
  • Create in PHP file Class.php in path / path / in

    This method can be used to perform some actions after installation or, as a rule, to change the extension configuration page (the method can return the HTML that will be included here).

     class Tx_Path_To_Class { /** * Generates and returns an message. * * @param array $params Name and value from ext_conf_template.txt * @param t3lib_tsStyleConfig $styleConfig Instance of config style editor * * @return string HTML code */ public function postInstall(array $params, t3lib_tsStyleConfig $styleConfig) { // Do your stuff return ''; } 

    }

I use this to add specific user output to the extension’s configuration page, but you can also do some initial setup.

After installing the extension, you can click the “Make Updates” button to execute the script.

+2
source

At least there is a hook in the old EM (TYPO3 4.5 and below). I think there are new ones.

You can add some fields to the view where you can set your preferences.

 $TYPO3_CONF_VARS['SC_OPTIONS']['typo3/mod/tools/em/index.php']['tsStyleConfigForm'][] = "EXT:yourextension/class.yourextension.php:yourextension->main"; 
0
source

Source: https://habr.com/ru/post/1442642/


All Articles