Untitled

 avatar
unknown
plain_text
a year ago
802 B
3
Indexable
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]));
}
Editor is loading...
Leave a Comment