I created a module that creates a block to show a schedule information. I need taxonomy terms to configure the block. I want that those terms are filled with preconfigured values when I install the module.
I have in my config/install folder the definition of my taxonomy:
core.entity_form_display.taxonomy_term.schedule_channels.default.yml
core.entity_view_display.taxonomy_term.schedule_channels.default.yml
field.field.taxonomy_term.schedule_channels.field_channel_id.yml
field.storage.taxonomy_term.field_channel_id.yml
taxonomy.vocabulary.schedule_channels.yml
Here the content of the file field.storage.taxonomy_term.field_channel_id.yml:
langcode: en
status: true
dependencies:
module:
- taxonomy
id: taxonomy_term.field_channel_id
field_name: field_channel_id
entity_type: taxonomy_term
type: string
settings:
max_length: 50
is_ascii: false
case_sensitive: false
module: core
locked: false
cardinality: 1
translatable: true
indexes: { }
persist_with_no_fields: false
custom_storage: false
Also in my schedule_block.install I have:
class schedule_block_class{
const schedule_block_channels_terms = array(
array(
'name' => 'Brava',
'field_channel_id' => 'BRA001'
),
array(
'name' => 'DJazz',
'field_channel_id' => 'DJA001'
));
const schedule_block_channels_vid = 'schedule_channels';
}
function schedule_block_install(){
$schedule_block_terms = schedule_block_class::schedule_block_channels_terms;
$schedule_block_vid = schedule_block_class::schedule_block_channels_vid;
foreach($schedule_block_terms as $schedule_block_term){
$term = Term::create(array(
'name' => $schedule_block_term['name'],
'field_channel_id' => $schedule_block_term['field_channel_id'],
'description' => '',
'parent' => array(0),
'vid' => $schedule_block_vid
));
$term->save();
}
}
function schedule_block_uninstall(){
$schedule_block_terms = schedule_block_class::schedule_block_channels_terms;
$schedule_block_vid = schedule_block_class::schedule_block_channels_vid;
$terms = array();
foreach($schedule_block_terms as $schedule_block_term){
if($terms_name = taxonomy_term_load_multiple_by_name($schedule_block_term['name'], $schedule_block_vid)){
$terms = array_merge($terms, $terms_name);
}
}
foreach($terms as $term){
$term->delete();
}
$taxo = \Drupal\taxonomy\Entity\Vocabulary::load(schedule_block_class::schedule_block_channels_vid);
if(!is_null($taxo)){
$taxo->delete();
}
}
When I install my module, my taxonomy vocabulary is created and my terms are loaded with my values
... BUT ...
After about 24h the values have disappeared. Checking in the table taxonomy_term__field_channel_id confirms that there is no more any values. I still have my taxo vocab, and all the needed tables are present.
Why the values are not permanent?