You are here

protected function CasAttributesSubscriber::getFieldMappings in CAS Attributes 8

Same name and namespace in other branches
  1. 2.x src/Subscriber/CasAttributesSubscriber.php \Drupal\cas_attributes\Subscriber\CasAttributesSubscriber::getFieldMappings()

Map fields to the pre-defined CAS token values.

Parameters

array $casAttributes: The list of CAS attributes for the user logging in.

2 calls to CasAttributesSubscriber::getFieldMappings()
CasAttributesSubscriber::onPreLogin in src/Subscriber/CasAttributesSubscriber.php
Subscribe to the CasPreLoginEvent.
CasAttributesSubscriber::onPreRegister in src/Subscriber/CasAttributesSubscriber.php
Subscribe to the CasPreRegisterEvent.

File

src/Subscriber/CasAttributesSubscriber.php, line 151

Class

CasAttributesSubscriber
Provides a CasAttributesSubscriber.

Namespace

Drupal\cas_attributes\Subscriber

Code

protected function getFieldMappings(array $casAttributes) {
  $mappings = $this->settings
    ->get('field.mappings');
  if (empty($mappings)) {
    return [];
  }
  $field_data = [];
  foreach ($mappings as $field_name => $attribute_token) {
    $result = trim($this->tokenService
      ->replace($attribute_token, [
      'cas_attributes' => $casAttributes,
    ], [
      'clear' => TRUE,
    ]));
    $result = html_entity_decode($result);

    // Only update the fields if there is data to set.
    if (!empty($result)) {
      $field_data[$field_name] = $result;
    }
  }
  return $field_data;
}