I generated with drupal console utility my own module and content entity code. After I added a user entity reference field and a taxonomy term entity reference field.
Now I'm listing my content with views, I don't do nothing with the code generated the integration is done.
But, when I expose a filter by taxonomy field and user field it doesn't give me the option to show as a dropdown, it directly appears as a textfield.
In others views, listing nodes with entity reference fields, if I add exposed filter of entity reference offers to me a dropdown or autocomplete widget.
What I have to change to my entity to have dropdown select for my entity reference field as exposed filter in a view?
Here is the field definition in the Entity class
$fields['term_id'] = BaseFieldDefinition::create('entity_reference')
->setLabel(t('Log type'))
->setDescription(t('The term ID of the Log entry type.'))
->setRevisionable(FALSE)
->setSetting('target_type', 'taxonomy_term')
->setSetting('handler', 'default:taxonomy_term')
->setSetting('handler_settings',
array(
'target_bundles' => array(
'logs_type' => 'logs_type'
)))
->setTranslatable(FALSE)
->setDisplayOptions('view', array(
'label' => 'inline',
'type' => 'taxonomy_term',
'weight' => -2,
))
->setDisplayOptions('form', array(
'type' => 'entity_reference_autocomplete',
'weight' => -2,
'settings' => array(
'match_operator' => 'CONTAINS',
'size' => '60',
'autocomplete_type' => 'tags',
'placeholder' => '',
),
))
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE);
Update:
I achieve to have a dropdown in the exposed filter in my view creating the file mymodule.views.inc and puting this code:
function log_activity_views_data_alter(&$data) {
$data['log']['term_log_tid_depth'] = array(
'help' => t('Display content if it has the selected taxonomy terms, or children of the selected terms. Due to additional complexity, this has fewer options than the versions without depth.'),
'real field' => 'term_id',
'argument' => array(
'title' => t('Log type (with depth)'),
'id' => 'taxonomy_index_tid_depth',
'accept depth modifier' => TRUE,
),
'filter' => array(
'title' => t('Has taxonomy terms (with depth)'),
'id' => 'taxonomy_index_tid_depth',
),
);
}
But when I choose a term to filter the view, it does not return any item and it should do so.