0

Apparently if you take the "minimal" installation, it does not create the user picture field. I tried to manually create it, but now the Simple Facebook Connect module is not synching profile images, because it can't find the default user_picture field.

This is what the facebook module does:

// Try to download the profile picture and add it to user fields.
if (user_picture_enabled() && $picture_url) {
  if ($file = $this->downloadProfilePic($picture_url, $fbid)) {
    $fields['user_picture'] = $file->id();
  }
}
$new_user = User::create($fields);
$new_user->save();

I can confirm that it is able to get the $file, but the problem has something to do with the fields.

How do I correct recreate the "user_picture" field?

This is returning false:

function user_picture_enabled() {
      $field_definitions = \Drupal::entityManager()->getFieldDefinitions('user', 'user');
      return isset($field_definitions['user_picture']);
}

How do I add this field definition again?

I looked in the minimal.install file. I was hoping to find the code that enables user_picture, but all I could find was:

\Drupal::configFactory()->getEditable('system.theme.global')->set('features.node_user_picture', FALSE)->save(TRUE);

There is nothing in standard.install. I tried running the following, without any luck.

\Drupal::configFactory()->getEditable('system.theme.global')->set('features.node_user_picture', TRUE)->save(TRUE);

How do I get my user_picture field back without adding it manually, since I would end up with field_user_picture?

1 Answer 1

2

User pictures are no longer guaranteed to exist in Drupal 8. It is added by the standard profile, but not added if you use the minimal profile.

$field = \Drupal\field\Entity\FieldConfig::loadByName('user', 'user', 'user_picture');
$default_image = $field->getSetting('default_image');
$file = \Drupal::entityManager()->loadEntityByUuid('file', $default_image['uuid']);
$file->getFileUri();
3
  • Yes, but how do I get it BACK if it was removed? The facebook connect plugin wants the field to be "user_picture". If I add a field manually, it becomes "field_user_picture". So how do I get "user_picture" back? Mar 10, 2016 at 5:24
  • You need to do it in the way that the original install profile does it, through config. Look at /core/profiles/standard/config/install/field.field.user.user.user_picture.yml
    – Clive
    Mar 10, 2016 at 9:02
  • Importing the user picture related config files from the standard profile worked for me. Feb 28, 2017 at 20:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.