TYPO3 TCA value as a variable on Fluid - php

I have a base extension so i can version my website. That means i have not a controller or a repository on the extension. So what i want to do, is to create my own settings on existing elements. I was experimenting around with a text align values on the header content element.
Keep in mind, there is already a setting for this, but i am just
experimenting.
I figured out how to add them and the values are saved on the database.
What i now want to do, is to take the values and add them as a class on FLUID. This is where i stuck. I can not get the values. Any idea how to do it?
After this guide How to enable header_position in TYPO3 7.6
i manage to get my code that far:
On the folder /Configuration/TCA/Overrides/tt_content.php
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
ExtensionManagementUtility::addTCAcolumns('tt_content',[
'header_position_custom' => [
'exclude' => 1,
'label' => 'header position',
'config' => [
'type' => 'select',
'renderType' => 'selectSingle',
'items' => [
['left', 'left'],
['right', 'right'],
['center', 'center']
]
]
]
]);
ExtensionManagementUtility::addFieldsToPalette('tt_content', 'header', '--linebreak--,header_position_custom', 'after:header_layout');
ExtensionManagementUtility::addFieldsToPalette('tt_content', 'headers', '--linebreak--,header_position_custom', 'after:header_layout');
On the folder /Configuration/Typoscript/Constants/Base.typoscript
styles.templates.templateRootPath = EXT:my_website_base/Resources/Private/Extensions/Fluid_styled_content/Resources/Private/Templates/
styles.templates.partialRootPath = EXT:my_website_base/Resources/Private/Extensions/Fluid_styled_content/Resources/Private/Partials/
styles.templates.layoutRootPath = EXT:my_website_base/Resources/Private/Extensions/Fluid_styled_content/Resources/Private/Layouts/
On the /Resources/Private/Extensions/Fluid_styled_content/Resourcs/Private/Partials/Header.html
<h1 class="{positionClass} {header_position_custom} {data.header_position_custom} showed">
<f:link.typolink parameter="{link}">{header}</f:link.typolink>
</h1>
I 've put the class showed just to make sure that i am reading the
file from the path i gave on the constants
File ext_tables.php
TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addStaticFile($_EXTKEY,'Configuration/TypoScript', 'Website Base');
File ext_tables.sql
CREATE TABLE tt_content (
header_position_custom varchar(255) DEFAULT '' NOT NULL,
);
With all these i get my selectbox where i wanted to be and i get the values on the database. That means that if i select the value "Center" in the selectbox, then it will be saved on the database. How can i get this value and use it as class on the FLUID?
Thanks in advance,

You will find your field in the data object.
For inspecting your fluid variables you can use the f:debug-VH:
<f:debug title="the data">{data}</f:debug>
for inspecting all (in the current context) available variables you can debug _all:
<f:debug title="all data">{_all}</f:debug>
Hint: use the title attribute to identify the output
and don't forget to write a get* and set* function for new fields!

Related

TYPO3 Media-Emelent own field

is it possible to extend the media type in my typo3 extension?
Default fields are alternative, title, desription.
How can i add a own field?
$GLOBALS['TCA']['tt_content']['types']['my_slider'] = [
'showitem' => '
--palette--;' . $frontendLanguageFilePrefix . 'palette.general;general,
--palette--;' . $languageFilePrefix . 'tt_content.palette.mediaAdjustments;mediaAdjustments,
pi_flexform,
--div--;' . $customLanguageFilePrefix . 'tca.tab.sliderElements,
assets
',
'columnsOverrides' => [
'media' => [
'label' => $languageFilePrefix . 'tt_content.media_references',
'config' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getFileFieldTCAConfig('media', [
'appearance' => [
'createNewRelationLinkTitle' => $languageFilePrefix . 'tt_content.media_references.addFileReference'
],
// custom configuration for displaying fields in the overlay/reference table
// behaves the same as the image field.
'foreign_types' => $GLOBALS['TCA']['tt_content']['columns']['image']['config']['foreign_types']
], $GLOBALS['TYPO3_CONF_VARS']['SYS']['mediafile_ext'])
]
]
];
if you analyze the datastructure of your TYPO3 database you will find: those fields (title and alternative) are not fields in the table sys_file but in sys_file_metadata (and in sys_file_reference for overwriting them on a specific usage)
With that knowledge you can add your fields to these tables and give them a proper rendering and behaviour.
Adding the fields to sys_file_metadata will make them available for every file as default values if the fiel is used anywhere.
If you want these fields appear only at special usage you need to set the fields only for the table sys_file_reference which is used only for relations between a file and it's usage. AND you need to set conditions to show the fields only if your content elements use a file. This condition might be a litte complicated. if you use inidvidual tables the condition could be used the usage of this foreign_table, if you use tt_content records you also need to include the CTypeof the record in the condition. Probably you will need an userfunc.
Or you have an unique fieldname?

yii2 DetailView template/layout without values

I have a little problem in yii2 framework.
I have DetailView widget
<?= DetailView::widget([
'model' => $table_1,
'attributes' => [
'year',
'table_zs_field_1',
'table_zs_field_2',
'table_zs_field_3',
'table_zs_field_4',
'table_zs_field_5',
'table_zs_field_6',
'table_zs_field_7',
'table_zs_field_8',
'table_zs_field_9',
'table_zs_field_10',
'table_zs_field_11',
'table_zs_field_12',
'table_zs_field_13',
'table_zs_field_14',
'table_zs_field_15',
'table_zs_field_16',
'table_zs_field_17',
'table_zs_field_18',
'table_zs_field_19',
],
]) ?>
If i write this to code I'll see a DetailView widget with names of fields(get from model) and values.
Problem: I want to hide values and show only names of fields from model and in next time hide names and show only values. Anybody know ?
Change the $template property of the Detailview.
The Default is
$template = '<tr><th>{label}</th><td>{value}</td></tr>'
Adding
'template'=>'<tr><th>{label}</th></tr>' ,
to the config array of your DetailView should show only the names of the fields.
Adding
'template'=>'<tr><td>{value}</td></tr>',
should show only the value.
See the corresponding section in the Documentation of DetailView.

how to Assign name to drop down options

Using Phalcon framework, I have a Form class file where I declare select and render in .volt file:
$soc_bulding = new Select("soc_building_id", $options['soc_bulding'],
array('using' => array('soc_building_id', 'soc_building_name'),
"class" => "mandatory-field") );
$soc_bulding->setLabel("Buiding name" . REQ_FIELD);
$this->add($soc_bulding);
in the above code, 'using' => array('soc_building_id', 'soc_building_name') reflect soc_building_id as option value and soc_building_name actual text in drop down option, but I want one more property name in that same option box, already tried to pass 3 parameter to that array but it's not working.
Please use the code below and replace yours
echo $this->tag->select(array("users",
Users::find(),
"useEmpty" => true,
"emptyText" => "Please select",
"using" => array("id", "name"),
));

Yii2:Date Application Formatter

I am using Yii::$app->formatter in one of my attribute like:
Controller code
$model->discharge_date=Yii::$app->formatter->asDatetime
($model->discharge_date, 'php:d-M-Y H:i');
Model Code
[['admission_date','discharge_date'],'date','format' => 'php:d-M-Y H:i'],
Everything is working fine except when discharge date is left blank, on update it is filled with this line:
<span class="not-set">(not set)</span>
I couldn't make out from where this is coming, as in the DB the value is NUll
Thanks.
It's default and expected behavior.
See documentation for $nullDisplay property of Formatter.
You can cnahge that across application through application configuration:
'formatter' => [
'nullDisplay' => '',
],
For specific view you can change it through formatter component (note that you should add that code before view is rendered):
use Yii;
...
Yii::$app->formatter->nullDisplay = '';

How do I set the 'value' in my Zend form checkbox?

The Zend Form is proving to be a bit tricky for me, even as much as I am working with it lately...
I have this form and I am attempting to dynamically create the several checkboxes for it. It is working out alright, except I cannot seem to get the 'value' attribute to change.
In my Zend form class I have this snippet...
// psychotic symptoms
$this->addElement('checkbox', 'psychoticsymptom', array(
'label' => 'psychoticsymptom',
'name' => 'psychoticsymptom',
));
In my view (phtml) I am calling it like this...
<div class="element">
<?php // Psychotic Symptoms
$Criteria = new Criteria();
$Criteria->add( DictionaryPeer::CATEGORY, 'MAR: Psychotic Symptoms' );
$Criteria->addAscendingOrderByColumn( 'Ordinal' );
$this->PsychoticSymptomsList = DictionaryPeer::doSelect( $Criteria );
foreach( $this->PsychoticSymptomsList as $Symptom ) {
$form->psychoticsymptom->setValue($Symptom->getDictionaryId());
$form->psychoticsymptom->setAttrib('name', $Symptom->getWord());
echo $Symptom->getDictionaryId(); // prove my id is coming through... (it is)
$form->psychoticsymptom->getDecorator('label')->setTag(null);
echo $form->psychoticsymptom->renderViewHelper();
$form->psychoticsymptom->setLabel($Symptom->getWord());
echo $form->psychoticsymptom->renderLabel();
echo '<br />';
}
?>
</div>
Everything seems to be working fine, except the value attribute on each checkbox is rendering a value of '1'. I have tried moving the 'setValue' line to several different positions, as to set the value before the form element renders but I am having no luck getting this to work. It's worth any effort to me because I need to do the same type of operation in many areas of my application. I would have done this a bit different too, but I am re-factoring another application and am trying to keep some things unchanged (like the database for instance).
Any help is much appriciated
Thanks
you can try to overwrite the "checkedValue" and "uncheckedValue". check this reference
$this->addElement('checkbox', 'psychoticsymptom', array(
'label' => 'psychoticsymptom',
'name' => 'psychoticsymptom',
'checkedValue' => 'checked Value',
'uncheckedValue' => 'unchecked Value'
));
You seem to only have one psychoticsymptom element "checkbox" which your adding (changing) the value too for each $this->PsychoticSymptomsList.
Maybe you would be better off using a multicheckbox element instead.

Categories