Adding the Icon for Menu from page media property

From typo3 6.2.x, please use the following code  to generate the icon for menus from its page’s media property.

lib.menu = HMENU
lib.menu {
entryLevel = 1
expAll = 1
1 = TMENU
1{
wrap = <ul class=”leftmenu”> | </ul>
expAll = 1
NO = 1
NO{
before.wrap = <li>|
stdWrap.cObject = COA
stdWrap.cObject {
10 = FILES
10 {
# Get the images related to the current page
references {
table = pages
fieldName = media
}
# Render each image and wrap it as appropriate
renderObj = TEXT
renderObj {
typolink {
parameter.data = file:current:publicUrl
forceAbsoluteUrl = 1
returnLast = url
}
wrap = |,
}
stdWrap {
# Take only the first image if several are defined
listNum = 0
# Use default image if none is available
ifEmpty.cObject = TEXT
ifEmpty.cObject.typolink {
parameter = path_to_images/logo.png
forceAbsoluteUrl = 1
returnLast = url
}
wrap = <img src=”|” title=”image” />
}
}

20 = TEXT
20.field = title
20.wrap = <span>|</span>
}
after.wrap = |</li>
}
ACT < .NO
ACT.before.wrap = <li class=”active”> |

CUR < .NO
CUR.before.wrap = <li class=”active”> |
}
}

This snippet informs how to add or allow custom tags in RTE

PAGE TS CONFIG AS FOLLOWS:

# Allow embed, parm, object and iframe tags, also see RTE parser code added in config.ts
RTE.default.proc {
allowTags := addToList(object,param,embed,iframe)
allowTagsOutside := addToList(object,embed,iframe)
entryHTMLparser_db.allowTags < RTE.default.proc.allowTags
}

TYPOSCRIPT SETUP SHOULD BE AS FOLLOWS

# Allow embed, parm, object and iframe tags, also see RTE setup added in rte.ts
lib.parseFunc_RTE.allowTags := addToList(object,param,embed,iframe)

TYPO3 FAL (file abstraction layer) in Extbase/Fluid extension

Recently I came across to implement extbase plugin having multiple file upload FE form.

My Typo3 version was 6.1
The extension was created using Extension Builder

File ext_tables.sql

CREATE TABLE tx_clientside_domain_model_orderitems (
:
files int(11) unsigned DEFAULT ‘0’ NOT NULL,
:

);

File Configuration/TCA/OrderItems.php

$TCA[‘tx_clientside_domain_model_orderitems’] = array(
//…… removed code

‘files’ => array(
‘exclude’ => 1,
‘label’ => ‘Files’,
‘config’ => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getFileFieldTCAConfig(‘files’, array(
‘appearance’ => array(
‘createNewRelationLinkTitle’ => ‘LLL:EXT:cms/locallang_ttc.xlf:images.addFileReference’
),
), $GLOBALS[‘TYPO3_CONF_VARS’][‘GFX’][‘imagefile_ext’]),
),

//…..

);

File Classes/Domain/Model/OrderItems.php

class OrderItems extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity {

/**
* Files
*
* @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\TYPO3\CMS\Extbase\Domain\Model\FileReference>
*/
protected $files;

/**
* __construct
*
* @return AbstractObject
*/
public function __construct() {
$this->files = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
}
/**
* Returns the files
*
* @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage
*/
public function getFiles() {
return $this->files;
}

}

I have not used function setFiles here.

File Classes/Controller/OrderItemsController.php

class OrderItemsController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController {

/**
* orderItemsRepository
*
* @var \TYPO3\Clientside\Domain\Repository\OrderItemsRepository
* @inject
*/
protected $orderItemsRepository;

/**
* action create
*
* @param \TYPO3\Clientside\Domain\Model\OrderItems $newOrderItems
* @dontvalidate $newOrderItems
* @return void
*/
public function createAction(\TYPO3\Clientside\Domain\Model\OrderItems $newOrderItems) {

$this->orderItemsRepository->add($newOrderItems);

$persistenceManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(‘Tx_Extbase_Persistence_Manager’);
$persistenceManager->persistAll();
$uidNew = $newOrderItems->getUid();

if ($_FILES[‘tx_clientside_orderitems’]) {
for ($i = 0; $i < count($_FILES[‘tx_clientside_orderitems’][‘name’][‘myfiles’]); $i++) {
$file = array();
$file[‘name’] = $_FILES[‘tx_clientside_orderitems’][‘name’][‘myfiles’][$i];
$file[‘type’] = $_FILES[‘tx_clientside_orderitems’][‘type’][‘myfiles’][$i];
$file[‘tmp_name’] = $_FILES[‘tx_clientside_orderitems’][‘tmp_name’][‘myfiles’][$i];
$file[‘size’] = $_FILES[‘tx_clientside_orderitems’][‘size’][‘myfiles’][$i];
if ($file[‘name’]) {
$files = $this->uploadFile($file[‘name’], $file[‘type’], $file[‘tmp_name’], $file[‘size’]);
$sysFileCreate = $this->orderItemsRepository->myFileOperationsFal($files, $file[‘type’], $file[‘size’], $uidNew);
}
}
}

$this->flashMessageContainer->add(‘Your new OrderItems was created.’);
$this->redirect(‘list’);
}

protected function uploadFile($name, $type, $temp, $size) {
if($size > 0) {
$basicFileFunctions = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(‘t3lib_basicFileFunctions’);

$name = $basicFileFunctions->cleanFileName($name);
$uploadPath = $basicFileFunctions->cleanDirectoryName(‘fileadmin/user_upload/’);
$uniqueFileName = $basicFileFunctions->getUniqueName($name, $uploadPath);
$fileStored = move_uploaded_file($temp, $uniqueFileName);

$returnValue = basename($uniqueFileName);
}

return $returnValue;
}

}

 

File Classes/Romain/Repository/OrderItemsRepository.php

class OrderItemsRepository extends \TYPO3\CMS\Extbase\Persistence\Repository {

public function myFileOperationsFal($filename, $filetype, $filesize, $uidNew){

$newSysFields = array(
‘pid’ => 0,
‘identifier’ =>’/user_upload/’.$filename,
‘mime_type’ => $filetype,
‘name’ => $filename,
‘size’ => $filesize,
‘storage’ => 1,
‘crdate’ => $GLOBALS[‘EXEC_TIME’],
‘tstamp’ => $GLOBALS[‘EXEC_TIME’]
);

$newSysRes = $GLOBALS[‘TYPO3_DB’]->exec_INSERTquery(‘sys_file’, $newSysFields);

$uid_local = $GLOBALS[‘TYPO3_DB’]->sql_insert_id($newSysRes);
$newRefFields = array(
‘pid’ => 88,
‘tablenames’ => ‘tx_clientside_domain_model_orderitems’,
‘uid_foreign’ => $uidNew,
‘uid_local’ => $uid_local,
‘table_local’ => ‘sys_file’,
‘fieldname’ => ‘files’,
‘crdate’ => $GLOBALS[‘EXEC_TIME’],
‘tstamp’ => $GLOBALS[‘EXEC_TIME’]
);

$GLOBALS[‘TYPO3_DB’]->exec_INSERTquery(‘sys_file_reference’, $newRefFields);
}

}

Here I am writing custom File operation function, that creates new entry in table sys_file and mm relation to table sys_file_reference.
I have searched google for any other good way, without success 🙁

Suggestions are welcome 🙂

File Resources/Private/Templates/Root/New.html

<f:form action=”create” enctype=”multipart/form-data” name=”newOrderItems” object=”{newOrderItems}” >
<input name=”tx_clientside_orderitems[myfiles][]” type=”file” /><br />
<input name=”tx_clientside_orderitems[myfiles][]” type=”file” /><br />
<f:form.submit value=”Create new” /></f:form>

 

Here is how to dispaly that images in frontend

File Resources/Private/Templates/Root/Show.html

<f:for each=”{orderItems.files}” as=”file”>
<f:image src=”{file.uid}” alt=”” width=’101′ height=”67″ treatIdAsReference=”1″/>
</f:for>

 

Running a SQL Query using TypoScript

Well, after using this feature for quite long time, I though I should post this info:Consider the following Query:

SELECT DISTINCT FROM_UNIXTIME(`datetime`, ‘%Y’) AS `year` FROM tt_news where pid=113 order by datetime limit 1

My main goal was to get the latest year from the tt_news records, that is then going to be pushed to Tesseract filter.

Soln:

20 = CONTENT
20 {
table = tt_news
select {
selectFields = FROM_UNIXTIME(`datetime`, ‘%Y’) AS year
orderBy = datetime desc
pidInList = 113
max = 1
}
renderObj = TEXT
renderObj.field = year
}

Reference: http://typo3.org/documentation/document-library/core-documentation/doc_core_tsref/4.5.0/view/1/5/#id2621093