You are here

public function ContactStorageExportService::getLabels in Contact Storage Export 8

Returns labels from the field definitions.

Parameters

\Drupal\contact\MessageInterface $message: A contact message object to get labels for.

Return value

array The labels.

2 calls to ContactStorageExportService::getLabels()
ContactStorageExportService::encode in src/ContactStorageExportService.php
Returns the encoded contact messages.
ContactStorageExportService::serialize in src/ContactStorageExportService.php
Returns a serialized message.

File

src/ContactStorageExportService.php, line 240

Class

ContactStorageExportService
Provides a set of methods to export contact messages in CSV format.

Namespace

Drupal\contact_storage_export

Code

public function getLabels(MessageInterface $message) {
  $labels = [];
  foreach ($message
    ->getFieldDefinitions() as $key => $field) {
    if ($label = $field
      ->getLabel()) {

      // Remove characters not allowed in keys of associative arrays.
      $labels[$key] = filter_var($label, FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_HIGH | FILTER_FLAG_STRIP_LOW | FILTER_FLAG_NO_ENCODE_QUOTES);
    }
  }
  return $labels;
}