I am trying to do something that should be extremely easy in drupal. I just want to simply hide a form field in the drupal admin by default.
Making the field disabled simply doesn't work. I cannot find any documentation for this. It's unbelievable that it's this hard to do something so simple in Drupal.
$form['field_name']['#states'] = [
'visible' => [
':input[name="field_foo[0][target_id]"]' => ['value' => 'blah'],
],
'invisible' => true,
];
The visible part works. If another field has a certain value, then show the form element.
But I simply cannot get it to hide this field on default when you're adding a new node.
Add into form element array $element = ['#access' => FALSE,]:
$form['field_name'] = [
'#access' => FALSE,
]
Easy and does not affect your default value (if default is set):
$form['field_name']['#attributes']['class'][] = 'hidden';
Drupal core will "display: none;" this element from core styles using the 'hidden' css class.
You don't need to set invisible, it will be hidden by default unless the visible condition is met. Also the input looks to be wrong, as it should be whatever the name attribute is set to in the element you are basing the condition on.
The drupal.org documentation with an example.
e.g.
$form['field_name']['#states'] = [
'visible' => [
':input[name="field_conditional_on"]' => ['value' => 'value_conditional_on'],
],
];
Or if you just want to hide it using CSS's display property, you could use something like below,
$form['field_name']['#states'] = [
'#attributes' => array('style' => array('display: none;')),
];
Related
The following scenario: I have a page translated (connected mode, not copy/free mode!) with multiple elements that are translated from the default language.
In my elements without inline fields everything is fine!
In my elements with inline fields I am completely confused about the handling and/or the configuration!
Let’s say I have a content element which contains three inline elements (let’s call them “quotes”). If I translate these quotes 1:1 everything works as expected.
Well ... almost:
I can create new quotes in the translation, but they won’t be displayed.
I can change the sorting, which won’t be taken into account in frontend. The frontend uses the sorting of the default language.
If I create a new quote in the default language, I get the record displayed in the translation and can translate it. So this works as expected.
This leads me to my questions:
How do I make it the quotes/inline elements in the translation independent of the default language?
If this is not possible (which would be fine to me, as it contradicts the idea of the Translate/Connected-Mode somehow) how do I get rid of the buttons for Sort and Create new (of cause only in the translation, not the default language!)? Otherwise, of course, editors try this and wonder why it doesn’t work.
I hope I’ve simply forget an option, but I’ve been thinking about it and looking for a solution for hours now that I probably can’t see the forest for the trees.
This might help if it is a missing option:
TCA
'config' => [
'appearance' => [
'collapseAll' => '1',
'enabledControls' => [
'dragdrop' => '1',
],
'levelLinksPosition' => 'bottom',
'newRecordLinkTitle' => 'New quote',
'useSortable' => '1',
'showSynchronizationLink' => true,
'showAllLocalizationLink' => true,
'showPossibleLocalizationRecords' => true,
],
'foreign_field' => 'parent_id',
'foreign_sortby' => 'sorting',
'foreign_table' => 'my_quotes_table',
'foreign_table_field' => 'parent_table',
'minitems' => '1',
'type' => 'inline',
],
Typoscript
dataProcessing {
10 = TYPO3\CMS\Frontend\DataProcessing\DatabaseQueryProcessor
10 {
if.isTrue.field = my_quotes_field
table = my_quotes_table
pidInList.field = pid
where = parent_id=###uid### AND deleted=0 AND hidden=0
orderBy = sorting
markers.uid.field = uid
as = quotes
}
}
I am using TYPO3 version 11.5.17 with PHP 8.1 and MariaDB 10.5
1.How do I make it the quotes/inline elements in the translation independent of the default language?
You cannot (by any standard TYPO3 means) do this in connected mode. Your page needs to be in free-translation mode to do stuff like that.
If you want do hide the field for all the other languages you can add a "displayCond" property to your tca like this:
'displayCond' => [
'AND' => [
'FIELD:sys_language_uid:=:0'
]
],
This way the field at least stays hidden for the connected languages.
I’m working on an extension where I synchronise some data to another database and I wanted to show this in the backend using a TCA icon overlay. Sadly I could not find out how to do this. I thought about using ‘ctrl’=>‘typeicon_classes’ (using the state field of my table to choose an icon), this works for the default (non synchronised element) but I cannot figure out how to set an overlay. Any idea on how to do this?
My TCA configuration looks like this:
'ctrl' => [
...
'typeicon_column' => 'state',
'typeicon_classes' => [
'new' => 'mimetypes-x-content-login',
'synced' => 'mimetypes-x-content-login-overlay-approved',
]
],
The "synced" part does not work as expected. What I would expect is to either add the overlay at the end of the icon or by adding it with a whitespace but both did not work.
Any help is appreciated.
PS: I really just need this in the TYPO3 backend, the obvious solution for frontend is to use fluid or PHP but I don't think this suits the TYPO3 Backend list.
You need to register your icon files.
Given your icon files are named content_login.svg and content_login_overlay_approved.svg located in directory /Resources/Public/Icons/ you can register these in ext_localconf.php as following:
if (TYPO3_MODE === 'BE') {
$icons = [
'mimetypes-x-content-login' => 'content_login.svg',
'mimetypes-x-content-login-overlay-approved' => 'content_login_overlay_approved.svg',
];
$iconRegistry = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Imaging\IconRegistry::class);
foreach ($icons as $identifier => $path) {
$iconRegistry->registerIcon(
$identifier,
\TYPO3\CMS\Core\Imaging\IconProvider\SvgIconProvider::class,
['source' => 'EXT:YOUREXTENSIONNANME/Resources/Public/Icons/' . $path]
);
}
}
Adapt yourextensionname
I have an entity called "lawyers."
And another entity refers to lawyers.
The problem is that when searching the reference field with the autocompletion system many repeated names appear:
Pablo
Pablo
Pablo
Pablo
I need the reference field to be able to show the surnames of that person so that it turns out to be
Pablo Martínez
Paglo Gutirerrez
Pablo Iglesias
Pablo López
how can I do this?
You will have to create a Entity Reference View to use as handler for doing the autocomplete lookup. Then you can add additional fields (such as last name) to the autocomplete results. This article outlines that process well enough:
https://www.cmsminds.com/blog/entity-reference-entity-reference-view-in-drupal-8/
If the field is a base field and is not available on the Manage form Display page, you will have to modify the entity class Lawyer::baseFieldDefinitions function. Specifically, you need to change the handler and set the form display settings. In your BaseFieldDefinition::create call:
->setSetting('handler', 'default')
Needs to change to this:
->setSetting('handler', 'views')
->setSetting('handler_settings', [
'view' => [
'view_name' => 'name_of_entity_reference_view',
'display_name' => 'name_of_view_display',
],
])
->setDisplayOptions('form', [
'type' => 'entity_reference_autocomplete',
'weight' => 2,
'settings' => [
'match_operator' => 'CONTAINS',
'size' => '60',
'autocomplete_type' => 'tags',
'placeholder' => '',
],
])
Alternatively, if you want to make base fields available in the UI, you can use this line to make the field available in the form display settings ui (and then export your form display settings as config:
->setDisplayConfigurable('form', TRUE);
Help wanted
I'm struggling with the Form API/Webforms in Drupal 8.
I've made a couple of custom composite form elements that we use in a form. Some of the fields have a #states option. Here is a small example:
$elements['invoice_notice_of_default_file'] = [
'#type' => 'file',
'#title' => t('Voeg uw ingebrekestelling toe'),
'#states' => [
'visible' => [
':input[name="invoice_fields[invoice_notice_of_default]"]' => ['value' => 'yes'],
],
],
];
The problem with this is when I add more than 1 of the same composites on the same page, the name will have a number, like invoice_fields_2[invoice_notice_of_default], invoice_fields_3[invoice_notice_of_default]. This will break the states because of the hardcoded name. Anybody know what can be done about this?
Thanks in advance!!
I need to add a custom filter to the aos_products popup where you can choose the line items from the aos_quotes edit view.
What the filter should look like is equal to WHERE aos_procucts_cstm.remaining_capacity_c > 0.
What I have so far is in editviewdefs.php of the aos_product module:
array(
'name' => 'remaining_capacity_c',
'label' => 'LBL_RESTKAPAZITAET',
'displayParams' =>
array(
'initial_filter' => array(
'&remaining_capacity_c > 0',
),
),
),
but this does not work as intended. I believe that it is not possible to set up the filter like I did. So any suggestions are highly appreciated.
Following below steps:
remaining_capacity_c needs to be a field type that where you can "Enable Range Search" in studio. So I would suggest using "Integer" type in this case.
Second, you will need to add the field into the popup search definition.
you will need to set the variables required to do a range search.
Example:
'initial_filter' => array(
'&remaining_capacity_c_advanced_range_choice=greater_than&range_remaining_capacity_c_advanced=0&start_range_remaining_capacity_c_advanced=&end_remaining_range_capacity_c_advanced=',
),
EDIT
You can use the keys found in date_range_search_dom dropdown. just set the [fieldname]_advanced_range_choice to one of the keys and range_[fieldname]_advanced to the value you wish to compare. When you wish to edit the start and end. You need to specify the start_range_[fieldname]_advanced and end_range_[fieldname]_advanced values.