I'm following official sulu documentation about creating custom data provider:
https://docs.sulu.io/en/2.2/cookbook/smart-content-data-provider.html#dataprovider
Here, inside ExampleDataProvider class, inside getConfiguration() method there is chunk of code:
->enableTypes([
['type' => 'example-type-1', 'title' => 'type-translation-key-1'],
['type' => 'example-type-2', 'title' => 'type-translation-key-2'],
])
And I for my repository class I'm using DataProviderRepositoryTrait trait, as suggested there.
What are those types? Can they be excluded. I assume they have something to do with filters of smart field type, but I don't understand how this works.
Update:
What the actual problem is - when I try to open edit page at back-end, where my smart type appears I get the error:
[Semantical Error] line 0, col 84 near 'type WHERE entity.id': Error: Class App\Entity\MatchEvent has no association named type
I tried just excluding the code that is adding enabled types, but it's the same.
By error, I would say that some sql query is still looking for some type parameters even I excluded enabled types, but I don't know where and how to fix this.
I found some similar issue here: How do i solve Semantical error: "Class has no association named.."
So if the problem is the same it means that field "type" should be added to my custom entity type. But it's not mentioned in this tutorial article?
I figured out that:
public function appendJoins(QueryBuilder $queryBuilder, $alias, $locale)
{
$queryBuilder->addSelect('type')->leftJoin($alias . '.type', 'type');
}
which I had to add inside my repository class when implementing DataProviderRepositoryInterface interface is adding this 'type' to query. If I comment out that line I don't get error any more, but my field never finish loading (spinner is running infinitely)
Yes you are right, this is for the filtering by
types
. These types are e.g. thetemplate-keys
forpages
and thetitle
is for the translation in the admin ui.The selected types can be used in your CustomDataProvider with the
Sulu/Component/Content/SmartContent/QueryBuilder
to filter the items by a specific type.The
DataProviderRepositoryTrait
uses the type-filtering on the these lines. You can also overwrite theappendTypeRelation
method, if the alias is not correct for your custom entity.But if you don't need filtering by types, you can just ignore it.