How can I set the icon for a content element in TYPO3? - typo3

In tt_content I have added something like this, and set the core icon 'content-image':
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTcaSelectItem(
'tt_content',
'CType',
[
'My Element',
'myelement',
'content-image'
],
'textmedia',
'after'
);
And this works in the 'Type' dropdown menu. However, when in Page or List view it always shows the default text icon. How do I change this to match the type menu?

Just found another question with a real good answer - mainly the same
as mine, but better structured - have a look:
How to setup icons for content elements or plugins in a TYPO3 extension
You may revisit https://docs.typo3.org/m/typo3/reference-coreapi/main/en-us/ApiOverview/ContentElements/AddingYourOwnContentElements.html with a full overview.
The \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTcaSelectItem() registers the icon only for the select field.
For the "new content element" wizard you have to provide a proper TSconfig part https://docs.typo3.org/m/typo3/reference-coreapi/main/en-us/ApiOverview/ContentElements/AddingYourOwnContentElements.html#add-it-to-the-new-content-element-wizard
// example - you must adopt for your element
mod.wizards.newContentElement.wizardItems {
// add the content element to the tab "common"
common {
elements {
examples_newcontentelement {
iconIdentifier = content-text
title = LLL:EXT:examples/Resources/Private/Language/locallang.xlf:examples_newcontentelement_title
description = LLL:EXT:examples/Resources/Private/Language/locallang.xlf:examples_newcontentelement_description
tt_content_defValues {
CType = examples_newcontentelement
}
}
}
show := addToList(examples_newcontentelement)
}
}
If you want to use a custom image, you have to register it. Either in ext_localconf.php with proper icon calls or depending on the core version with the simple Configuration/Icons.php file.
See for 11.5+ https://docs.typo3.org/m/typo3/reference-coreapi/main/en-us/ApiOverview/Icon/Index.html or before see https://docs.typo3.org/m/typo3/reference-coreapi/10.4/en-us/ApiOverview/Icon/Index.html
The next part is then TCA configuration for the specific table. Generic table icon file is configured with:
// or $GLOBALS if done as TCA Override for a existing table
return [
// ...
'ctrl' => [
'iconFile' => '',
// ...
],
// ...
https://docs.typo3.org/m/typo3/reference-tca/main/en-us/Ctrl/Properties/Iconfile.html
Table with types can have different icons per types, which can be set with typeicon_classes
https://docs.typo3.org/m/typo3/reference-tca/main/en-us/Ctrl/Properties/TypeiconClasses.html#ctrl-reference-typeicon-classes - however, this depends on the type field. For tt_content this is "CType". So this helps only for real content elements which registeres as own CType - and not as list CType with a subtype list_type. For extbase plugin this is done with the proper plugin registration in Configuration/TCA/Overrides/tt_content.php:
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerPlugin(
'ExtkeyInCamelCase',
'PluginIdentifier',
'plugin title',
// icon
'my-icon');

Related

TYPO3 preview image of inline records

A tt_content custom content element (imageslider) has IRRE slides.
The slide record has a title and an image (filereference).
Is it possible to preview the image of the IRRE record?
The previewRenderer class seems to be oriented only on the page view.
typo3/sysext/backend/Classes/Form/Container/InlineRecordContainer.php shows a TCA setting for headerThumbnail
However this TCA doesn't produce the headerThumbnail.
'appearance' => [
'headerThumbnail' => [
'field' => 'image',
'width' => '45',
'height' => '45c',
],
So a userFunc or something is needed to retrieve the fileUid for field? Or is there an easier solution possible?
[EDIT] An IRRE record could of course have multiple images. So I guess this should be a feature for the InlineRecordContainer class, like the previewRenderer class to adjust the look and content.
Nice hint, that there should be custom thumbnails possible...
After diving a bit deeper in InlineRecordContainer, it seems to be clear, that this can't work (anymore?). There are (in v10/v11) the following lines:
// Renders a thumbnail for the header
if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['thumbnails'] && !empty($inlineConfig['appearance']['headerThumbnail']['field'])) {
$fieldValue = $rec[$inlineConfig['appearance']['headerThumbnail']['field']];
$fileUid = $fieldValue[0]['uid'];
For the UID of the thumbnail, the first array entry in the given field is used. But when debugging $rec (=$data['databaseRow']), we see, it is just the raw record, which means a FAL-field will not be an array but only an integer that counts the relations...
IMO this is a bug. I have just reported it: https://forge.typo3.org/issues/96188

Add custom elements to TYPO3 as hidden by default?

I have an installation with multiple websites. Each site has a site package with custom fields and content elements that are specific to that site.
But the custom fields and content elements are shown on all sites.
In tt_content.php I add a custom element to the type dropdown. How can I make it hidden, then enable it in ts config for the page tree that it is used for?
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTcaSelectItem(
'tt_content',
'CType',
[
'Banner',
'my_extension_banner',
'EXT:core/Resources/Public/Icons/T3Icons/content/content-image.svg'
],
'textmedia',
'after'
);
Likewise, I have some custom fields added to existing elements. How can I make this field hidden unless specifically enabled by the ts config of the page that it is made for?
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addFieldsToPalette(
'tt_content',
'headers',
'--linebreak--,my_extension_myfield',
'after:subheader'
);
After some trial and error, I found that I can remove elements and fields globally by adding this to my ext_localconf.php:
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPageTSConfig('
#Remove Custom Content Elements
TCEFORM.tt_content.CType.removeItems := addToList(my_extension_banner)
#Remove Custom Fields
TCEFORM.tt_content {
my_extension_myfield.disabled = 1
}
');
Then add them in again with my page specific ts config file PageTSConfig.tsconfig
#Add Custom Content Elements
TCEFORM.tt_content.CType.removeItems := removeFromList(my_extension_banner)
#Add Custom Fields
TCEFORM.tt_content {
my_extension_myfield.disabled = 0
}
I don't know if I understand the problem correctly, but you could place Page TsConfig in the root page of any web page and then hide the fields accordingly:
TCEFORM.pages {
subtitle.disabled = 1
}

How to add condition for a field in the layout of SuiteCRM.?

In that in studio I have created some fields in one module and i also add those fields in Layout. but i want to display the fields according to the selection, for example: if user select option-1 from dropdown field then it has to display say only three field, and if user select option-2 from dropdown field then it has to display say six fields. so i need to add some condition in the layout field. but i can't find any option there.. please help me to find out.
i also attached the example image below.
If you are using sugar 7.6 I can help,
You want to change the fields according to drop down values if i am not wrong .
For that you have to right a code in "record.js" and "create-actions.js" files . just write a js function.
This is an example for crerate-action.js
({
extendsFrom: 'CreateActionsView',
initialize: function (options) {
this.model.on("change:dropdown", this.renderFields, this);
},
renderFields: function () {
// write your code here
},
})
You need to modify the view definitions to add a script into the edit view of your module.
Example:
$viewdefs ['<Module Name>'] =
array(
'<View Name>View' =>
array(
'templateMeta' =>
array(
...
'includes' =>
array(
0 =>
array(
'file' => 'path/to/your/script.js',
),
1 =>
array(
'file' => 'path/to/your/script.js',
),
),
...
),
...
),
...
);
You then can use jQuery or any javascript library to hide or show the fields. if you are using SuiteR or SuiteP theme you can simply add/remove the hidden class to the elements.
Just make sure that you add all the fields into your view which you wish to show or hide.
To make this upgrade save modify or create
custom/modules/module name/metadata/editviewdefs.php for the edit view
custom/modules/module name/metadata/detailviewdefs.php for the detail view
There are many defined ways in sugarcrm, as you have created new fields, all you need to add dependencies on those fields like
$dictionary['YOUR_MODULE_NAME']['fields']['YOUR_FIELD_NAME']['dependency']='(equal($YOUR_DROPDOWN,"OPTION_1"))
see
http://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_7.7/Architecture/Sugar_Logic/Dependency_Actions/SetVisibility/#Visibility_Dependencies_in_Field_Definitions
This can also be added through Studio.
Go to Studio > module > fields > YOUR_FIELD > Dependent and add dependency.

Display Views exposed form item label inside selects (Instead of the default '- Any -')?

How to display form item label in Views exposed form instead of '- Any -'? To be more specific I use this code to replace select's default value text with custom text and want that custom text to be the label of that element:
function THEMENAME_form_views_exposed_form_alter(&$form, &$form_state) {
//dpm($form);
if ($form['#id'] == 'views-exposed-form-FORMID') {
$form['ITEMNAME']['#options']['All'] = t('My custom translatable text');
}
}
This works for custom text. What I want is to display its label instead of My custom translatable text with the simple code like:
$form['ITEMNAME']['#options']['All'] = $form['ITEMNAME']['#name'];
but have no luck on such and similar codes to work. According fo $dpm($form) output '#name', '#title' elements seem not to exist at all.
The goal is to have similar functionality of https://drupal.org/project/compact_forms or https://drupal.org/project/In-Field-Labels without another Javascript library (prefer to use couple PHP lines, please no JS solutions)
Your above code will work in case of select field but not for text field. If you need it to work for text fields you can try this
$form['ITEMNAME']['#attributes'] = array('placeholder' => array('My custom translatable text'));
or
$form['ITEMNAME']['#attributes'] = array('placeholder' =>$form['ITEMNAME']['#name']);
hope this helps you

How to apply a different wrap in a TMENU for certain items only?

In a TMENU, I would like to apply a special wrap to certain pages only.
So of
Home
-- This
-- That
-- Such
-----A
-----Thing
Only the page "Such" would have this wrap (with a special class or an icon for wrapItemsAndSub).
Ideally, this could be done from the page tree / from the CMS. Or by pid.
But I think it's not possible to reach into the TMENU in an easy way?
OptionSplit is not an option, as it's only a few special pages.
Can this be done and how?
You must use CASE object here and apply that to property/wrap which has stdWrap.
Look at this example.
NO {
wrapItemAndSub.cObject = CASE
wrapItemAndSub.cObject {
key.field = uid
default = TEXT
default.value = <li>|</li>
// for page uid = 99
99 = TEXT
99.value = <li class="special">|</li>
}
}
You can use this way to every element that has stdWrap.
BTW: as pgampe said it can be of course done more universal with some checkbox or even dropdown when you select class name.
This is a short tutorial for checkbox. For this tutorial I assume the extension name is "t3_local"
STEP 1
In ext_tables.sql file add:
CREATE TABLE pages (
tx_t3local_special tinyint(4) DEFAULT '0' NOT NULL,
}
Then go into Extension Manager into your extension and update database to create the new field in pages table.
STEP 2
In ext_tables.php file add:
$tempColumns = Array(
'tx_t3local_special' => Array(
'exclude' => 1,
'label' => 'Some label for special',
'config' => Array(
'type' => 'check',
'default' => 0
)
)
);
t3lib_div::loadTCA('pages');
t3lib_extMgm::addTCAcolumns('pages', $tempColumns, 1);
t3lib_extMgm::addToAllTCAtypes('pages', 'tx_t3local_special');
It is ready now to use in the backend. After you clear the TYPO3 cache you should see the checkbox in page properties. Now we must only use it to build our menu in frontend.
STEP 3
Now it all depends what do you want to do with this switch. Assuming that you want to add a class for li here is a little trick how to allow to use several such switches to accumulate different classes.
NO.wrapItemAndSub.stdWrap {
prepend.cObject = LOAD_REGISTER
prepend.cObject {
special1class.cObject = TEXT
special1class.cObject {
value = special1-class
if.isTrue.field = tx_t3local_special
}
special2class.cObject = TEXT
special2class.cObject {
value = special2-class
if.isTrue.field = tx_t3local_special2
}
}
append = TEXT
append.value = <li class="clearfix {register:special1class} {register:special2class}">/li>
append.insertData = 1
}
NOTE
As you now know how to add switches to page property you can also use them to turn off/on some functionality on page. For example I use such switch to turn on/off breadcrumbs for page. In this example the if checkbox is checked the breadcrumb of off.
For this working you must remember to add the field name to typo3conf/localconf.php file (or LocalConfiguration.php in 6.x)
$TYPO3_CONF_VARS['FE']['addRootLineFields'] .= ',tx_t3local_breadcrumb';
And the TS:
lib.breadcrumb = COA
lib.breadcrumb.stdWrap.if.isFalse.data = page:tx_t3local_breadcrumb
lib.breadcrumb {
...
...
...
}