How to read locallang file in typo3 custom extension.


 
For multi language site locallang file is very important for set all labels language wise.

First of all we have to set path for xml file which we have to read. So for that we will use following code.

This is for EXTBASE Extension
$xmlPath = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('EXTENSION_NAME').'locallang_db.xml';

OR

This is for PI Base Extension
$xmlPath = t3lib_extMgm::extPath('EXTENSION_NAME').'locallang_db.xml';

Now we have to read xml file. following code should do the trick.


$curLang = "default";

This is for EXTBASE Extension
\TYPO3\CMS\Core\Utility\GeneralUtility::readLLXMLfile($xmlPath, $lang);
OR

This is for PI Base Extension
t3lib_div::readLLXMLfile($xmlPath, $lang);

For get particular language data we have to use following script.


$cfile = t3lib_extMgm::extPath('EXTENSION_NAME').'locallang_db.xml';

$curLang = "default";

$LOCAL_LANG = t3lib_div::readLLXMLfile($cfile, $curLang);

$label = $LOCAL_LANG[$curLang]['lbl_welcome_msg'];

if we wont it on other language then simply use language code in $curLang variable.

$curLang = "de";

after set “de” as language code it will display all data from related languages.

If you have any queries, please do not hesitate to contact me at Jainish Senjaliya

Advertisements

How to get all images from folder in typo3


For get list of all images from folder you have first read all files from folder.

Click here for more detail about how to get all files list from folder in typo3


$folderPath = "fileadmin/images/"

$files = \TYPO3\CMS\Core\Utility\GeneralUtility::getFilesInDir($folderPath, '', true, 1, '');

From above script you will get all files list from your folder.

Now we only need to get image or any selected extension files

for that we have to use following script for get particular extension file.

if (count($files) > 0) {

    foreach ($files as $key => $image) {
        
        $pathinfo = pathinfo($image);

        if (\TYPO3\CMS\Core\Utility\GeneralUtility::inList('gif,png,jpeg,jpg', strtolower($pathinfo['extension']))) {
            $images[$key] = $image;
        }
    }
}

Note : gif,png,jpeg,jpg is a file extension.

You will get all selected file list in “$images” array.

Note : if you want only PDF file then you have to write “pdf” instead of all image extension like : jpe, png, gif etc.

whatever particuler file you want just set extension in inList function.

If you have any queries, please do not hesitate to contact me at Jainish Senjaliya

How to get all files list from folder in typo3


For get list of all file from folder you have to use following script.

If you have three file and five folders in your current folder then it will render only three files.


$folderPath = "fileadmin/images/"

$files = \TYPO3\CMS\Core\Utility\GeneralUtility::getFilesInDir($folderPath, '', true, 1, '');

After print of that result Output will look like below

print_r($files);

Array
(
    [82141013ca93e10552e65da03ea89014] => fileadmin/images/jainish.jpg
    [514f220a8ceb5d13971e6fddf5a06f0c] => fileadmin/images/senjaliya.jpg
    [5ee9823729a422345befd96d2ece6b69] => fileadmin/images/jainish.txt
)

You will get all files list in array.

Note : It will not render folders. its only render list of all files with different extension.

If you have any queries, please do not hesitate to contact me at Jainish Senjaliya

ZipArchive is not working in Extbase + typo3


 
When we create a new zips “$zip = new ZipArchive();”

However, we get always the following error message:

Fatal error: Class ‘TYPO3 \ .. \ Domain \ Repository \ ZipArchive’ not found in … / Classes / Domain / Repository / XXXRepository.php on line 143.

Zip works nicely on the server. A simple PHP script which zips a file running properly in server.

In Extbase we have to add backward slash [ \ ] infront of class name.

Following script should do the trick.

$zip = new \ZipArchive();

If you have any queries, please do not hesitate to contact me at Jainish Senjaliya

How to image store in tt_content or sys_file_reference table + TYPO3.


 
If you want to use images field in custom plugin then you have to use following code.

This image will take it from sys_file table. this will be store in tt_content field.

It’s create relations directly to the “sys_file” table by not using MM information.

$tempColumns = Array (
    "images" => Array (
        "exclude" => 0,
        "label" => "Images",
        'config' => array(
            'type' => 'group',
            'internal_type' => 'db',
            'allowed' => 'sys_file',

            'prepend_tname' => TRUE,
            'appearance' => array(
                'elementBrowserAllowed' => $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'],
                'elementBrowserType' => 'file'
            ),

            'max_size' => $GLOBALS['TYPO3_CONF_VARS']['BE']['maxFileSize'],
            'show_thumbs' => '1',
            'size' => '5',
            'maxitems' => '200',
            'minitems' => '0',
            'autoSizeMax' => 40,
        ),
    ),
);

If you want to store it in sys_file_reference table then you have to use following two line in configuration.

It’s create relations using MM information [ sys_file_reference ].

'MM' => 'sys_file_reference',
'MM_match_fields' => array(
    'fieldname' => 'image_fal_group'
),

Since “db” references can be stored for multiple tables the rule is that uid numbers without a table name prefixed are implicitly from the first table in the allowed table list! Thus the list “32,141,72,10” is implicitly understood as “sys_file_32,sys_file_141,sys_file_72,sys_file_10”. That would be equally good for storage,

If you want to add image as tt_content field in your custom plugin then please Click Here

If you have any queries, please do not hesitate to contact me at Jainish Senjaliya

How to image upload in extension of typo3 6.2 version + Drag n drop image functionality in extension of typo3 6.2


 
Its very useful functionality for upload all images from system directory [sys_file]

Drag n drop image functionality also available in flexform of typo3 6.2

You can have to add following configuration in your image field.

Following code need to modify in your tca.php file.


$tempColumns = Array (

   "images"  => Array (
	
      "exclude"  => 0,
      "label"  => "Add your Media",
		
      "config"  => Array (
         "type"  => "inline",
         "internal_type"  => "file",
         "size"  => 10,
         "minitems"  => 1,
         "maxitems"  => 100,
			
         "appearance"  => Array(
            "headerThumbnail"  => Array(
               "field"  =>"uid_local",
                  "height"  =>"45c",
                  "width"  => "45"
               ),
               "enabledControls"  => Array(
                  "delete" => 1,
                  "dragdrop"  => 1,
                  "hide"  => 1,
                  "info"  => 1,
                  "localize"  => 1
               ),
               "useSortable"  => 1
         ),
			
         "behaviour"  => Array(
            "localizationMode"  => "select",
            "localizeChildrenAtParentLocalization"  => 1
         ),
			
         "foreign_field"  => "uid_foreign",
         "foreign_label"  => "uid_local",

         "foreign_match_fields"  => Array(
            "fieldname"  => "fal_filelist"
         ),
			
         "foreign_selector"  => "uid_local",
			
         "foreign_selector_fieldTcaOverride"  => Array(
            "config"  => Array(
               "appearance"  => Array(
                  "elementBrowserAllowed"  => "gif,jpg,jpeg,bmp",
                  "elementBrowserType"  => "file"
               )
            )
         ),
			
         "foreign_sortby"  => "sorting_foreign",
         "foreign_table"  => "sys_file_reference",
         "foreign_table_field"  => "tablenames",

         "show_thumbs" => 1,

      )
   ),
);

it will look like below image.

Flexform + image + typo3 6.2

Flexform + image + typo3 6.2

OR if you want to add image as tt_content field in your custom plugin then please Click Here

If you have any queries, please do not hesitate to contact me at Jainish Senjaliya

How to use tt_content fields in custom plugin of TYPO3.


 
How to add new field in custom plugin option

Its very important and useful for add tt_content field in custom plugin option or in normal content element area.

If you want to set second title field in your tt_content record then you have to set following script in your ext_table.php

$tempColumns = array(
    'subtitle' => array(
        'exclude' => 0,
        'label' => 'title2',
        'config' => array(
            'type' => 'input'
        )
    )
);

Then you have to load tt_content TCA file

This is for EXTBASE Extension
\TYPO3\CMS\Core\Utility\GeneralUtility::loadTCA('tt_content');

OR

This is for PI Base Extension
t3lib_div::loadTCA("tx_dam_cat");

If you want to display this field in ALL CONTENT ELEMENT then use following script.

This is for EXTBASE Extension
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns('tt_content', $tempColumns);

OR

This is for PI Base Extension
t3lib_extMgm::addTCAcolumns("tx_dam_cat",$tempColumns,1);

Third parameter is deprecated in latest version of TYPO3 6.X.X

If you want to display this field in PARTICULAR EXTENSION then use following script.

This is for EXTBASE Extension
$TCA["tt_content"]["types"]["list"]["subtypes_excludelist"]["abc_xyz"]="layout,select_key,pages";
$TCA["tt_content"]["types"]["list"]["subtypes_addlist"]["abc_xyz"]="subtitle;;;;1-1-1";

OR

This is for PI Base Extension
$TCA["tt_content"]["types"]["list"]["subtypes_excludelist"][$_EXTKEY."_pi1"]="layout,select_key,pages";
$TCA["tt_content"]["types"]["list"]["subtypes_addlist"][$_EXTKEY."_pi1"]="subtitle;;;;1-1-1";

Note :
If your extension key is “Abc” and your plugin key is “Xyz”, then the index is “abc_xyz”, all in small.

I hope it will work for you and make your day 😉

If you have any queries, please do not hesitate to contact me at Jainish Senjaliya