function social_event_update_8910 in Open Social 10.3.x
Same name and namespace in other branches
- 10.0.x modules/social_features/social_event/social_event.install \social_event_update_8910()
- 10.1.x modules/social_features/social_event/social_event.install \social_event_update_8910()
- 10.2.x modules/social_features/social_event/social_event.install \social_event_update_8910()
Update the enrollment method text of an event on event add form.
File
- modules/
social_features/ social_event/ social_event.install, line 1707 - Install, update and uninstall functions for the social_event module.
Code
function social_event_update_8910() {
// Load the existing configuration.
$config_name = 'field.storage.node.field_enroll_method';
$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'], 'Open') !== FALSE) {
$config_data['settings']['allowed_values'][$key]['label'] = 'Open to enroll';
}
if (strpos($value['label'], 'Request') !== FALSE) {
$config_data['settings']['allowed_values'][$key]['label'] = 'Request to enroll';
}
if (strpos($value['label'], 'Invite-only') !== FALSE) {
$config_data['settings']['allowed_values'][$key]['label'] = 'Invite-only';
}
}
}
$config
->setData($config_data)
->save();
// Make sure we clear cached definitions for the fields.
\Drupal::service('entity_field.manager')
->clearCachedFieldDefinitions();
}
}