function user_install_picture_field

Creates a user picture image field for the User entity.

This is only used in core's standard.install, but is kept as a separate helper function so that other install profiles can reuse it.

2 calls to user_install_picture_field()
standard_install in drupal/core/profiles/standard/standard.install
Implements hook_install().
UserPictureTest::setUp in drupal/core/modules/user/lib/Drupal/user/Tests/UserPictureTest.php
Sets up a Drupal site for running functional and integration tests.

File

drupal/core/modules/user/user.install, line 305
Install, update and uninstall functions for the user module.

Code

function user_install_picture_field() {
  $t = get_t();
  $field = array(
    'field_name' => 'user_picture',
    'module' => 'image',
    'type' => 'image',
    'cardinality' => 1,
    'locked' => FALSE,
    'indexes' => array(
      'fid' => array(
        'fid',
      ),
    ),
    'settings' => array(
      'uri_scheme' => 'public',
      'default_image' => FALSE,
    ),
  );
  $field = field_create_field($field);
  $instance = array(
    'field_name' => 'user_picture',
    'entity_type' => 'user',
    'label' => 'Picture',
    'bundle' => 'user',
    'description' => $t('Your virtual face or picture.'),
    'required' => FALSE,
    'settings' => array(
      'file_extensions' => 'png gif jpg jpeg',
      'file_directory' => 'pictures',
      'max_filesize' => '30 KB',
      'alt_field' => 0,
      'title_field' => 0,
      'max_resolution' => '85x85',
      'min_resolution' => '',
      'default_image' => 0,
    ),
  );
  field_create_instance($instance);

  // Assign form display settings for the 'default' view mode.
  entity_get_form_display('user', 'user', 'default')
    ->setComponent('user_picture', array(
    'type' => 'image_image',
    'settings' => array(
      'progress_indicator' => 'throbber',
      'preview_image_style' => 'thumbnail',
    ),
    'weight' => -1,
  ))
    ->save();

  // Assign display settings for the 'default' and 'compact' view modes.
  entity_get_display('user', 'user', 'default')
    ->setComponent('user_picture', array(
    'label' => 'hidden',
    'type' => 'image',
    'settings' => array(
      'image_style' => 'thumbnail',
      'image_link' => 'content',
    ),
  ))
    ->save();
  entity_get_display('user', 'user', 'compact')
    ->setComponent('user_picture', array(
    'label' => 'hidden',
    'type' => 'image',
    'settings' => array(
      'image_style' => 'thumbnail',
      'image_link' => 'content',
    ),
  ))
    ->removeComponent('member_for')
    ->save();
}