function social_event_type_update_8902 in Open Social 10.0.x
Same name and namespace in other branches
- 10.3.x modules/social_features/social_event/modules/social_event_type/social_event_type.install \social_event_type_update_8902()
- 10.1.x modules/social_features/social_event/modules/social_event_type/social_event_type.install \social_event_type_update_8902()
- 10.2.x modules/social_features/social_event/modules/social_event_type/social_event_type.install \social_event_type_update_8902()
Create new field & field storage configuration for new event type icon field.
File
- modules/
social_features/ social_event/ modules/ social_event_type/ social_event_type.install, line 79 - Install, update and uninstall functions for the social_event_type module.
Code
function social_event_type_update_8902(&$sandbox) {
$config_file = drupal_get_path('module', 'social_event_type') . '/config/static/social_event_type_update_8902.yml';
if (is_file($config_file)) {
$sandbox['configs'] = Yaml::parse(file_get_contents($config_file));
if (!isset($sandbox['total'])) {
// Count the amount we need to add to cover batching..
$sandbox['total'] = count($sandbox['configs']);
$sandbox['current'] = 0;
}
$names = array_keys($sandbox['configs']);
$name = $names[$sandbox['current']++];
$data = $sandbox['configs'][$name];
$parts = explode('.', $name);
switch ($parts[0] . '.' . $parts[1]) {
case 'field.storage':
$entity_type = \Drupal::service('config.manager')
->getEntityTypeIdByName($name);
/** @var \Drupal\Core\Config\Entity\ConfigEntityStorageInterface $storage */
$storage = \Drupal::entityTypeManager()
->getStorage($entity_type);
$entity = $storage
->createFromStorageRecord($data);
$entity
->save();
break;
case 'field.field':
$field_config = FieldConfig::loadByName($parts[2], $parts[3], $parts[4]);
if ($field_config instanceof FieldConfigInterface) {
$field_config
->setDescription($data);
}
else {
$field_config = FieldConfig::create($data);
}
$field_config
->save();
break;
default:
// Fallback similar to before.
\Drupal::configFactory()
->getEditable($name)
->setData($data)
->save(TRUE);
}
$sandbox['#finished'] = $sandbox['current'] / $sandbox['total'];
}
}