Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
802 B
1
Indexable
Never
use Drupal\user\Entity\User;

// Load the user by user ID.
$uid = 1; // Replace with the user ID you want to update.
$user = User::load($uid);

if ($user) {
    // Get the current 'user.data' field.
    $user_data = $user->get('user.data')->value;
    $user_data_array = unserialize($user_data);

    // Update the 'social_profile_privacy' value.
    $user_data_array['social_profile_privacy'] = 'new_value'; // Replace 'new_value' with the desired value.

    // Serialize the array back to a string.
    $user_data_serialized = serialize($user_data_array);

    // Set the updated 'user.data' field.
    $user->set('user.data', $user_data_serialized);

    // Save the user entity.
    $user->save();
}
else {
    \Drupal::messenger()->addError(t('User with ID %uid not found.', ['%uid' => $uid]));
}
Leave a Comment