You are here

public function SocialProfileFieldsHelper::getProfileFields in Open Social 8.5

Same name and namespace in other branches
  1. 8.9 modules/social_features/social_profile/modules/social_profile_fields/src/SocialProfileFieldsHelper.php \Drupal\social_profile_fields\SocialProfileFieldsHelper::getProfileFields()
  2. 8.3 modules/social_features/social_profile/modules/social_profile_fields/src/SocialProfileFieldsHelper.php \Drupal\social_profile_fields\SocialProfileFieldsHelper::getProfileFields()
  3. 8.4 modules/social_features/social_profile/modules/social_profile_fields/src/SocialProfileFieldsHelper.php \Drupal\social_profile_fields\SocialProfileFieldsHelper::getProfileFields()
  4. 8.6 modules/social_features/social_profile/modules/social_profile_fields/src/SocialProfileFieldsHelper.php \Drupal\social_profile_fields\SocialProfileFieldsHelper::getProfileFields()
  5. 8.7 modules/social_features/social_profile/modules/social_profile_fields/src/SocialProfileFieldsHelper.php \Drupal\social_profile_fields\SocialProfileFieldsHelper::getProfileFields()
  6. 8.8 modules/social_features/social_profile/modules/social_profile_fields/src/SocialProfileFieldsHelper.php \Drupal\social_profile_fields\SocialProfileFieldsHelper::getProfileFields()
  7. 10.3.x modules/social_features/social_profile/modules/social_profile_fields/src/SocialProfileFieldsHelper.php \Drupal\social_profile_fields\SocialProfileFieldsHelper::getProfileFields()
  8. 10.0.x modules/social_features/social_profile/modules/social_profile_fields/src/SocialProfileFieldsHelper.php \Drupal\social_profile_fields\SocialProfileFieldsHelper::getProfileFields()
  9. 10.1.x modules/social_features/social_profile/modules/social_profile_fields/src/SocialProfileFieldsHelper.php \Drupal\social_profile_fields\SocialProfileFieldsHelper::getProfileFields()
  10. 10.2.x modules/social_features/social_profile/modules/social_profile_fields/src/SocialProfileFieldsHelper.php \Drupal\social_profile_fields\SocialProfileFieldsHelper::getProfileFields()

Functions fetches profile fields from a profile type.

Parameters

string $profile_type_id: The profile bundle.

Return value

array An array of fields.

File

modules/social_features/social_profile/modules/social_profile_fields/src/SocialProfileFieldsHelper.php, line 35

Class

SocialProfileFieldsHelper
Class SocialProfileFieldsHelper.

Namespace

Drupal\social_profile_fields

Code

public function getProfileFields($profile_type_id) {
  $fields = [];

  // Use storage to get only the profile fields of the current bundle type.
  try {
    $profile_fields = $this->entityTypeManager
      ->getStorage('field_config')
      ->loadByProperties([
      'entity_type' => 'profile',
      'bundle' => $profile_type_id,
    ]);
  } catch (\Exception $e) {
    return $fields;
  }

  // Loop through the fields and return the necessary values.

  /** @var \Drupal\Core\Field\FieldConfigInterface $profile_field */
  foreach ($profile_fields as $profile_field) {

    // Rewrite the ID a bit, since otherwise config thinks it's an array.
    $id = str_replace('.', '_', $profile_field
      ->id());

    // Build the array.
    $fields[$id] = [
      'id' => $id,
      'name' => $profile_field
        ->getName(),
      'label' => $profile_field
        ->getLabel(),
    ];
  }

  // Return the array of fields.
  return $fields;
}