TYPO3 7.6 backend search (TCA searchFields) does not work on related table - typo3

Following constellation:
TYPO3 7.6.6
own Extension
I have two simple tables:
tx_exaibbrplus_domain_model_clients (clients)
tx_exaibbrplus_domain_model_yearsclientsinstitutions (yci)
One "clients" with a column for a social security number (ex: 123.4567.675.432)). Another (yci) with a relation to clients.
I need the possibility to search the social security number on the second table (yci). On the classic list view I can see the clients social security number (see screenshot) but the list search does not work on the clients social security number.
My TCA (most important parts) of the second table contains "clients" in searchFields.
return array(
'ctrl' => array(
'title' => 'LLL:EXT:exaibbrplus/Resources/Private/Language/locallang_db.xlf:tx_exaibbrplus_domain_model_yearsclientsinstitutions',
'label' => 'year',
'label_alt' => 'clients',
'label_alt_force' => TRUE,
'searchFields' => 'year, clients',
Using the live search to search a social security number works (and brings results of clients table).
Any ideas welcome.

After further investigations and exchange with TYPO3 gurus... I led myself to the illusion this can be achieved because it was so easy to display the related data in the list. Meanwhile I also found a feature whish for this, see: https://forge.typo3.org/issues/75017
In short: there is no solution for this with actual stock TYPO3.

Related

Adding a single field adds a lot of seconds to page generation time

I know in this case I must then customize storing/updating data. No problem in this side.
I m adding this field
$this->crud->addField([
'label' => 'Denominazione',
'type' => 'text',
'tab' => 'Cliente/Richiedente',
'name' => 'customer.name',
'wrapper' => ['class' => 'form-group col-md-6'],
'attributes' => [
'class' => 'form-control text-uppercase'
]
]);
The entity being edited is a Practice
Practice has a 1:1 relationship to Customer
public function customer()
{
return $this->hasOne(Customer::class, 'practice_id');
}
and customer has the field named name
What I'm diong works perfectly but the problem is that adding this field, bring page load time from <3 sec to >9 second
I've only 1 record in practices table and only 1 record in customers table
customer.practice_id point to practice.id and is a foreign key in the db
I think i'm doing something wrong here, and I don't know why it's adding so much time to load a single field !
Notes
I am using debug bar for laravel, so I've execution time of ALL queries. The problem is NOT a slow query.
adding field to a different tab doesn't change; removing tabs at all doesn't change execution time; removing this specific field removes 8 seconds of 9 total execution. Why ?!
I'm using latest version of backpack, 5.3.5, with also a paid Pro package
Also note I'm not using a TONS of views
With the field
Without the field
I was unable to reproduce that specific issue.
I've create a CRUD, added 2 Fields (one text and other hasOne.relation_attribute), with or without the hasOne field the load times are similar. 200ms/350ms
From the issue you described I would expect atleast for it to go to 1 second or something similar when I added the hasOne relation
The times are very similar, if I refresh the page some more times I get less loading time with the hasOne field that with only the text field.
If you use the hasOne relation in any other crud you can notice the same behavior? Or is it only in this specific CRUD?
I tried it also in our demo, specifically the MonsterCrud that has ALOT of fields and it's not optimized. Removing the hasOne fields from there has not the impact you are describing here.
If you change the field place instead of deleting, same happens ?
Cheers
I opened an issue on backpack crud to full document my timings. I found 'where' the issue is in the backpack code, but NOT WHY. And also, I've no idea on how to make it reproducible
The problem is when internally backpack try to 'guess' the default field name of a relationship.
By my knowledge, the implementation is not optimized, but has no problem, but a specific call causes 7 seconds of 'hang'
That said, I found 2 workarounds
Adding a attribute field to each field coming from a relationship
(instead of 1.) Adding in each models a public function identifiableAttribute() returning the default field name for a model, just to avoid at all the calling of that code
So
I'am not sure if it's not a strange bug of framework, backpack or php, but 2 of my coworkers, with same code, has same problem, but, we cannot reproduce in no other project, so it's of course due to a moltitude of factors we cannot understand
Is there 2 workarounds and now our code bring a full monster page on < 1 second

How to re-order 'columns listing in list module in Typo3'

I'm setting up a storage folder where records can be entered via tca, I need to display two columns in the backend when they are listing, two columns are displaying now but the issue is one column is far from another column, needed to display columns both near. I used description_column in ctrl section (TCA) to display the second column. Where do I need to change to re-order the columns?
attaching the screenshot below: volume column is needed near name column, now it is far away
Thank you
maybe you are looking for the configuration label_alt and lable_alt_force. with this you can change the shown label of a record to a concatenation of multiple fields:
this needs to be configured in the ctrl part of the TCA of the records.
'ctrl' => [
'label' => 'header',
'label_alt' => 'header,subheader',
'label_alt_force' => 1
],
be aware: this will change the label in all usages, not only the list display
see the manual

Make records "Non-Editable" after certain approving in TCA TYPO3 backend forms.

I have an extension called calendar and it contains a record event. For an event to be displayed on the Front End it has be approved by the admin. But once the admin has approved/rejected it, the record should no longer be editable from the backend.
I want to do something like this :
TcaEvent.php
if ($currentRecord_Permission=='Accept' or $currentRecord_Permission=='Reject')
# Make the current record non-editable
else #make the current record editable
Will the $TCA array contain the details of the current record being edited? If so, I can use it to achieve the above mentioned.
Try to use 'editlock'. This is exactly what you need.
Field name, which – if set – will prevent all editing of the record
for non-admin users.The field should be configured as a checkbox type.
Non-admins could be allowed to edit the checkbox but if they set it,
they will effectively lock the record so they cannot edit it again –
and they need an Admin-user to remove the lock.Note that this flag is
cleared when a new copy or version of the record is created.This
feature is used on the pages table, where it also prevents editing of
records on that page (except other pages)! Also, no new records
(including pages) can be created on the page.
So all you have to do is to set this field to TRUE after admin will approve the record. Or even admin can set that field if the approve means he enter to edit the BE record anyway.
Read more here:
http://typo3.org/documentation/document-library/core-documentation/doc_core_tca/4.7.1/view/1/3/
Find 'editlock'.
Basically you have to define in your TCA waht field in table will be an editlock field like this:
$TCA['tx_address_domain_model_item'] = array(
'ctrl' => array(
'title' => 'Title'
'editlock' => 'editlock',
...
The $TCA is a configuration array and does not contain any data of any records. It just holds the configuration of all fields that TYPO3 uses. There is also not a field which prevents a record from beeing edited except an admin. To achive this, you can create a second page which holds approved records and make this page invisible for non admin users via the permission module. Just set the owner of the page to user admin and group admin.

Is there way to create & index N no. of 'fields' dynamically with Sphinx

I am using Sphinx (with Thinking Sphinx v2.0 for RoR plugin),
Lets say I have several indexes on User model, lets say on 'name', 'address' and its one-to-many associations like 'posts' , 'comments' etc.
This means searching by post content would return me the User who made the post, and using :fieldmask 'rank mode' of sphinx, I am able to determine that the user was searched due to matching of 'posts'. But user has 'many' posts. So how to determine which 'post' it matched.
Is there any way, while indexing I can specify the index dynamically.?
For e.g. If I can specify index 'post_1'='< post1content >' , 'post_5'='< post5content >' as different 'fields' for user1; similarly 'post_2', 'post_7' for user2, Thus after searching It would return me user2 matched with matching fields as post_7...
Sphinx can't have different fields for each record, I'm afraid, so what you're hoping to do isn't possible with that approach.
If you need to know which posts match a query, I'd recommend conducting the search on the Post model instead, and then you can refer to a post's user? You could sort by user_id before weight, or group by user_id (so only one post per user is returned)? You'd be able to bring in user data into the Post index definition (and if a post has one user, then that data is kept to single values, instead of many, per record).
Hope this gives you some clarity with your options.
If you know, you want to search for post_5 in one query, and for post_7 in another query, you may use json as {post_1:, post_2:}.
Problem is that you have to know number of post you are searching for.
Maybe look to: https://stackoverflow.com/a/24505347/1444576 -if it is similar to your example.

Drupal 7: Sorting multiple content types in Views, with different date fields

I'm using Drupal 7, with the Views, Feeds and Views PHP modules (among others, but I think those are the only relevant ones).
My goal is a single view that combines (a) multiple RSS feeds brought in through the Feeds module, (b) two or three content types of my own, for contant created manually on my site. The result will be a block and a page that has a stream of all my latest work, wherever it is -- my own site or another site (as long as that other site has an RSS feed, of course).
The ideal result would show a single list, sorted by date, mingling the items without regard for content type.
My problem: The Feeds module and my custom content types have different date fields. My content types have a field called Original Date, which I set when I create content (eg, adding an article I wrote three years ago -- I clearly want it to be sorted by when it was published, not when I added it to the site). However, each feed_item has a date field, Published Date, that corresponds to the date in the RSS feed and is received with the rest of the item by RSS.
I have tried to use the Views PHP functionality to use if/then statements, in a variety of ways. For example, I check what the content_type is, and then set a variable to either the Original Date or by the Published Date, depending on the content type. Alternatively, I have tested whether the Original Date field is set; if so, I return that field, otherwise I return the Published Date field. They all fail in various ways. Most throw PHP errors that are visible even to anonymous users (obviously a problem).
I have tried these various approaches directly in the Sort Criterial section of Views; I've also tried to come up with the date in the Fields section, and then have a Sort criterion call that result. I've converted everything to a Unix timestamp, to make sure I have something simple to sort by; I've tried leaving dates as dates. No luck any which way.
Here's the really weird part: I have successfully used these approaches to display the correct date, so that (for example) the block shows • TITLE | Original Date for custom content types, and • TITLE | Published Date for feed items. But when I try the same approach(es) to sort by date, it fails.
Am I overlooking something simpler? Do I have to use PHP Views? Is there some other way to sort a View of multiple content types by a combination of two different (though similar) fields?
Thanks!
tf
Have you tried using the relationship feature of views? You could use that to get access to all of the date fields of all of the content types, then add some conditional code to the field item and you should be golden. (That is, if I'm understanding the question correctly...)
I found many possible solutions and summarized them here: https://drupal.org/node/2133879
However, this is a simple solution that I'd recommend:
In a custom module use the hook_views_query_alter() function to alter the sort criteria to use CASE ... WHEN to add a conditional in the orderby condition. A good example is shown here:
<?php
/**
* Implements hook_views_query_alter
* #param type $view
* #param type $query
*/
function MODULE_views_query_alter(&$view, &$query) {
if ($view->name == 'views_name' && $view->current_display == 'display_name') {
$query->orderby = array(
array(
'field' => 'CASE WHEN field_data_field_date_publication.field_date_publication_value
THEN field_data_field_date_publication.field_date_publication_value
ELSE node.created END',
'direction' => 'DESC',
)
);
}
}
?>