TYPO3 Custom Content fields on save database error - database

I added some content Fields which looks as it follows;
$temporaryColumnHC = array(
'my_type' => array(
'exclude' => 0,
'label' => 'My Type',
'config' => array(
'type' => 'select',
'renderType' => 'selectSingle',
'items' => array(
array('Bar', 'bar'),
array('Pie', 'pie'),
array('Donut', 'donut'),
array('Line', 'line'),
array('Bar 2', 'bar2'),
array('Bar 3', 'bar3'),
array('Bubble', 'bubble'),
)
)
),
'my_suffix' => array(
'exclude' => 0,
'label' => 'My Label Suffix',
'config' => array(
'type' => 'input',
'size' => 10,
'max' => 20
)
),
'my_source_url' => array(
'exclude' => 0,
'label' => 'Source URL',
'config' => array(
'type' => 'input',
'renderType' => 'inputLink'
)
),
'my_source' => array(
'exclude' => 0,
'label' => 'Source Text',
'config' => array(
'type' => 'text',
'cols' => 40,
'rows' => 15
)
),
);
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns(
'tt_content',
$temporaryColumnHC
);
but on save I get the following error
error [1620]: Unknown column 'suffix' in 'field list'
What I have to do that this fields is saved in database

As mentioned already as a comment, TYPO3 complains that the column is missing in the Database.
Your extension should provide an ext_tables.sql which extends the Database Schema. See https://docs.typo3.org/m/typo3/reference-coreapi/10.4/en-us/ExtensionArchitecture/FilesAndLocations/Index.html#ext-tables-sql for further information.
The file always contains CREATE TABLE statements, which will be converted by TYPO3 do update the schema.
Updating the schema can be done through the install tool of TYPO3, or tools like TYPO3 console via command line.

Related

How do I add publish dates to uploaded files in Typo3?

I am currently maintaining a client's existing Typo3 6.1 site and one of the things they would like to add to their site is the possibility of applying publish and expiration dates on uploaded files, in the same way such dates can be applied on Typo3 pages.
I did some research on the matter to see if something like this had already been done before. I tried looking for existing Typo3 extensions on Google and on the official Typo3 extensions repository that would add this functionality, but nothing like this seems to exist. I also tried to find ways of doing it myself, still without any results.
What would be the best approach to add this functionality to a Typo3 6.1 website?
EDIT
After some investigating, I noticed another extension was already hooked up with the TCEForm of the file editing page: http://i.stack.imgur.com/up7mO.png
In this screenshot, you can see I managed to add the start and end datetime fields as the first two fields in the form ("Date de publication" and "Date d'expiration"). I currently have the following configuration in my ext_table.php:
<?php
if (!defined('TYPO3_MODE')) {
die('Access denied.');
}
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerPlugin(
$_EXTKEY, 'Documents', 'Documents'
);
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addStaticFile($_EXTKEY, 'Configuration/TypoScript', 'Documents');
\TYPO3\CMS\Core\Utility\GeneralUtility::loadTCA('sys_file');
$newFileColumns = array(
'date_publication' => array(
'exclude' => 0,
'label' => 'LLL:EXT:the_extension_key/Resources/Private/Language/locallang_db.xlf:document.date_publication',
'config' => array(
'type' => 'input',
'size' => 13,
'max' => 20,
'eval' => 'datetime',
'checkbox' => 0,
'default' => 0,
'range' => array(
'lower' => mktime(0, 0, 0, date('m'), date('d'), date('Y'))
),
),
),
'date_expiration' => array(
'exclude' => 0,
'label' => 'LLL:EXT:the_extension_key/Resources/Private/Language/locallang_db.xlf:document.date_expiration',
'config' => array(
'type' => 'input',
'size' => 13,
'max' => 20,
'eval' => 'datetime',
'checkbox' => 0,
'default' => 0,
'range' => array(
'lower' => mktime(0, 0, 0, date('m'), date('d'), date('Y'))
),
),
),
'desactive' => array(
'exclude' => 1,
'config' => array(
'type' => 'passthrough'
)
),
'isbn' => array(
'label' => 'LLL:EXT:the_extension_key/Resources/Private/Language/locallang_db.xlf:document.isbn',
'config' => array(
'type' => 'input',
'size' => 50,
'eval' => 'trim'
),
),
'auteurs_internes' => array(
'label' => 'LLL:EXT:the_extension_key/Resources/Private/Language/locallang_db.xlf:document.auteurs_internes',
'config' => array(
'type' => 'select',
'foreign_table' => 'fe_users',
'MM' => 'tx_documents_document_auteur_mm',
'size' => 5,
'maxitems' => 10,
'minitems' => 0,
'wizards' => array(
'suggest' => array(
'type' => 'suggest',
'default' => array(
'searchWholePhrase' => 1
),
),
),
),
),
'auteurs_externes' => array(
'label' => 'LLL:EXT:the_extension_key/Resources/Private/Language/locallang_db.xlf:document.auteurs_externes',
'config' => array(
'type' => 'input',
'size' => 50,
'eval' => 'trim'
),
),
'responsable' => array(
'label' => 'LLL:EXT:the_extension_key/Resources/Private/Language/locallang_db.xlf:document.responsable',
'config' => array(
'type' => 'group',
'internal_type' => 'db',
'allowed' => 'tx_common_domain_model_unitelogique',
'size' => 1,
'maxitems' => 1,
'minitems' => 0,
'wizards' => array(
'suggest' => array(
'type' => 'suggest',
'default' => array(
'searchWholePhrase' => 1
),
),
),
),
),
'type_document' => array(
'label' => 'LLL:EXT:the_extension_key/Resources/Private/Language/locallang_db.xlf:document.type_document',
'config' => array(
'type' => 'select',
'foreign_table' => 'sys_category',
'foreign_table_where' => ' AND sys_category.tx_common_type = "type_document" ORDER BY sys_category.title ASC',
'maxitems' => 1,
'minitems' => 1,
'renderMode' => 'tree',
'treeConfig' => array(
'parentField' => 'parent',
),
),
),
'public_cible' => array(
'label' => 'LLL:EXT:the_extension_key/Resources/Private/Language/locallang_db.xlf:document.public_cible',
'config' => array(
'type' => 'select',
'foreign_table' => 'sys_category',
'MM' => 'tx_documents_document_publiccible_mm',
'foreign_table_where' => ' AND sys_category.tx_common_type = "public_cible_document" ORDER BY sys_category.title ASC',
'maxitems' => 100,
'minitems' => 0,
'renderMode' => 'tree',
'treeConfig' => array(
'parentField' => 'parent',
),
),
),
'important' => array(
'exclude' => 1,
'label' => 'LLL:EXT:the_extension_key/Resources/Private/Language/locallang_db.xlf:document.important',
'config' => array(
'type' => 'check',
),
),
'nouveau' => array(
'label' => 'LLL:EXT:the_extension_key/Resources/Private/Language/locallang_db.xlf:document.nouveau',
'config' => array(
'type' => 'input',
'eval' => 'date'
),
),
'misajour' => array(
'label' => 'LLL:EXT:the_extension_key/Resources/Private/Language/locallang_db.xlf:document.misajour',
'config' => array(
'type' => 'check',
),
),
'no_magistra' => array(
'label' => 'LLL:EXT:the_extension_key/Resources/Private/Language/locallang_db.xlf:document.no_magistra',
'config' => array(
'type' => 'input',
'size' => 50,
'eval' => 'trim'
),
),
'centre_documentation' => array(
'label' => 'LLL:EXT:the_extension_key/Resources/Private/Language/locallang_db.xlf:document.centre_documentation',
'config' => array(
'type' => 'check',
),
),
'image' => array(
'exclude' => 0,
'label' => 'LLL:EXT:the_extension_key/Resources/Private/Language/locallang_db.xlf:document.image',
'config' => array(
'type' => 'group',
'internal_type' => 'file',
'allowed' => $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'],
'minitems' => 0,
'maxitems' => 1,
'size' => 1,
'show_thumbs' => 1,
'uploadfolder' => 'uploads/pics',
'disable_controls' => 'list',
),
),
);
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns('sys_file', $newFileColumns);
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addToAllTCAtypes('sys_file', '--div--;LLL:EXT:the_extension_key/Resources/Private/Language/locallang_db.xlf:document.tab, date_publication, date_expiration, isbn, auteurs_internes, auteurs_externes, responsable, type_document, public_cible, important, nouveau, no_magistra, centre_documentation, image');
// Edit of existing fields
\TYPO3\CMS\Core\Utility\GeneralUtility::loadTCA('sys_file');
$TCA['sys_file']['columns']['title']['config']['placeholder'] = '';
$TCA['sys_file']['columns']['title']['config']['eval'] = 'required';
$TCA['sys_file']['columns']['title']['config']['size'] = '50';
$TCA['sys_file']['columns']['description']['config']['wizards'] = array(
'RTE' => array(
'icon' => 'wizard_rte2.gif',
'notNewRecords' => 1,
'RTEonly' => 1,
'script' => 'wizard_rte.php',
'title' => 'LLL:EXT:cms/locallang_ttc.xlf:bodytext.W.RTE',
'type' => 'script'
)
);
$TCA['sys_file']['columns']['description']['defaultExtras'] = 'richtext:rte_transform[flag=rte_enabled|mode=ts]';
// Add category types
\TYPO3\CMS\Core\Utility\GeneralUtility::loadTCA('sys_category');
$TCA['sys_category']['columns']['tx_common_type']['config']['items'][] = array('LLL:EXT:the_extension_key/Resources/Private/Language/locallang_db.xlf:category.type.type_document', 'type_document');
$TCA['sys_category']['columns']['tx_common_type']['config']['items'][] = array('LLL:EXT:the_extension_key/Resources/Private/Language/locallang_db.xlf:category.type.public_cible_document', 'public_cible_document');
?>
However, defining the columns as start and end access dates with
$GLOBALS['TCA']['sys_file']['ctrl']['enablecolumns']['starttime'] = 'tx_myext_starttime';
$GLOBALS['TCA']['sys_file']['ctrl']['enablecolumns']['endtime'] = 'tx_myext_starttime';
as suggested in the answers makes the file list show an error instead of loading a list of files. Instead, I tried using the $TCA variable to define them. The error page shown by Typo3 is not shown anymore using this, but the editing page still can't be rendered successfully.
The $TCA configuration I added:
$TCA['sys_file'] = array(
'ctrl' => array(
'label' => 'title',
'label_alt' => 'name,description,alternative,identifier,uid',
'tstamp' => 'tstamp',
'crdate' => 'crdate',
'cruser_id' => 'cruser_id',
'versioningWS' => 2,
'versioning_followPages' => TRUE,
'origUid' => 't3_origuid',
'enablecolumns' => array(
'disabled' => 'desactive',
'starttime' => 'date_publication',
'endtime' => 'date_expiration',
)
)
);
The following image shows what happens with this $TCA configuration added while trying to edit a file: http://i.stack.imgur.com/8VaCD.png
The TCEForm is simply not rendered and I don't know why. I'm not sure if my configuration in ext_tables.php contains a bad configuration (especially in the $TCA config I added) or if the problem comes from another file in the extension.
What can be causing this error and how can I fix it?
FAL (File Abstraction Layer) does not have a starttime and endtime field.
But since the sys_file related tables (like sys_file_reference) can be extended by your own extension and TCA offers you the starttime/endtime functionality by default my biggest guess will be that this can be accomplished with some modifications in the TCA.
Here a quick kickstart of how you can try to extend sys_file with the starttime and endtime fields.
ext_emconf.php
$EM_CONF[$_EXTKEY] = array (
// more stuff here in between
'constraints' => array (
'depends' => array (
'filelist' => '6.1.0-6.1.99',
),
),
);
ext_tables.sql
#
# Table structure for table 'sys_file'
#
CREATE TABLE sys_file (
tx_myext_starttime int(11) unsigned DEFAULT '0' NOT NULL,
tx_myext_endtime int(11) unsigned DEFAULT '0' NOT NULL,
)
ext_tables.php
<?php
if (!defined ('TYPO3_MODE')) {
die ('Access denied.');
}
$tempColumns = array();
$tempColumns['tx_myext_starttime'] = array(
'exclude' => 1,
'l10n_mode' => 'mergeIfNotBlank',
'label' => 'LLL:EXT:lang/locallang_general.xlf:LGL.starttime',
'config' => array(
'type' => 'input',
'size' => 13,
'max' => 20,
'eval' => 'datetime',
'checkbox' => 0,
'default' => 0,
'range' => array(
'lower' => mktime(0, 0, 0, date('m'), date('d'), date('Y'))
),
),
);
$tempColumns['tx_myext_endtime'] = array(
'exclude' => 1,
'l10n_mode' => 'mergeIfNotBlank',
'label' => 'LLL:EXT:lang/locallang_general.xlf:LGL.endtime',
'config' => array(
'type' => 'input',
'size' => 13,
'max' => 20,
'eval' => 'datetime',
'checkbox' => 0,
'default' => 0,
'range' => array(
'lower' => mktime(0, 0, 0, date('m'), date('d'), date('Y'))
),
),
);
$GLOBALS['TCA']['sys_file']['ctrl']['enablecolumns']['starttime'] = 'tx_myext_starttime';
$GLOBALS['TCA']['sys_file']['ctrl']['enablecolumns']['endtime'] = 'tx_myext_starttime';
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns('sys_file', $tempColumns, 1);
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addToAllTCAtypes('sys_file', '--div--;LLL:EXT:cms/locallang_ttc.xlf:tabs.access, tx_myext_starttime, tx_myext_endtime');
unset($tempColumns);
I don't know if the FAL persistence layer and repositories does support (or better: eat) this configuration and I can't estimate in which kind of problems you're gonna run. But I guess it's a try worth.
Good luck!

.install file not creating table in drupal

Hi i am very new in drupal. i just create a module that create a form with some inputs. I wrote .install file for the same but it is not creating table. While i am installing this module it is neither showing error nor install table.
function mycontact_schema() {
$schema['mycontact'] = array(
'description' => t('This table for mycontact.'),
'fields' => array(
'mycontctid' => array(
'description' => t('The primary identifier for a mycontact.'),
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE),
'vid' => array(
'description' => t('The current {mycontact_revisions}.vid version identifier.'),
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0),
'name' => array(
'description' => t('The {mycontact_name} of this mycontact.'),
'type' => 'varchar',
'length' => 32,
'not null' => TRUE,
'default' => ''),
'email' => array(
'description' => t('The name of this contact, always treated a non-markup plain text.'),
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => ''),
),
'comments' => array(
'description' => t('The comments of this contact, always treated a non-markup plain text.'),
'type' => 'text',
'not null' => TRUE,
'default' => ''),
'primary key' => array('mycontctid'),
);
return $schema;
}
It is not showing any error and any warning.
There is nothing wrong in the hook_install implementation.
I followed these steps to get it working:
Created a directory called mycontact inside sites/all/modules.
Created a the files mycontact.info, mycontact.module, and mycontact.install.
Inside mycontact.info I added the following lines:
name = my contact
core = 7.x
And in the mycontact.install file, I copied all the code from the question as it is.
Left the mycontact.module file empty. Note: Drupal needs this empty file.
Enabled the module. And it worked!
What you could do now is, disable the module -> uninstall it -> follow the above steps to install the module; and you should have your database table created for you.

Drupal 7 Feeds Module not working

I have installed the Drupal 7 feeds module and created an Importer.
I can display the Stand-alone form, add a file but the upload / parse page just displays the message "Importing..." It doesn't do much else and does not import into a selected content type. No errors are displayed.
Any ideas?
// Importer below /////////////////////////////////////////////////////////
$feeds_importer = new stdClass();
$feeds_importer->disabled = FALSE;
$feeds_importer->api_version = 1;
$feeds_importer->id = 'shop_ids';
$feeds_importer->config = array(
'name' => 'Shop IDs',
'description' => 'Import a CSV file which feeds into Shop ID node type',
'fetcher' => array(
'plugin_key' => 'FeedsFileFetcher',
'config' => array(
'allowed_extensions' => 'txt csv tsv xml opml',
'direct' => 0,
'directory' => 'public://feeds',
'allowed_schemes' => array(
'public' => 'public',
'private' => 'private',
),
),
),
'parser' => array(
'plugin_key' => 'FeedsCSVParser',
'config' => array(
'delimiter' => ',',
'no_headers' => 1,
),
),
'processor' => array(
'plugin_key' => 'FeedsNodeProcessor',
'config' => array(
'expire' => '-1',
'author' => 0,
'authorize' => 1,
'mappings' => array(
0 => array(
'source' => '\'0\'',
'target' => 'title',
'unique' => 1,
),
1 => array(
'source' => '\'1\'',
'target' => 'body',
'unique' => FALSE,
),
),
'update_existing' => '1',
'input_format' => 'plain_text',
'skip_hash_check' => 0,
'bundle' => 'shop_ids',
),
),
'content_type' => '',
'update' => 0,
'import_period' => '-1',
'expire_period' => 3600,
'import_on_create' => 1,
'process_in_background' => 0,
);
Looks like there was an error with batch.js
JQuery causing function error
fix was to add ; to beginning of code.
;(function ($) {
and add the (jQuery); to the end of the file...
})(jQuery);

yii booster checkbox doesn't show boxes to check

I add the checkbox functionality from the yii-booster. But the widget renders the model view without the needed boxes. What's wrong?
Widjet code in view
<?php
$this->widget('bootstrap.widgets.TbExtendedGridView',array(
'id'=>'docs-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'type'=>'bordered condensed',
'template' => "{items}",
'bulkActions' => array(
'actionButtons' => array(
array(
'buttonType' => 'button',
'type' => 'primary',
'size' => 'small',
'label' => 'Choose',
'click' => 'js:function(values){console.log(values);}'
)
),
// if grid doesn't have a checkbox column type, it will attach
// one and this configuration will be part of it
'checkBoxColumnConfig' => array(
'name' => 'id'
),
),
));
If you are using bulkActions, you have to use 'columns' to list out the columns you want to display instead of using 'template'.
'columns' => array(
'id',
'title',
...
),
the problem has been in the wrong hierarchy from the example:
The 'checkBoxColumnConfig' attribute must be outside of the 'actionButtons' attribute:
'bulkActions' => array(
'actionButtons' => array(
/*array(
'buttonType' => 'button',
'type' => 'primary',
'size' => 'small',
'label' => 'Выбрать отмеченные',
'click' => 'js:function(values){console.log(values);}'
)
),*/
// if grid doesn't have a checkbox column type, it will attach
// one and this configuration will be part of it
),
'checkBoxColumnConfig' => array(
'name' => 'id'
),
...
));
but now the widget doesn't work when i uncomment the array part inside 'actionButtons':
array(
'buttonType' => 'button',
'type' => 'primary',
'size' => 'small',
'label' => 'Выбрать отмеченные',
'click' => 'js:function(values){console.log(values);}'
)
what might be a cause?

saveAll: save new data for related model or use existing record

I'm trying to update data about many shipments with one form.
Shipment model belongsTo Shippingaddress model and Shippingaddress hasMany Shipment.
In interface user can use his previously saved Shippingaddress from select field or fill small form and add new one.
Currently example structure of data which are posted to controller looks like this:
array(
(int) 0 => array(
'Shipment' => array(
'id' => '223',
'shippingaddress_id' => '8',
)
),
(int) 1 => array(
'Shipment' => array(
'id' => '224',
'shippingaddress_id' => '',
),
'Shippingaddress' => array(
'recipient' => 'some name',
'address' => 'some addres data',
'zip' => '00-555',
'city' => 'some city',
)
),
(int) 2 => array(
'Shipment' => array(
'id' => '225',
'shippingaddress_id' => '12',
)
)
)
It would be nice to save Shiippingaddress data and update all Shipments in one transaction with
$this->Shipment->saveAll($data).
Is it possible?
I was trying many combination of posted array structure but without success.
Your $data structure should looks like this:
$data = array(
'Shippingadress' => array(
'0' => array(
'id' => '8',
'Shipment' => array(
'id' => '223'
)
),
'1' => array(
'recipient' => 'some name',
'address' => 'some addres data',
'zip' => '00-555',
'city' => 'some city'
'Shipment' => array(
'id' => '224'
)
),
'2' => array(
'id' => '12',
'Shipment' => array(
'id' => '255'
)
),
)
);
For save use saveMany:
$this->Shippingadress->saveMany($data, array('deep' => true) );
You don't need to specify shippingadress_id to empty string because Cake already takes care of it and put all relevant foreign keys based on the relationship of your models.

Resources