View source
<?php
function styled_google_map_data_install() {
$files = [];
$pins = \Drupal::service('file_system')
->scanDirectory(drupal_get_path('module', 'styled_google_map_data') . '/images', '/.png/');
foreach (array_keys($pins) as $file_path) {
$file_content = file_get_contents($file_path);
$files[] = file_save_data($file_content);
}
$property_types = [
'Condo',
'Multi-Family',
'Residential',
];
$terms = [];
$term_storage = \Drupal::entityTypeManager()
->getStorage('taxonomy_term');
foreach ($property_types as $key => $property_type) {
$term = $term_storage
->create([
'vid' => 'real_estate',
'name' => $property_type,
'field_icon' => $files[$key],
]);
if ($term
->save()) {
$terms[$term
->id()] = $property_type;
}
}
batch_set([
'operations' => [
[
'import_real_estate',
[
$terms,
],
],
],
'finished' => 'demo_real_estate_finished',
'title' => t('Updating depths for all terms'),
'file' => drupal_get_path('module', 'styled_google_map_data') . '/demo.batch.inc',
]);
if (function_exists('drush_backend_batch_process')) {
$batch =& batch_get();
$batch['progressive'] = FALSE;
drush_backend_batch_process();
}
}
function styled_google_map_data_uninstall() {
$term_storage = \Drupal::entityTypeManager()
->getStorage('taxonomy_term');
$terms = $term_storage
->loadByProperties([
'vid' => 'real_estate',
]);
$term_storage
->delete($terms);
batch_set([
'operations' => [
[
'delete_real_estate',
[],
],
],
'finished' => 'demo_real_estate_finished',
'title' => t('Delete real estate'),
'file' => drupal_get_path('module', 'styled_google_map_data') . '/demo.batch.inc',
]);
if (function_exists('drush_backend_batch_process')) {
$batch =& batch_get();
$batch['progressive'] = FALSE;
drush_backend_batch_process();
}
}