I've created custom content entity, where one of fields defined in BaseFieldDefinitions() is
$fields['game_category'] = BaseFieldDefinition::create('entity_reference')
->setLabel(t('Game category'))
->setDescription(t('Game category'))
->setSetting('target_type', 'taxonomy_term')
->setRevisionable(false)
->setCardinality(-1);
;
Now, I'm trying to create a list using Views, where one of displayed fields will be "Game category" term name. What I managed to achieve is to display that term's tid.
QUESTION: How to display term's name ?
I suppose I should add a relationship, so Views is able to make a JOIN with taxonomy table
My class exposing fields to Views looks like this:
class GameViewsData extends EntityViewsData implements EntityViewsDataInterface {
public function getViewsTableForEntityType(EntityTypeInterface $entity_type) {
return $entity_type->getDataTable() ? : $entity_type->getBaseTable();
}
public function getViewsData() {
$data = parent::getViewsData();
$data['game'] = array();
$data['game']['table']['group'] = t('Game Entity Table');
$data['game']['table']['provider'] = 'game_entity';
$data['game']['table']['base'] = array(
'field' => 'id',
'title' => t('Game Entity Table'),
'help' => t('Game Entity Table'),
'weight' => -10,
);
$data['game']['name'] = array(
'title' => t('name'),
'help' => t('name'),
'field' => array(
'id' => 'standard',
),
'sort' => array(
'id' => 'standard',
),
'filter' => array(
'id' => 'string',
),
'argument' => array(
'id' => 'string',
),
);
$data['game_entity_game__game_category'] = array();
$data['game_entity_game__game_category']['table']['group'] = t('Game Entity Table');
$data['game_entity_game__game_category']['table']['provider'] = 'game_entity';
$data['game_entity_game__game_category']['table']['join'] = array(
'game' => array(
'left_field' => 'id',
'field' => 'entity_id',
),
);
$data['game_entity_game__game_category']['game_category_target_id'] = array(
'title' => t('game_category_target_id'),
'help' => t('game_category_target_id'),
'field' => array(
'id' => 'standard',
),
'sort' => array(
'id' => 'standard',
),
'filter' => array(
'id' => 'string',
),
'argument' => array(
'id' => 'string',
),
);
return $data;
}
}