You are here

public function UserExportPluginBase::profileGetTaxonomyFieldValue in Open Social 8.3

Same name and namespace in other branches
  1. 8.9 modules/social_features/social_user_export/src/Plugin/UserExportPluginBase.php \Drupal\social_user_export\Plugin\UserExportPluginBase::profileGetTaxonomyFieldValue()
  2. 8.4 modules/social_features/social_user_export/src/Plugin/UserExportPluginBase.php \Drupal\social_user_export\Plugin\UserExportPluginBase::profileGetTaxonomyFieldValue()
  3. 8.5 modules/social_features/social_user_export/src/Plugin/UserExportPluginBase.php \Drupal\social_user_export\Plugin\UserExportPluginBase::profileGetTaxonomyFieldValue()
  4. 8.6 modules/social_features/social_user_export/src/Plugin/UserExportPluginBase.php \Drupal\social_user_export\Plugin\UserExportPluginBase::profileGetTaxonomyFieldValue()
  5. 8.7 modules/social_features/social_user_export/src/Plugin/UserExportPluginBase.php \Drupal\social_user_export\Plugin\UserExportPluginBase::profileGetTaxonomyFieldValue()
  6. 8.8 modules/social_features/social_user_export/src/Plugin/UserExportPluginBase.php \Drupal\social_user_export\Plugin\UserExportPluginBase::profileGetTaxonomyFieldValue()
  7. 10.3.x modules/social_features/social_user_export/src/Plugin/UserExportPluginBase.php \Drupal\social_user_export\Plugin\UserExportPluginBase::profileGetTaxonomyFieldValue()
  8. 10.0.x modules/social_features/social_user_export/src/Plugin/UserExportPluginBase.php \Drupal\social_user_export\Plugin\UserExportPluginBase::profileGetTaxonomyFieldValue()
  9. 10.1.x modules/social_features/social_user_export/src/Plugin/UserExportPluginBase.php \Drupal\social_user_export\Plugin\UserExportPluginBase::profileGetTaxonomyFieldValue()
  10. 10.2.x modules/social_features/social_user_export/src/Plugin/UserExportPluginBase.php \Drupal\social_user_export\Plugin\UserExportPluginBase::profileGetTaxonomyFieldValue()

Returns the values of a taxonomy reference field.

Parameters

string $field_name: The field name to get the value for, should be taxonomy term reference.

\Drupal\profile\Entity\ProfileInterface $user_profile: The profile to get the data for.

Return value

string Returns comma separated string of taxonomy terms of the field.

Overrides UserExportPluginInterface::profileGetTaxonomyFieldValue

3 calls to UserExportPluginBase::profileGetTaxonomyFieldValue()
UserInterests::getValue in modules/social_features/social_user_export/src/Plugin/UserExportPlugin/UserInterests.php
Returns the value.
UserProfileTag::getValue in modules/social_features/social_user_export/src/Plugin/UserExportPlugin/UserProfileTag.php
Returns the value.
UserSkills::getValue in modules/social_features/social_user_export/src/Plugin/UserExportPlugin/UserSkills.php
Returns the value.

File

modules/social_features/social_user_export/src/Plugin/UserExportPluginBase.php, line 213

Class

UserExportPluginBase
Base class for User export plugin plugins.

Namespace

Drupal\social_user_export\Plugin

Code

public function profileGetTaxonomyFieldValue($field_name, ProfileInterface $user_profile = NULL) {
  if ($user_profile === NULL) {
    return '';
  }
  $concatenated_value = '';
  try {
    $values = $user_profile
      ->get($field_name)
      ->getValue();
    if (is_array($values) && !empty($values)) {
      $taxonomy_terms = [];
      foreach ($values as $x => $value) {
        if (isset($value['target_id'])) {

          /** @var \Drupal\taxonomy\Entity\Term $term */
          $taxonomy_term = Term::load($value['target_id']);
          $taxonomy_terms[] = $taxonomy_term
            ->getName();
        }
      }
      $concatenated_value = implode(', ', $taxonomy_terms);
    }
  } catch (\Exception $e) {
    $concatenated_value = '';
  }
  return $concatenated_value;
}