PHP code example of icodr8 / contao-translation-fields
1. Go to this page and download the library: Download icodr8/contao-translation-fields library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
icodr8 / contao-translation-fields example snippets
$GLOBALS['TL_DCA']['tl_mytable']['fields']['myfield'] = array
(
'label' => &$GLOBALS['TL_LANG']['tl_mytable']['myfield'],
'exclude' => true,
'inputType' => 'text',
'eval' => array('maxlength'=>255),
'sql' => "varchar(255) NOT NULL default ''"
);
$GLOBALS['TL_DCA']['tl_mytable']['config']['sql']['keys']['myfield'] = 'index';
$GLOBALS['TL_DCA']['tl_mytable']['fields']['myfield'] = array
(
'label' => &$GLOBALS['TL_LANG']['tl_mytable']['myfield'],
'exclude' => true,
'inputType' => 'TranslationTextField',
'eval' => array('maxlength'=>255),
'sql' => "int(10) unsigned NOT NULL default '0'",
'relation' => array('type'=>'hasOne', 'load'=>'lazy')
);
$GLOBALS['TL_DCA']['tl_mytable']['fields']['myfield'] = array
(
'label' => &$GLOBALS['TL_LANG']['tl_mytable']['myfield'],
'exclude' => true,
'inputType' => 'textarea',
'eval' => array('rte'=>'tinyMCE', 'tl_class'=>'long'),
'sql' => "text NULL"
);
$GLOBALS['TL_DCA']['tl_mytable']['config']['sql']['keys']['myfield'] = 'index';
$GLOBALS['TL_DCA']['tl_mytable']['fields']['myfield'] = array
(
'label' => &$GLOBALS['TL_LANG']['tl_mytable']['myfield'],
'exclude' => true,
'inputType' => 'TranslationTextArea',
'eval' => array('rte'=>'tinyMCE', 'tl_class'=>'long'),
'sql' => "int(10) unsigned NOT NULL default '0'",
'relation' => array('type'=>'hasOne', 'load'=>'lazy')
);
$GLOBALS['TL_DCA']['tl_mytable']['fields']['myfield'] = array
(
'label' => &$GLOBALS['TL_LANG']['tl_mytable']['myfield'],
'exclude' => true,
'inputType' => 'inputUnit',
'options' => array('h1', 'h2', 'h3', 'h4', 'h5', 'h6'),
'eval' => array('maxlength'=>200, 'tl_class'=>'w50'),
'sql' => "blob NULL"
);
$GLOBALS['TL_DCA']['tl_mytable']['config']['sql']['keys']['myfield'] = 'index';
$GLOBALS['TL_DCA']['tl_mytable']['fields']['myfield'] = array
(
'label' => &$GLOBALS['TL_LANG']['tl_mytable']['myfield'],
'exclude' => true,
'inputType' => 'TranslationInputUnit',
'options' => array('h1', 'h2', 'h3', 'h4', 'h5', 'h6'),
'eval' => array('maxlength'=>200, 'tl_class'=>'w50'),
'sql' => "blob NULL",
'relation' => array('type'=>'hasOne', 'load'=>'lazy')
);
$intId = '1485'; // Example value
$strTranslated = \TranslationFields::translateValue($intId);
echo $strTranslated; // Returns e.g. "Hi there!"
$intId = '1485'; // Example value
$strForceLanguage = 'de';
$strTranslated = \TranslationFields::translateValue($intId, $strForceLanguage);
echo $strTranslated; // Returns e.g. "Hallo zusammen!"
$objDC->exampleValue = '1485'; // Example value
$objDC = \TranslationFields::translateDCObject($objDC);
echo $objDC->exampleValue; // Returns e.g. "Hi there!"
$arrDC['exampleValue'] = '1485'; // Example value
$arrDC = \TranslationFields::translateDCArray($arrDC, $strTable);
echo $arrDC['exampleValue']; // Returns e.g. "Hi there!"
class MyApplicationRunconce extends \Controller
{
// Code ...
public function __construct()
{
parent::__construct();
// Code ...
// Load \ClassLoader::addClass('TranslationFields\TranslationFieldsWidgetHelper', 'system/modules/translation-fields/classes/TranslationFieldsWidgetHelper.php');
\ClassLoader::addClass('TranslationFields\TranslationFieldsModel', 'system/modules/translation-fields/models/TranslationFieldsModel.php');
\ClassLoader::register();
}
public function run()
{
// Code ...
\TranslationFields\Updater::convertTranslationField('tl_my_table_name', 'my_field_name');
// Code ...
}
// Code ...
}