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?
Related
I'm having some issues with the Codeigniter 4 validation rules. I'm using the is_unique function within the ruleset in Order to except one single row from the validation.
The problem here is that there are two fields in the table that need to be checked:
'episodeTitle' => [
'label' => 'episodeTitle',
'rules' => 'required|max_length[100]|is_unique[episodes.episodeTitle,episodes.episodeID,' . $episodeID . ',episodes.podcastID,' . $podcastID . ']',
'errors' => [
'required' => lang('Errors.nested.episode.episodeTitleRequired'),
'max_length' => lang('Errors.nested.messages.maxLength100'),
'is_unique' => lang('Errors.nested.episode.episodeTitleUnique'),
],
],
Is it possible, to make the exception depending on 2 or more fields?
I want to check the episodeID AND the podcastID not only one of these values.
You need to create a custom rule to achieve what you're looking for.
Rules are stored within simple, namespaced classes. They can be stored any location you would like, as long as the autoloader can find it. These files are called RuleSets. To add a new RuleSet, edit Config/Validation.php and add the new file to the $ruleSets array:
public $ruleSets = [
\CodeIgniter\Validation\Rules::class,
\CodeIgniter\Validation\FileRules::class,
\CodeIgniter\Validation\CreditCardRules::class,
];
Within the file itself, each method is a rule and must accept a string as the first parameter, and must return a boolean true or false value signifying true if it passed the test or false if it did not:
class MyRules
{
public function check_unique(string $str): bool
{
// Your code to check the values and don't forget to return true or false.
}
}
Then in your validation just use the check_unique rule.
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!
I was trying to show/hide ActionColumn based on some condition.
In my system, 2 roles are defined : Primary & Secondary. I wanted to hide ActionColumn for Role Secondary and to show ActionColumn for Role Primary.
I got one visible attribute option from $visible. Where, 'visible'=> true and 'visible'=> false are working properly.
<?
[
'class' => 'yii\grid\ActionColumn',
'visible' => false,
.
.
.
]
But, Problem is: I wanted to set visible option as True / False dynamically based on some condition.
<?
[
'class' => 'yii\grid\ActionColumn',
'visible' => function ($data) {
if (Yii::$app->userinfo->hasRole([AR::ROLE_PRIMARY])) {
return true;
}
if (Yii::$app->userinfo->hasRole([AR::ROLE_SECONDARY])) {
return false;
}
},
.
.
.
]
I tried in this way too. But, didn't got luck. Any help/hint/suggestion is appreciable.
I searched Yii2 GridView hide column conditionally.
You can't set visible to a callable, although there is nothing to stop you setting a variable before calling the gridview.
In this case though, visibility is only dependant on whether they have the primary role, you can just use:
'visible' => Yii::$app->userinfo->hasRole([AR::ROLE_PRIMARY])
You can use conditional statement to hide particular checkbox in grid view
Here is simple code which works for me
[
'class' => 'yii\grid\CheckboxColumn',
'checkboxOptions' => function($dataProvider) {
return ["value" => ($dataProvider['tiIsPaid'] == 0)?$dataProvider['iDriverEarningId']:'',"style"=>($dataProvider['tiIsPaid'] == 0)?'':'display:none'];},
]
Here i have used simple logic to hide checkbox for particular column
Set value null or blank so it can not be selected when you click on select all checkbox
Hide check box using display none property of css
Hope this help you in hiding particular column based on your conditions.
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.
I'm using Drupal 6.x and I'm writing a php class that will grab an RSS feed and insert it as nodes.
The problem I'm having is that the RSS feed comes with images, and I cannot figure out how to insert them properly.
This page has some information but it doesn't work.
I create and save the image to the server, and then I add it to the node object, but when the node object is saved it has no image object.
This creates the image object:
$image = array();
if($first['image'] != '' || $first['image'] != null){
$imgName = urlencode('a' . crypt($first['image'])) . ".jpg";
$fullName = dirname(__FILE__) . '/../../sites/default/files/rssImg/a' . $imgName;
$uri = 'sites/default/files/rssImg/' . $imgName;
save_image($first['image'], $fullName);
$imageNode = array(
"fid" => 'upload',
"uid" => 1,
"filename" => $imgName,
"filepath" => $uri,
"filemime" => "image/jpeg",
"status" => 1,
'filesize' => filesize($fullName),
'timestamp' => time(),
'view' => '<img class="imagefield imagefield-field_images" alt="' . $first['title'] . '" src="/' . $uri . '" /> ',
);
$image = $imageNode;
}
and this adds the image to the node:
$node->field_images[] = $image;
I save the node using
module_load_include('inc', 'node', 'node.pages');
// Finally, save the node
node_save(&$node);
but when I dump the node object, it no longer as the image. I've checked the database, and an image does show up in the table, but it has no fid. How can I do this?
Why not get the Feedapi, along with feedapi mapper, and map the image from the RSS field into an image CCK field you create for whatever kind of node you're using?
It's very easy, and you can even do it with a user interface.
Just enable feedapi, feedapi node (not sure on the exact name of that module), feedapi mapper, and create a feed.
Once you've created the feed, go to map (which you can do for the feed content type in general as well) on the feed node, and select which feed items will go to which node fields.
You'll want to delete your feed items at this point if they've already been created, and then refresh the feed. That should be all you need to do.
Do you need to create a separate module, or would an existing one work for you?
Are you using hook_nodeapi to add the image object to the node object when $op = 'prepare'?
If you read the comments on the site you posted, you'll find:
To attach a file in a "File" field
(i.e. the field type supplied by
FileField module) you have to add a
"description" item to the field array,
like this:
$node->field_file = array(
array(
'fid' => 'upload',
'title' => basename($file_temp),
'filename' => basename($file_temp),
'filepath' => $file_temp,
'filesize' => filesize($file_temp),
'list' => 1, // always list
'filemime' => mimedetect_mime($file_temp),
'description' => basename($file_temp),// <-- add this
), );
maybe that works. You could also try to begin the assignment that way:
$node->field_file = array(0 => array(...
If you are just grabbing content wich has images in, why not just in the body of your nodes change the path of the images to absolute rather than local, then you won't have to worry about CCK at all.
Two other things that you may need to do
"fid" => 'upload', change this to the fid of the file when you save it. If it isn't in the files table then that is something you will need to fix. I think you will need feild_file_save_file()
2.you may need an array "data" under your imageNode array with "title", "description" and "alt" as fields.
To build file information, if you have filefield module, you can also use field_file_load() or field_file_save_file(). See file filefield/field_file.inc for details.
Example:
$node->field_name[] = field_file_load('sites/default/files/filename.gif');