TYPO3 list module: custom records not showing - typo3

I am using TYPO3 7.6.11.
I wrote an provider extension to add some ts-code, templates, and viewhelpers.
After that, I wanted to add a custom data record (to use in the Backend).
I added the table in the ext_tables.sql.
I have a TCA-config under /[extension]/Configuration/TCA/tablename.php
I added
TYPO3\CMS\Core\Utility\ExtensionManagementUtility::allowTableOnStandardPages('tablename');
TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addToInsertRecords('tablename');
to my ext_tables.php
Did I miss something?
I get a new record type under "System Records" in the List Module. I can add such an record, and the TCA-config seems to work fine for the record form.
But after saving, I have no record in the list view. The DB is looking fine. The record is saved correctly in my new table. What am I doing wrong?
Thanks
Edit:
crtl:
'ctrl' => array (
'title' => 'LLL:EXT:svkcore/Resources/Private/Language/locallang.xlf:records.title',
'label' => 'title',
'label_alt' => '',
'label_alt_force' => TRUE,
'default_sortby' => 'ORDER BY datetime DESC',
'prependAtCopy' => 'LLL:EXT:lang/locallang_general.php:LGL.prependAtCopy',
'versioningWS' => TRUE,
'versioning_followPages' => TRUE,
'origUid' => 't3_origuid',
'shadowColumnsForNewPlaceholders' => 'sys_language_uid,l18n_parent,starttime,endtime,fe_group',
'dividers2tabs' => TRUE,
'useColumnsForDefaultValues' => 'type',
'transOrigPointerField' => 'l18n_parent',
'transOrigDiffSourceField' => 'l18n_diffsource',
'languageField' => 'sys_language_uid',
'crdate' => 'crdate',
'tstamp' => 'tstamp',
'delete' => 'deleted',
'type' => 'type',
'cruser_id' => 'cruser_id',
'editlock' => 'editlock',
'enablecolumns' => array (
'disabled' => 'hidden',
'starttime' => 'starttime',
'endtime' => 'endtime',
'fe_group' => 'fe_group',
),
'typeicon_column' => 'type',
'typeicons' => array (
'1' => 'EXT:svkcore/res/gfx/svkcore_inturl.gif',
'2' => 'EXT:svkcore/res/gfx/svkcore_exturl.gif',
),
'thumbnail' => 'image',
'iconfile' => 'EXT:svkcore/res/gfx/ext_icon.gif',
'searchFields' => 'uid,title,short,bodytext'),
'interface' => Array (
'showRecordFieldList' => 'title,hidden,datetime_start,starttime,archivedate,category,short,image,record_files'
),

Since Typo3 7 it is possible to mask the list-view. This is configured via PageTSConfig, have a look at your info-Module (select the correct page in the page tree) and check the TSConfig there.
The configuration can be found in the following path:
mod.web_list.allowedNewTables

Check in ext_tables.php if you have everything needed for your new table : Typoscript inclusion, language file, exemple :
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addStaticFile($_EXTKEY, 'Configuration/TypoScript', 'My TS configuration');
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addLLrefForTCAdescr('tx_myext_domain_model_mytable', 'EXT:my_ext/Resources/Private/Language/locallang_csh_tx_myext_domain_model_mytable.xlf');
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::allowTableOnStandardPages('tx_myext_domain_model_mytable');
Are you sure the new records are stored in the current page : have a look at the TS "persistence.storagePid".
You can check in the database wich pid is used for your new records.
Regards,
Florian

Related

In SuiteCRM how to add custom field in sub panel from relationship table?

I have a module and a sub panel with another module in relationship with it.
As shown in below image-
In the above image its a sub-panel of a module in the relationship,
I have added a column in the relationship table in database.
My requirement is to add that field in this sub-panel list view like shown in image in red rectangle, which is ideally not possible from the studio as per my knowledge.
If anyone has idea to do stuff like this please share.
There may come a time in the development of a custom SuiteCRM module when it would be handy to store additional data in the relationship table between two modules. This is not possible in studio or module builder and is not that straight forward even for an experienced coder unless you have a deep understanding of SuiteCRM underlying architecture.
Step 1 The first thing you need to do is define your new fields in the metadata for the relationship. I will be adding the field in the relationship between a custom module FP_events and Contacts. The relationship fp_events_contacts is a many to many and the subpanel will be displaying the field in the contacts subpanel on the FP_events module.
This file can be found at custom/metadata/fp_events_contactsMetaData.php
In the code below notice that I added a field called date_cancelled with type date to the fields array.
$dictionary["fp_events_contacts"] = array (
'true_relationship_type' => 'many-to-many',
'relationships' =>
array (
'fp_events_contacts' =>
array (
'lhs_module' => 'FP_events',
'lhs_table' => 'fp_events',
'lhs_key' => 'id',
'rhs_module' => 'Contacts',
'rhs_table' => 'contacts',
'rhs_key' => 'id',
'relationship_type' => 'many-to-many',
'join_table' => 'fp_events_contacts_c',
'join_key_lhs' => 'fp_events_contactsfp_events_ida',
'join_key_rhs' => 'fp_events_contactscontacts_idb',
),
),
'table' => 'fp_events_contacts_c',
'fields' =>
array (
0 =>
array (
'name' => 'id',
'type' => 'varchar',
'len' => 36,
),
1 =>
array (
'name' => 'date_modified',
'type' => 'datetime',
),
2 =>
array (
'name' => 'deleted',
'type' => 'bool',
'len' => '1',
'default' => '0',
'required' => true,
),
3 =>
array (
'name' => 'fp_events_contactsfp_events_ida',
'type' => 'varchar',
'len' => 36,
),
4 =>
array (
'name' => 'fp_events_contactscontacts_idb',
'type' => 'varchar',
'len' => 36,
),
5 =>
array (
'name' => 'invite_status',
'type' => 'varchar',
'len'=>'25',
'default'=>'Not Invited',
),
6 =>
array (
'name' => 'accept_status',
'type' => 'varchar',
'len'=>'25',
'default'=>'No Response',
),
7 =>
array (
'name' => 'email_responded',
'type' => 'int',
'len' => '2',
'default' => '0',
),
8 =>
array (
'name' => 'date_cancelled',
'type' => 'date',
),
),
'indices' =>
array (
0 =>
array (
'name' => 'fp_events_contactsspk',
'type' => 'primary',
'fields' =>
array (
0 => 'id',
),
),
1 =>
array (
'name' => 'fp_events_contacts_alt',
'type' => 'alternate_key',
'fields' =>
array (
0 => 'fp_events_contactsfp_events_ida',
1 => 'fp_events_contactscontacts_idb',
),
),
),
);
Once you have added your desired fields to the fields arrays do a quick repair and rebuild from the admin panel of SuiteCRM and then execute the suggested SQL queries this will add the fields to the database table for the relationship. (I double-checked that the fields were added by going into phpmyadmin and looking at the fp_events_contacts_c table.)
Step 2 Your fields are now defined and in the actual database table but your only halfway their if you want your fields to actually be displayed in the subpanel. The next thing you want to do is define your new fields in the vardefs for the relationship. This is done by adding a file in the custom/Extensions folder like so: custom/Extension/modules/Contacts/Ext/Vardefs/CAN_BE_ANY_NAME.php
In this file add the following three definitions for each field your adding. Pay careful attention that all the field names and ids match up between definitions as minor typos here will prevent the fields from showing in the subpanel and can be major pain to spot:
$dictionary['Contact']['fields']['e_date_cancelled'] =
array (
'name' => 'e_date_cancelled',
'rname' => 'id',
'relationship_fields'=>array('id' => 'cancelled_id', 'date_cancelled' => 'event_cancelled'),
'vname' => 'LBL_CONT_ACCEPT_CANCELLED',
'type' => 'relate',
'link' => 'fp_events_contacts',
'link_type' => 'relationship_info',
'join_link_name' => 'fp_events_contacts',
'source' => 'non-db',
'importable' => 'false',
'duplicate_merge'=> 'disabled',
'studio' => false,
);
$dictionary['Contact']['fields']['event_cancelled'] =
array(
'massupdate' => false,
'name' => 'event_cancelled',
'type' => 'date',
'studio' => 'false',
'source' => 'non-db',
'vname' => 'LBL_LIST_ACCEPT_CANCELLED',
'importable' => 'false',
);
$dictionary['Contact']['fields']['cancelled_id'] =
array(
'name' => 'cancelled_id',
'type' => 'varchar',
'source' => 'non-db',
'vname' => 'LBL_LIST_ACCEPT_CANCELLED',
'studio' => array('listview' => false),
);
Step 3 The final thing you need to do is define the fields in the actual layout defs of the subpanel. In this case, that file is located: custom/modules/Contacts/metadata/subpanels/FP_events_subpanel_fp_events_contacts.php
In the code below notice that I add my field event_cancelled (as defined in the step 2 vardefs) to list_fields array and further down in the array I also add e_date_cancelled and cancelled_id and mark their usage as query_only.
$subpanel_layout['list_fields'] = array (
'name' =>
array (
'name' => 'name',
'vname' => 'LBL_LIST_NAME',
'sort_by' => 'last_name',
'sort_order' => 'asc',
'widget_class' => 'SubPanelDetailViewLink',
'module' => 'Contacts',
'width' => '23%',
'default' => true,
),
'account_name' =>
array (
'name' => 'account_name',
'module' => 'Accounts',
'target_record_key' => 'account_id',
'target_module' => 'Accounts',
'widget_class' => 'SubPanelDetailViewLink',
'vname' => 'LBL_LIST_ACCOUNT_NAME',
'width' => '22%',
'sortable' => false,
'default' => true,
),
'phone_work' =>
array (
'name' => 'phone_work',
'vname' => 'LBL_LIST_PHONE',
'width' => '15%',
'default' => true,
),
'email1' =>
array (
'name' => 'email1',
'vname' => 'LBL_LIST_EMAIL',
'widget_class' => 'SubPanelEmailLink',
'width' => '20%',
'sortable' => false,
'default' => true,
),
'event_status_name' =>
array (
'vname' => 'LBL_STATUS',
'width' => '10%',
'sortable' => false,
'default' => true,
),
'event_accept_status' =>
array (
'width' => '10%',
'sortable' => false,
'default' => true,
'vname' => 'LBL_ACCEPT_STATUS',
),
'event_cancelled' =>
array (
'width' => '10%',
'sortable' => false,
'default' => true,
'vname' => 'LBL_ACCEPT_CANCELLED',
),
'edit_button' =>
array (
'vname' => 'LBL_EDIT_BUTTON',
'widget_class' => 'SubPanelEditButton',
'module' => 'Contacts',
'width' => '5%',
'default' => true,
),
'remove_button' =>
array (
'vname' => 'LBL_REMOVE',
'widget_class' => 'SubPanelRemoveButton',
'module' => 'Contacts',
'width' => '5%',
'default' => true,
),
'e_accept_status_fields' =>
array (
'usage' => 'query_only',
),
'event_status_id' =>
array (
'usage' => 'query_only',
),
'e_invite_status_fields' =>
array (
'usage' => 'query_only',
),
'event_invite_id' =>
array (
'usage' => 'query_only',
),
'e_date_cancelled' =>
array (
'usage' => 'query_only',
),
'cancelled_id' =>
array (
'usage' => 'query_only',
),
'first_name' =>
array (
'name' => 'first_name',
'usage' => 'query_only',
),
'last_name' =>
array (
'name' => 'last_name',
'usage' => 'query_only',
),
'salutation' =>
array (
'name' => 'salutation',
'usage' => 'query_only',
),
'account_id' =>
array (
'usage' => 'query_only',
),
);
Also, remember to add the label in this case LBL_ACCEPT_CANCELLED to the custom language strings.
I added it to: custom/Extension/application/Ext/Language/en_us.Advanced OpenEvents.php
$app_strings['LBL_ACCEPT_CANCELLED'] = 'Date Cancelled';
But it may work if added to the mod strings.
Now do another quick repair and rebuild from the admin panel and your custom relationship fields should now be showing up on the subpanel. You will now be able to add data into these fields in your module controller either via queries or through SuiteCRM bean framework.
Note you might have to manually go into the database and add some dummy data into those fields to confirm they are showing (Assuming you have not yet added any data to your new fields).
Cheers!

TYPO3 extbase & IRRE: add existing records with 'foreign_selector'

I "kickstarted" an extension with the extbase extension builder that contains some 1:1 and 1:n relations. It automatically set the field types to 'inline' and displayed a nice IRRE UI in the backend.
But by default, there is no way to select an existing record, just create new ones.
I found various explanations on how to achieve this with 'foreign_selector', but all of them very sketchy. The feature itself should be working, see https://forge.typo3.org/issues/43239
Can someone walk me through this or point to a working example in the TER? I could create a step-by-step tutorial from the example, once I get it to work.
PS The field's TCA config as generated by extension_builder:
'myfield' => array(
'exclude' => 1,
'label' => 'LLL:EXT:myextension/Resources/Private/Language/locallang_db.xlf:tx_myextension_domain_model_myitem.myfield',
'config' => array(
'type' => 'inline',
'foreign_table' => 'tx_myextension_domain_model_myfield',
'foreign_field' => 'myitem',
'maxitems' => 9999,
'appearance' => array(
'collapseAll' => 0,
'levelLinksPosition' => 'top',
'showSynchronizationLink' => 1,
'showPossibleLocalizationRecords' => 1,
'showAllLocalizationLink' => 1
),
),
),
The main problem is that IRRE relations of type 1:n work like this: A child record holds the uid of its parent. So your table tx_myext_domain_model_city holds the UID of your (imaginary) tx_myext_domain_model_address.
Therefore with the default configuration you will not be able to select a city multiple times as it can only have exactly one parent.
So you will need to use a relation table for this field. This table needs to contain a uid field for both the address (uid_address) and the city (uid_city):
CREATE TABLE tx_irreforeignselectordemo_address_city_mm (
uid int(11) NOT NULL auto_increment,
pid int(11) DEFAULT '0' NOT NULL,
uid_address int(11) unsigned DEFAULT '0' NOT NULL,
uid_city int(11) unsigned DEFAULT '0' NOT NULL,
sorting int(11) unsigned DEFAULT '0' NOT NULL,
PRIMARY KEY (uid),
KEY parent (pid)
);
And it needs to have a TCA configuration for these fields (while the table itself can be hidden):
return array(
'ctrl' => array(
'title' => 'Relation table',
'hideTable' => TRUE,
'sortby' => 'sorting',
),
'columns' => array(
'uid_address' => Array(
'label' => 'Address',
'config' => Array(
'type' => 'select',
'foreign_table' => 'tx_irreforeignselectordemo_domain_model_address',
'size' => 1,
'minitems' => 0,
'maxitems' => 1,
),
),
'uid_city' => Array(
'label' => 'City',
'config' => Array(
'type' => 'select',
'foreign_table' => 'tx_irreforeignselectordemo_domain_model_city',
'foreign_table_where' => ' AND sys_language_uid IN (0,-1)',
'size' => 1,
'minitems' => 0,
'maxitems' => 1,
),
),
),
'types' => array(
'0' => array('showitem' => 'uid_address,uid_city')
),
'palettes' => array()
);
You can then configure the TCA of your address to make it an IRRE field:
'type' => 'inline',
'foreign_table' => 'tx_yourext_address_city_mm',
'foreign_field' => 'uid_address',
'foreign_label' => 'uid_city',
'foreign_selector' => 'uid_city',
'foreign_unique' => 'uid_city',
'foreign_sortby' => 'sorting',
Note that foreign_unique tells TYPO3 that a city can only selected once.
And you need to define the relation from the other side (from your city TCA):
'addresses' => array(
'exclude' => 1,
'label' => 'Addresses',
'config' => array(
'type' => 'inline',
'foreign_table' => 'tx_irreforeignselectordemo_address_city_mm',
'foreign_field' => 'uid_city',
'foreign_label' => 'uid_address',
),
),
Once your configuration is complete, you will be able to use this in the Backend.
Since this is a non-standard MM relation, Extbase will not be able to deal with it by default. But we can compare this to the sys_file_reference table that was introduced in TYPO3 6. So we build an Extbase model for the CityRelation with the properties "address" and "city" and map this model to our mm table:
config.tx_extbase.persistence.classes {
Visol\Irreforeignselectordemo\Domain\Model\CityRelation {
mapping {
tableName = tx_irreforeignselectordemo_address_city_mm
columns {
uid_address.mapOnProperty = address
uid_city.mapOnProperty = city
}
}
}
}
Now in our address model, we define the city (or cities - of you allow more than one choice) as ObjectStorage of type CityRelation:
/**
* Cities
*
* #var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Visol\Irreforeignselectordemo\Domain\Model\CityRelation>
*/
protected $cities = NULL;
We now have a property "cities" that contains the references to all selected cities. You can iterate through them and use them:
<f:for each="{address.cities}" as="cityRelation">
<li>{cityRelation.city.name}</li>
</f:for>
Since I couldn't find an all-in-one demo for this and was interested in the topic, I created a demo extension that does what I just described - based on the Core and two extensions that deal with the topic: https://github.com/lorenzulrich/irreforeignselectordemo
The solution is an m:n approach anyway (because 1:n wouldn't work for the reasons stated above) so I decided to use "cities" instead of "city". While this might not make sense for selecting a city (as suggested by your post), it might make sense for other opportunities. Feel free to replace "cities" by "city" and set maxItems in the inline configuration to one - then you have kind of an 1:n.

Extension builder overwrite fe_user TCA

If I try to extend fe_user table by creating a new Model Object on extension builder in Typo3 6.1.7, it overwrites TCA by writing those lines in ext_tables.php of my extension:
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addLLrefForTCAdescr('fe_users', 'EXT:voiwizard/Resources/Private/Language/locallang_csh_fe_users.xlf');
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::allowTableOnStandardPages('fe_users');
$TCA['fe_users'] = array(
'ctrl' => array(
'title' => 'LLL:EXT:voiwizard/Resources/Private/Language/locallang_db.xlf:fe_users',
'label' => 'prova',
'tstamp' => 'tstamp',
'crdate' => 'crdate',
'cruser_id' => 'cruser_id',
'dividers2tabs' => TRUE,
'versioningWS' => 2,
'versioning_followPages' => TRUE,
'origUid' => 't3_origuid',
'languageField' => 'sys_language_uid',
'transOrigPointerField' => 'l10n_parent',
'transOrigDiffSourceField' => 'l10n_diffsource',
'delete' => 'deleted',
'enablecolumns' => array(
'disabled' => 'hidden',
'starttime' => 'starttime',
'endtime' => 'endtime',
),
'searchFields' => 'prova,',
'dynamicConfigFile' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath($_EXTKEY) . 'Configuration/TCA/User.php',
'iconfile' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath($_EXTKEY) . 'Resources/Public/Icons/fe_users.gif'
),
);
This code overwrites the original fe_users's TCA configuration and the back-end [website user][1] table becomes inaccessible.
Is there any way to prevent this or do I have to delete those lines every time I want to save the changes in the extension builder?
I've found an error in my relationship:
To properly extend fe_users table with a Model Object in Extension Builder, I had to "extend existing model class" \TYPO3\CMS\Extbase\Domain\Model\FrontendUser instead of "map to existing table" fe_users.
In this way, everything works as expected!

How to replace a build in relationship field by a flexrelate field

For example in Opportunities and Cases there are relationship fields directly pointing to accounts. I have a custom module that integrates into those modules. I could add a separate relate field for the custom module, but what I want is a flexrelate allowing only Accounts and the Custom module. This works fine by setting a special options list in the parent_name. but results in a parent_type and parent_id field in db.
How do I configure the flexrelate so that on selecting accounts as parent_type it save to account_id and on selecting the custom module it saves to it's id field?
The options for the flexrelate:
$app_list_strings['parent_type_display_custom']['CustomMod'] = 'CustomMod';
$app_list_strings['parent_type_display_custom']['Accounts'] = 'Accounts';
$app_list_strings['record_type_display_custom']['CustomMod'] = 'CustomMod';
$app_list_strings['record_type_display_custom']['Accounts'] = 'Accounts';
The additional vardefs for Cases:
$dictionary["Case"]["fields"]["parent_type"] = array (
'name' => 'parent_type',
'type' => 'link',
'vname' => 'LBL_PARENT_TYPE',
'type' => 'parent_type',
'dbType' => 'varchar',
'group' => 'parent_name',
'options' => 'parent_type_display_custom',
'len' => '255',
);
$dictionary["Case"]["fields"]['parent_name'] =
array(
'name' => 'parent_name',
'parent_type' => 'record_type_display',
'type_name' => 'parent_type',
'id_name' => 'parent_id',
'vname' => 'LBL_RELATED_TO',
'type' => 'parent(_custom)',
'source' => 'non-db',
'options' => 'record_type_display_custom',
);
$dictionary["Case"]["fields"]['parent_id'] =
array(
'name' => 'parent_id',
'vname' => 'LBL_PARENT_ID',
'type' => 'id',
'required' => false,
'reportable' => true,
'comment' => 'eighter the Id of an account or a custommodule'
);
Does this SugarCRM developer blog post help?
http://developers.sugarcrm.com/wordpress/2011/05/16/howto-create-a-flex-relate-for-other-modules/

How to validate a checkbox in ZF2

I've read numerous workarounds for Zend Framework's lack of default checkbox validation.
I have recently started using ZF2 and the documentation is a bit lacking out there.
Can someone please demonstrate how I can validate a checkbox to ensure it was ticked, using the Zend Form and Validation mechanism? I'm using the array configuration for my Forms (using the default set-up found in the example app on the ZF website).
Try this
Form element :
$this->add(array(
'type' => 'Zend\Form\Element\Checkbox',
'name' => 'agreeterms',
'options' => array(
'label' => 'I agree to all terms and conditions',
'use_hidden_element' => true,
'checked_value' => 1,
'unchecked_value' => 'no'
),
));
In filters, add digit validation
use Zend\Validator\Digits; // at top
$inputFilter->add($factory->createInput(array(
'name' => 'agreeterms',
'validators' => array(
array(
'name' => 'Digits',
'break_chain_on_failure' => true,
'options' => array(
'messages' => array(
Digits::NOT_DIGITS => 'You must agree to the terms of use.',
),
),
),
),
)));
You could also just drop the hidden form field (which I find a bit weird from a purist HTML point of view) from the options instead of setting its value to 'no' like this:
$this->add(array(
'type' => 'Zend\Form\Element\Checkbox',
'name' => 'agreeterms',
'options' => array(
'label' => 'I agree to all terms and conditions',
'use_hidden_element' => false
),
));
I had the same problem and did something similar to Optimus Crew's suggestion but used the Identical Validator.
If you don't set the checked_value option of the checkbox and leave it as the default it should pass in a '1' when the data is POSTed. You can set it if you require, but make sure you're checking for the same value in the token option of the validator.
$this->filter->add(array(
'name' => 'agreeterms',
'validators' => array(
array(
'name' => 'Identical',
'options' => array(
'token' => '1',
'messages' => array(
Identical::NOT_SAME => 'You must agree to the terms of use.',
),
),
),
),
));
This won't work if you use the option 'use_hidden_element' => false for the checkbox for the form. If you do this, you'll end up displaying the default NotEmpty message Value is required and can't be empty
This isn't directly related to the question, but here's some zf2 checkbox tips if you're looking to store a user's response in the database...
DO use '1' and '0' strings, don't bother trying to get anything else to work. Plus, you can use those values directly as SQL values for a bit/boolean column.
DO use hidden elements. If you don't, no value will get posted with the form and no one wants that.
DO NOT try to filter the value to a boolean. For some reason, when the boolean value comes out to be false, the form doesn't validate despite having 'required' => false;
Example element creation in form:
$this->add([
'name' => 'cellPhoneHasWhatsApp',
'type' => 'Checkbox',
'options' => [
'label' => 'Cell phone has WhatsApp?',
'checked_value' => '1',
'unchecked_value' => '0',
'use_hidden_element' => true,
],
]);
Example input filter spec:
[
'cellPhoneHasWhatsApp' => [
'required' => false,
],
]
And here's an example if you want to hide some other form fields using bootstrap:
$this->add([
'name' => 'automaticTitle',
'type' => 'Checkbox',
'options' => [
'label' => 'Automatically generate title',
'checked_value' => '1',
'unchecked_value' => '0',
'use_hidden_element' => true,
],
'attributes' => [
'data-toggle' => 'collapse',
'data-target' => '#titleGroup',
'aria-expanded' => 'false',
'aria-controls' => 'titleGroup'
],
]);
I'm a ZF2 fan, but at the end of the day, you just have to find out what works with it and what doesn't (especially with Forms). Hope this helps somebody!
Very old question, but figured it might still be used/referenced by people, like me, still using Zend Framework 2. (Using ZF 2.5.3 in my case)
Jeff's answer above helped me out getting the right config here for what I'm using. In my use case I require the Checkbox, though leaving it empty will count as a 'false' value, which is allowed. His answer helped me allow the false values, especially his:
DO NOT try to filter the value to a boolean. For some reason, when the boolean value comes out to be false
The use case is to enable/disable certain entities, such as Countries or Languages so they won't show up in a getEnabled[...]() Repository function.
Form element
$this->add([
'name' => 'enabled',
'required' => true,
'type' => Checkbox::class,
'options' => [
'label' => _('Enabled'),
'label_attributes' => [
'class' => '',
],
'use_hidden_element' => true,
'checked_value' => 1,
'unchecked_value' => 0,
],
'attributes' => [
'id' => '',
'class' => '',
],
]);
Input filter
$this->add([
'name' => 'enabled',
'required' => true,
'validators' => [
[
'name' => InArray::class,
'options' => [
'haystack' => [true, false],
],
],
],
])