function social_event_update_8908 in Open Social 10.0.x
Same name and namespace in other branches
- 10.3.x modules/social_features/social_event/social_event.install \social_event_update_8908()
- 10.1.x modules/social_features/social_event/social_event.install \social_event_update_8908()
- 10.2.x modules/social_features/social_event/social_event.install \social_event_update_8908()
Update labels for content visibility.
File
- modules/
social_features/ social_event/ social_event.install, line 1657 - Install, update and uninstall functions for the social_event module.
Code
function social_event_update_8908() {
// Load the existing configuration.
$config_name = 'field.storage.node.field_content_visibility';
$config = \Drupal::configFactory()
->getEditable($config_name);
$config_data = $config
->getRawData();
if (!empty($config_data['settings']['allowed_values'])) {
foreach ($config_data['settings']['allowed_values'] as $key => $value) {
if (!empty($value['label'])) {
// Since we are not sure about the array keys for the allowed values
// we loop over them, and whenever there is a possible label match
// we alter it.
// This to ensure any custom added values are not affected.
if (strpos($value['label'], 'Public -') !== FALSE) {
$config_data['settings']['allowed_values'][$key]['label'] = 'Public';
}
if (strpos($value['label'], 'Community -') !== FALSE) {
$config_data['settings']['allowed_values'][$key]['label'] = 'Community';
}
if (strpos($value['label'], 'Group members -') !== FALSE) {
$config_data['settings']['allowed_values'][$key]['label'] = 'Group members';
}
}
}
$config
->setData($config_data)
->save();
// Make sure we clear cached definitions for the fields.
\Drupal::service('entity_field.manager')
->clearCachedFieldDefinitions();
}
}