In a MenuLinkContent entity I've a list_string field populated with a $key => $value
array of a custom config entity. When I add or delete a config entity the values in my field are not updated until I rebuild the cache.
I think I should set a cache tag, but I can not figure out where I should add the tag and which tag should I use.
Edit: The array is created in a static method on my entity class.
public static function getConfigList() {
$entities = SvgIcon::loadMultiple();
$config_list = array();
/** @var SvgIconInterface $entity */
foreach ($entities as $entity) {
$config_list[$entity->get('id')] = $entity->get('label');
}
return $config_list;
}
The field is defined via hook_entity_base_field_info().
function svg_icon_menu_link_entity_base_field_info(EntityTypeInterface $entity_type) {
$fields = array();
if ( $entity_type->get('id') !== 'menu_link_content' ) {
return $fields;
}
$fields['svg'] = BaseFieldDefinition::create('list_string')
->setLabel('SVG sprite')
->setDescription('Select the SVG sprite file.')
->setSettings(array(
'allowed_values' => SvgIcon::getConfigList()
))
->setDisplayOptions('form', array(
'type' => 'select',
'weight' => 0,
'settings' => array(
'display_label' => TRUE
)
));
return $fields;
}