Drupal 8 - Entity Reference - Autocomplete - Add fields to search and result in autocomplete - autocomplete

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);

Related

How do I show a field based on the selection of another field

I have a form field, when I select a car, I want to get the type of car or the result of the model.
$this->crud->addField([
'name' => 'car_id',
'label' => 'Car',
'type' => 'select2_from_ajax',
'attribute' => 'name',
'model' => Car::class,
'data_source' => url('admin/api/cars'),
'placeholder' => 'Search and select a car',
'minimum_input_length' => 2,
]);
And how do I use the result to determine which other fields to show in the form?
You can do that in Backpack v5 using the included CrudField JS Library. To hide/show other fields depending on card_id, you should:
Step 1. In your setupCreateOperation() and/or setupUpdateOperation() load a new JS file:
Widget::add()->type('script')->content('assets/js/admin/forms/product.js');
Step 2. Create that JS file. Inside it, you can now easily select and get the value of Backpack fields. To show/hide other fields depending on car_id:
crud.field('car_id').onChange(function(field) {
// eg. show "car_model" if "car_id" is 1
crud.field('car_model').show(field.value == 1);
}).change();
For more things you can do with the CrudField JS Library, check out its docs.

What's the best way to site specific configuration in a multisite TYPO3 installation?

We have a TYPO3 9.5 installation with a bunch of different websites in it.
We want to store some custom configurations for each site (eg. show phone number in footer yes/no and something like this) and give the editors the possibility to change this in a simple way in the backend.
It would be nice if we can store these properties on the rootpage of each site but be able to overwrite (some) properties on sub pages if needed.
Similar to the page properties that fluidtypo3/flux brings.
Is there a possibility to achieve this with TYPO3 core and a custom extension? Eg. by extending the page table or adding custom table?
You need to differ between a site configuration and regular pages!
The site configuration is valid for the full site, so for every page
A page can be different on a page level
Both use cases are valid, so let's explain in detail
Extending the site configuration
The site configuration can easily be extended by creating the file <site-extension>/Configuration/SiteConfiguration/Overrides/sites.php
<?php
defined('TYPO3_MODE') || die('Access denied.');
call_user_func(
function ($table) {
$GLOBALS['SiteConfiguration'][$table]['columns']['trackingCode'] = [
'label' => 'Label',
'config' => [
'type' => 'input',
'eval' => 'trim',
'placeholder' => 'GTM-123456',
],
];
$GLOBALS['SiteConfiguration'][$table]['types']['0']['showitem'] .= ',--div--;Extra,trackingCode';
},
'site'
);
The value of the new field trackingCode can then be easily fetched, e.g. by TS with data = site:trackingCode. As an alternative you can also use the SiteProcessor to get access to the site configuration in a FLUIDTEMPLATE.
Extending pages
Create the file <site-extension>/Configuration/TCA/Overrides/pages.php
<?php
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns(
'pages',
[
'trackingCode' => [
'exclude' => true,
'label' => 'A label',
'config' => [
'type' => 'input',
]
],
]
);
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addToAllTCAtypes(
'pages',
'--div--;Extra, trackingCode'
);
and `ext_tables.sql``
CREATE TABLE pages (
trackingCode text NOT NULL
);
and you get access to the field with TypoScript and within FLUIDTEMPLATE with {data.trackingCode}.
Using slide
By adding trackingCode to the comma separated list in [FE][addRootLineFields] (use the Install Tool > Settings > Configure Installation-Wide Options it is possible to override the value for all subpages.
The following TypoScript will get up the rootline and return the 1st value set.
lib.code = TEXT
lib.code.data = levelfield:-1,trackingCode, slide

SuiteCRM setting initial_filter of the aos_products popup

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.

How to change the default order of the sub panels in the opportunities module

I have a need to change the default order of the sub panels in the opportunities module. I have been looking for a solution for a while and have not found a solution that works.
I am using SugarCRM CE 6.5.13
Thanks in advance.
Your question is actually unclear. Are you asking for the order of a subpanel meaning how to place one subpanel above another. Or is your question concerning the order of the data inside a subpanel?
A fast response to both is:
in {MainModule}/metadata/subpaneldefs.php there should be the sort order declared for the subpanel like this:
$layout_defs[{MainModule}] = array(
// list of what Subpanels to show in the DetailView
'subpanel_setup' => array(
'{TheSubpanel}' => array(
'order' => 1, // influences the place of the subpanel relative to the other subpanels
'module' => '{TheSubpanel}',
'subpanel_name' => 'default', // attention please check the subpanel module to make sure there is not another setting overriding this setting
'sort_order' => 'desc',
'sort_by' => 'date_entered',
...
check also the file defined above that contains the subpanels fields. In this case it can be found in {TheSubpanel}/metadata/subpanels/default.php
$module_name = '{TheSubpanel}';
$subpanel_layout = array(
'top_buttons' => array(
'where' => '',
'sort_order' => 'desc',
'sort_by' => 'date_entered',
Please consider that after a change you need to run 'rebuild & repair' and if you manually clicked on a sort field then you should clear your cookie cache and log in again too.
There are other questions on stack overflow concering this like how-to-change-default-sort-in-custom-subpanel-sugarcrm
If you do not want code level customization then you can just drag and drop the sequence of subpanels on detail view of record. The sequence of subpanel will be saved.

How to use the ChoiceListInterface in Symfony 2?

I'd like to display a dynamic list of checkboxes in a form.
So far, I built a form embedding a static list of checkboxes, and I created a Tag entity for different values in different languages and populated the database. I'd like to replace the static checkboxes by a dynamic list based on the Tag entity.
The documentation says I should use the ChoiceListInterface. But it is really poorly documented. Would you have an example or a global logic explanation to help me ?
You can extend LazyChoiceList abstract class and implement loadChoiceList() method, create a service of it, inject it to the form and set it as choice_list option.
Finally, I used an entity field type :
->add('tags', 'entity', array(
'class' => 'bndMyBundle:Tag',
'query_builder' => function(EntityRepository $er){
return $er->createQueryBuilder('t')
->orderBy('t.en', 'ASC');
},
'expanded' => true,
'multiple' => true,
'property' => 'en',
))
Then, I just need to replace the 'en' value by the user's current locale to choose the right language.