You are here

function profile_post_update_configure_register_form_mode in Profile 8

Show the profile form at user registration using the profile_form widget.

File

./profile.post_update.php, line 63
Post update functions for Profile.

Code

function profile_post_update_configure_register_form_mode() {
  $profile_types = ProfileType::loadMultiple();
  $profile_types = array_filter($profile_types, function (ProfileType $profile_type) {
    return $profile_type
      ->getRegistration();
  });
  if (!$profile_types) {

    // No profile types to update.
    return;
  }
  $register_display = EntityFormDisplay::load('user.user.register');
  if (!$register_display) {

    // The "register" form mode isn't customized by default.
    $default_display = EntityFormDisplay::load('user.user.default');
    $register_display = $default_display
      ->createCopy('register');
  }

  // Assign the inline widget to each computed field.
  $weight = 90;
  foreach ($profile_types as $profile_type) {
    $register_display
      ->setComponent($profile_type
      ->id() . '_profiles', [
      'type' => 'profile_form',
      'weight' => ++$weight,
    ]);
  }
  $register_display
    ->setStatus(TRUE);
  $register_display
    ->save();
}