TYPO3 set upload folder in tca - typo3

'image' => array(
'label' => 'LLL:EXT:fefiles/Resources/Private/Language/locallang_db.xlf:image',
'config' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getFileFieldTCAConfig(
'image', array(
'appearance' => array(
'createNewRelationLinkTitle' => 'LLL:EXT:cms/locallang_ttc.xlf:images.addFileReference'
),
'minitems' => 0,
'maxitems' => 1,
'foreign_match_fields' => array(
'fieldname' => 'image',
'tablenames' => 'tx_fechat_domain_model_smile',
'table_local' => 'sys_file_reference',
),
), $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext']
),
),
Can I set upload folder exactly for files for this field ? TYPO3 version 7.6.18

Its not possible through Tca, but you can utilized hook.
in localconf.php file
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauthgroup.php']['getDefaultUploadFolder']['my_ext'] = 'Vendor\\MYEXT\\Hooks\\BackendUserAuthentication->getDefaultUploadFolder';
in my_ext/Classes/Hooks/BackendUserAuthentication.php
namespace Vendor\MYEXT\Hooks;
class BackendUserAuthentication {
public function getDefaultUploadFolder(Array $params, \TYPO3\CMS\Core\Authentication\BackendUserAuthentication $backendUserAuthentication) {
//Define table name an field for which you want to change upload path
if($params['table'] == 'tx_myext_domain_model_objectdetail' && ($params['field'] == 'mediafiles'||$params['field'] == 'image'))
{
$uploadFolder = new \TYPO3\CMS\Core\Resource\Folder($params['uploadFolder']->getStorage(),'/uploadfolder/','uploadfolder');
return $uploadFolder;
}
return $params['uploadFolder'];
}
}

Related

TYPO3: Issue with File upload and File reference

I have "Book" model with a "pdf" and "image" property. Both property are files that can be uploaded by the user.
I followed Helhum's example for the image upload and it works fine.
I tried to do the same for the "pdf" field but it doesn't work. The file is being uploaded, the file ID is also saved in the database but the file reference is missing.
Here is a dump of the "Book" object after the upload:
pdf => NULL
image => Vendor\MyExt\Domain\Model\FileReference
In the "setTypeConverterConfigurationForImageUpload" function I added this line the pdf property:
$newExampleConfiguration->forProperty('pdf')
->setTypeConverterOptions(
'Vendor\\MyExt\\Property\\TypeConverter\\UploadedFileReferenceConverter',
$uploadConfiguration
);
I am probably missing something but I don't what.
EDIT:
I found the issue thanks to Heinz and Ghanshyam. It was a mistake in the TCA.
Here is how my working TCA looks like:
'image' => array(
'exclude' => 1,
'label' => 'Image',
'config' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getFileFieldTCAConfig('image', array(
'appearance' => array(
'elementBrowserType' => 'file',
'elementBrowserAllowed' => $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'],
),
'minitems' => 0,
'maxitems' => 1,
// custom configuration for displaying fields in the overlay/reference table
// to use the imageoverlayPalette instead of the basicoverlayPalette
'foreign_match_fields' => array(
'fieldname' => 'image',
'tablenames' => 'tx_myext_domain_model_book',
'table_local' => 'sys_file',
),
'foreign_types' => array(
'0' => array(
'showitem' => '
--palette--;;imagePalette,
--palette--;LLL:EXT:lang/locallang_tca.xlf:sys_file_reference.imageoverlayPalette;imageoverlayPalette,
--palette--;;filePalette',
),
),
), $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext']),
),

How can I hide create new button in TYPO3 TCA type inline?

I would like to hide "create new" image button in case of TCA for field type is inline.
My code is below:
<pre>
'image' => array(
'label' => 'Image',
'config' => array(
'type' => 'inline',
'foreign_table' => 'sys_file_reference',
'foreign_field' => 'uid_foreign',
'foreign_sortby' => 'sorting_foreign',
'foreign_table_field' => 'tablenames',
'foreign_match_fields' => array(
'fieldname' => 'field_slide_image',
),
'foreign_label' => 'uid_local',
'foreign_selector' => 'uid_local',
'foreign_selector_fieldTcaOverride' => array(
'config' => array(
'appearance' => array(
'elementBrowserType' => 'file',
'elementBrowserAllowed' => $allowedFileExtensions
)
)
),
'filter' => array(
array(
'userFunc' => 'TYPO3\\CMS\\Core\\Resource\\Filter\\FileExtensionFilter->filterInlineChildren',
'parameters' => array(
'allowedFileExtensions' => $allowedFileExtensions,
'disallowedFileExtensions' => $disallowedFileExtensions
)
)
),
'appearance' => array(
'useSortable' => TRUE,
'headerThumbnail' => array(
'field' => 'uid_local',
'width' => '45',
'height' => '45c',
),
'showPossibleLocalizationRecords' => FALSE,
'showRemovedLocalizationRecords' => FALSE,
'showSynchronizationLink' => FALSE,
'showAllLocalizationLink' => FALSE,
'showPossibleRecordsSelector' => "hide",
'enabledControls' => array(
'info' => FALSE,
'new' => false,
'dragdrop' => TRUE,
'sort' => true,
'hide' => TRUE,
'delete' => TRUE,
'localize' => TRUE,
),
),
'behaviour' => array(
'localizationMode' => 'select',
'localizeChildrenAtParentLocalization' => TRUE,
),
),
)
</pre>
I have added this code 'new' => false, but still it is not working.
Found Solution :
I have found one solution https://forge.typo3.org/issues/71918
I hope this can help for other users.
Use the permission system of TYPO3 to only allow read access to the field for a certain user group.
Hide "New" Button in TCA with
['appearance']['enabledControls']['new'] = false
This works in 8.x only.
Found Solution :
I have found one solution https://forge.typo3.org/issues/71918
// Render the level links (create new record):
if ($config['appearance']['enabledControls']['new']) {
> $levelLinks = $this->getLevelInteractionLink('newRecord', $nameObject . '-' . $foreign_table, $config);
}
Afaik, the "new" button only becomes hidden if the "maxitems" limit is set and reached.

new content element at content wizard

I have some problems with typo 7.6.2
I would like to add my own content elements to the content-element wizard.
My own extension with templates, partials, TypoScript... worked and the element is visible in the content-element wizard.
Content-element Wizard
If I choose the new element and click the place to add the following screen is shown.
(ext_tables.php):
TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addStaticFile(
$_EXTKEY,
'Configuration/TypoScript',
'Template Extension'
);
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPageTSConfig('
mod {
wizards.newContentElement.wizardItems.extra {
header = KCW Inhalte
elements {
mitglied {
icon = ../typo3/sysext/core/Resources/Public/Icons/T3Icons/content/content-header.svg
title = Mitglied
description = Ein Mitglied anlegen
tt_content_defValues {
CType = mitglied
}
}
}
show = *
}
}
');
"Configuration/TCA/Overrides/tt_content.php":
$TCA['mitglied'] = array(
'columns' => array(
'name' => array (
'exclude' => 1,
'label' => 'Vorname Name',
'config' => array (
'type' => 'input',
'size' => '20'
)
),
'spitzname' => array (
'exclude' => 1,
'label' => 'Spitzname',
'config' => array (
'type' => 'input',
'size' => '20'
)
),
'geburtstag' => array (
'exclude' => 1,
'label' => 'Geburtstag',
'config' => array (
'type' => 'input',
'size' => '10',
'eval' => 'date',
)
),
'posten' => array (
'exclude' => 1,
'label' => 'Posten',
'config' => array (
'type' => 'select',
'renderType' => 'selectSingle',
'items' => array (
array('Mitglied'),
array('Präsident'),
array('Kassenwart'),
array('Vergnügungsausschuss'),
),
'size' => 1,
'maxitems' => 1,
)
),
'foto' => array (
'exclude' => 1,
'label' => 'Foto',
'config' => array(
'type' => 'group',
'internal_type' => 'file',
'allowed' => 'jpg',
'max_size' => 1000,
'uploadfolder' => 'uploads/pics/',
'show_thumbs' => 1,
'size' => 3,
'minitems' => 1,
'maxitems' => 1,
'autoSizeMax' => 10,
)
),
),
'types' => array(
'0' => array('showitem' => 'name,spitzname,geburtstag,posten,foto')
)
);
\TYPO3\CMS\Core\Utility\ArrayUtility::mergeRecursiveWithOverrule($GLOBALS['TCA']['tt_content'], $tcaTtContent);
I think the problem is located in these lines in ext_tables.php:
tt_content_defValues {
CType = mitglied
}
You have to allow the value mitglied as value of the field cType. The tt_content_devValues just sets the default values for the newly created content element.
TCEFORM.tt_content.cType.addItems.mitglied = Field title
https://docs.typo3.org/typo3cms/TSconfigReference/PageTsconfig/TCEform/Index.html#pagetceformconfobj

How to modify the TCA ImageManipulation configuration of a FAL reference?

In TYPO3 7.4 I have the following TCA configuration for uploading a single image with the new ImageManipulation (crop tool) enabled:
'single_image_field' => array(
'exclude' => 1,
'label' => 'LLL:EXT:myext/Resources/Private/Language/locallang_db.xlf:sometable.single_image_field',
'config' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getFileFieldTCAConfig(
'single_image_field',
array(
'maxitems' => 1,
'appearance' => array(
'collapseAll' => 1,
'expandSingle' => 1,
),
'foreign_types' => array(
\TYPO3\CMS\Core\Resource\File::FILETYPE_IMAGE => array(
'showitem' => '--palette--;LLL:EXT:lang/locallang_tca.xlf:sys_file_reference.imageoverlayPalette;imageoverlayPalette,--palette--;;filePalette'
),
)
),
'jpg,jpeg,png'
),
),
Now I like to have my custom aspect ratio's configured. This seems possible with the TCA configuration of column type: ImageManipulation (see: https://wiki.typo3.org/TYPO3.CMS/Releases/7.2/Feature#Impact_9).
But how can I apply this in the above configuration?
The default crop aspect ratio's for sys_file_reference can be overwritten as follows:
$GLOBALS['TCA']['sys_file_reference']['columns']['crop']['config']['ratios'] = array(
'1.7777777777777777' => '16:9',
'1.3333333333333333' => '4:3',
'1' => '1:1',
'NaN' => 'Free',
);

how to use "filerenameupload" filter in zend framework2?

i add file element in form class with:
$this->add(array(
'type' => 'Zend\Form\Element\File',
'name' => 'logo_file',
'options' => array(
'label' => 'Select your logo image file:',
),
));
then add filter in model for filtering form data. i use "filerenameupload" filter to upload selected file :
$inputFilter = new InputFilter();
$inputFilter->add($factory->createInput(array(
'name' => 'logo_file',
'required' => false,
'filters' => array(
array('name' => 'filerenameupload',
'options'=>array(
//'target' => "./data/logo.png",
'randomize' => true,
)
),
),
)));
and in controller i call setInputFilter, setData and isValid normally. other elements go filter good, but "logo_file" does not be saved in "./data/logo.png".
in fact "filter" function in "Zend\Filter\File\RenameUpload" class does not be executed.
i use this link :
zf2 File Uploding Toturial
Someone's trying to solve this problem?
Have you tried using the full name for the Filter?
array(
'name' => 'Zend\Filter\File\RenameUpload'
)
You also need to make sure you add both the files array and the POST data to the form when validating, example:
$postArr = $request->getPost()->toArray();
$fileArr = $this->params()->fromFiles('logo_file');
$formData = array_merge(
$postArr, // $_POST
array('logo_file' => $fileArr['name']) // $_FILE...
);
$importForm->setData($formData);
Try:
Form.php:
public function addElements(){
$this->add(array(
'name' => 'image',
'attributes' => array(
'type' => 'file',
),
'options' => array(
),
));
FormValidator.php
public function getInputFilter()
{
if (!$this->inputFilter) {
$inputFilter = new InputFilter();
$factory = new InputFactory();
$inputFilter->add($factory->createInput(array(
"name" => "image",
"required" => true,
"filters" => array(
array("name" => "StripTags"),
array("name" => "StringTrim"),
array(
"name" => "Zend\Filter\File\RenameUpload",
"options" => array(
"target" => '/home/limonazzo/UPLOADDIR<----------',
"randomize" => true,
"use_upload_name" => true,
"use_upload_extension" => true
)
)
),
"validators" => array(
array(
"name" => "Zend\Validator\File\IsImage",
"break_chain_on_failure" => true,
"options" => array(
),
),
array(
"name" => "Zend\Validator\File\Extension",
"break_chain_on_failure" => true,
"options" => array(
"extension" => "jpg,jpeg,png",
),
),
array(
"name" => "Zend\Validator\File\Size",
"break_chain_on_failure" => true,
"options" => array(
"min" => "1kB",
"max" => "1024kB",
),
),
array(
"name" => "Zend\Validator\File\ImageSize",
"break_chain_on_failure" => true,
"options" => array(
"minWidth" => 10,
"minHeight" => 10,
"maxWidth" => 250,
"maxHeight" => 350,
),
),
),
)));
In controlle.php
$form = new Form();
$formValidator = new FormValidator();
$form->setInputFilter($formValidator->getInputFilter(''));
if ($form->isValid()) {
$data = $form->getData(\Zend\Form\FormInterface::VALUES_AS_ARRAY);
$imgName = $data["image"]["tmp_name"];