You are here

protected function SocialProfileFieldsSettingsForm::getProfileFields in Open Social 8.2

Functions fetches profile fields from a profile type.

Parameters

string $profile_type_id: The profile bundle.

Return value

array An array of fields.

2 calls to SocialProfileFieldsSettingsForm::getProfileFields()
SocialProfileFieldsSettingsForm::buildForm in modules/social_features/social_profile/modules/social_profile_fields/src/Form/SocialProfileFieldsSettingsForm.php
Form constructor.
SocialProfileFieldsSettingsForm::submitForm in modules/social_features/social_profile/modules/social_profile_fields/src/Form/SocialProfileFieldsSettingsForm.php
Form submission handler.

File

modules/social_features/social_profile/modules/social_profile_fields/src/Form/SocialProfileFieldsSettingsForm.php, line 182

Class

SocialProfileFieldsSettingsForm
Configure social profile settings.

Namespace

Drupal\social_profile_fields\Form

Code

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

  // Use storage to get only the profile fields of the current bundle type.
  $profile_fields = $this->fieldStorage
    ->loadByProperties([
    'entity_type' => 'profile',
    'bundle' => $profile_type_id,
  ]);

  // Loop through the fields and return the necessary values.
  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;
}