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;
  }
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;
  }
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 ; }
Functions fetches profile fields from a profile type.

@param string $profile_type_id
The profile bundle.

@return array
An array of fields.
Functions fetches profile fields from a profile type .