Extension Programming

How to enable jQuery with powermail OR How to remove mootools or prototype from powermail, and use jQuery validation

In some cases we may wish to retain one single library throughout our site, so powermail does not have issues if we choose mootools or prototype.
If we prefer jQuery, then we have some issues at present, as powermail does not yet allow us to use jQuery built in.
The future version however seem to include this feature, and we are waiting, untill then this might prove useful.

  • Step 1: Set nothing for the libraryToUse contstant (of course in constants section)
    plugin.powermail.libraryToUse =
  • Step 2: Set up a different template path for the formWrap — This is important, will explain later in Step3!
    To do this I will copy the formwrap.html located in typo3conf/ext/powermail/templates/tmpl_formwrap.html to fileadmin/templates and set following constant.
    plugin.powermail.template.formWrap = fileadmin/templates/tmpl_formwrap.html

    NOTE: You may change template even in setup section, check manual or ext_typoscript_setup.txt for details.

  • Step 3: Remove the validation script from formwrap.html that we copied just now.
    If you look at the tempalte file, you can see folloing JavaScript:

    <script type=”text/javascript”>
    function formCallback(result, form) {
    window.status = “valiation callback for form ‘” + form.id + “‘: result = ” + result;
    }
    var valid = new Validation(‘###POWERMAIL_NAME###’, {immediate : true, onFormValidate : formCallback});
    </script>

    Remove the above completely including <script> tags.

  • Step 4: Remove automatic inclusion of JS files using TypoScript. (IMPORTANT: This must appear in the setup section)
    page.includeJS.file31311 >
    page.headerData.31310 >

There you go, by now you should have disabled the output of all java scripts and inclusion of JS Libraries like mootools or prototype.
Now you are free to use any library you need.

NOTE: By now the default validation methods available in powermail are also disabled. Well we can easily use the jquery form validation!

Disable js_css_optimizer when using feeditadvanced

I recently noticed that the extension feeditadvanced when used alog with js_css_optimizer gives an error stating that a CSS file is missing!

This is probably caused because feeditadvanced did nt take into consideration the css files that are created by the js_css_optimizer.

Normally we do not need js_css_optimizer if we would like to edit content. So added a quick solution that disables the js_css_optimizer when using on feeditadvanced.

You will need to edit the following file:

typo3conf\ext\feeditadvanced\hooks\class.tx_feeditadvanced_pagerenderer.php

Open this and add the following 3 lines of code inside the IF Condition of the function preProcessPageRenderer():

unset($GLOBALS[‘TYPO3_CONF_VARS’][‘FE’][‘cssCompressHandler’]);
unset($GLOBALS[‘TYPO3_CONF_VARS’][‘FE’][‘jsCompressHandler’]);
unset($GLOBALS[‘TYPO3_CONF_VARS’][‘FE’][‘concatenateHandler’]);

Full code for preProcessPageRenderer():

public function preProcessPageRenderer($params, $parentObject) {

if ($parentObject->getConcatenateFiles() && (t3lib_div::_GP(‘eID’) === ‘feeditadvanced’) && $GLOBALS[‘TBE_TEMPLATE’]) {

unset($GLOBALS[‘TYPO3_CONF_VARS’][‘FE’][‘cssCompressHandler’]);
unset($GLOBALS[‘TYPO3_CONF_VARS’][‘FE’][‘jsCompressHandler’]);
unset($GLOBALS[‘TYPO3_CONF_VARS’][‘FE’][‘concatenateHandler’]);

$compressor = t3lib_div::makeInstance(‘t3lib_compressor’);
$cssOptions = array(‘baseDirectories’ => $GLOBALS[‘TBE_TEMPLATE’]->getSkinStylesheetDirectories());
$params[‘cssFiles’] = $compressor->concatenateCssFiles($params[‘cssFiles’], $cssOptions);
}
}

It would have been great if css files created by js_css_optimizer are used within feeditadvanced, unfortunately that is not the case at present.
Till then I hope we may use the above code.

Disable a TYPO3 extension or removing a hook specified by another extension

In some cases we may need to disable some hooks that are defined by another extension. Say for example in a recent case, I had to disable js_css_optimizer when a typo3 FE editor is logged in. This was necessary as feeditadvanced was not working together with js_css_optimizer.

So the moment I needed the services of feeditadvanced, I had to disable js_css_optimizer, so I added the following code:

unset($GLOBALS[‘TYPO3_CONF_VARS’][‘FE’][‘cssCompressHandler’]);

We have to make sure that we do this at correct stage, for example, if the extension we wanted to disable has already finished it’s execution, then we may not get desired result, so we may have to add another hook that executes much before the hook we wanted to remove.

Dividers to Tabs in Extensions

This article explains how easily we can get Tabs in the content elements of type “insert records”.

Generally we will need to edit tca.php and ext_tables.php.

To be more specific it involves adding two parameters.

1. Specify that you are using dividers to tabs “dividersstabs”
2. Mark all tabs using –div–

Let us see how.

1. Specify that you are using dividers to tabs “dividersstabs”

In the TCA array first look at the start of table definition. Generally this is located

EX:

$TCA['tx_myext_table] = array ( 
        'ctrl' => array ( 
                'title' => 'LLL:EXT:myext/locallang_db.xml:tx_myext_table, 
                'label' => 'title', 
                'tstamp' => 'tstamp', 
                'crdate' => 'crdate', 
                'cruser_id' => 'cruser_id', 
                'languageField' => 'sys_language_uid', 
                'transOrigPointerField' => 'l10n_parent', 
                'transOrigDiffSourceField' => 'l10n_diffsource', 
                'sortby' => 'sorting', 
                'delete' => 'deleted', 
                'dividers2tabs' => TRUE, 
                'enablecolumns' => array ( 
                        'disabled' => 'hidden', 
                ), 
                'dynamicConfigFile' => t3lib_extMgm::extPath($_EXTKEY).'tca.php', 
                'iconfile' => t3lib_extMgm::extRelPath($_EXTKEY).'icon_tx_myext_table.gif', 
        ), 
);

                

In the above config you can see that ‘dividers2tabs’ is set to TRUE

2. Mark all tabs using --div--

This is the step in which you would group all fields into different Tabs. This generally involves editing the TCA config usually locatd in tca.php.

In tca.php, look the section showitem, and add --div--;Tab Name,
EX: 
'types' => array ( 
        '0' => array(
                'showitem' => '--div--;General,
                                sys_language_uid;;;;1-1-1, l10n_parent, 
                                l10n_diffsource, hidden;;1,
                                --div--;Content,title;;;;3-3-3, parentid,top_page,content,
                                --div--;Header and Footer,footer,
                                background_image,background_align'
                ) 
),

As you can see I have added 3 tabs, General, Content, Header and Footer.

The idea is to add --div--; (two hypen followed by div and two hyphen and semicolon)

After semicolon add the “Title of your tab” and followed by a comma.

This section --div--;Tab Name, must be added just before a field, or after a field ends.

That should be it.

Happy coding.

Html tags like table,p are not comming for the newly added RTE field in tt_news

While I was working on some project, there was a requirement to add extra RTE field for tt_news. I extended the table tt_news by adding RTE fields. I faced the following problem

1) I inserted the table but after saving the tt_news record the table started disappearing

2) <p> tag was not inserted automatically for press of Enter

After doing some research I found the solution

1) Set the transformation mode for the RTE to “ts_css” in ext_tables.php

ex-

if (t3lib_extMgm::isLoaded(‘css_styled_content’)) {
t3lib_extMgm::addPageTSConfig(‘
# RTE mode for table “tt_news”
RTE.config.tt_news.exampleField.proc.overruleMode=ts_css’);
}

Here the table used is tt_news and the filed name is exampleField

2) For P tag to be inserted for every new line character I added the code

$rowfrntbl[$tblcol]=$pObj->local_cObj->stdWrap($rowfrntbl[$tblcol], $pObj->conf[‘general_stdWrap.’])

Here I am using hook  for tt_news to get the desired result.