You are here

public function ChannelManipulator::getFieldMapping in Entity Share 8.2

Get field mapping.

Parameters

\Drupal\entity_share_server\Entity\ChannelInterface $channel: The channel entity.

Return value

array The field mapping used for sorting.

Overrides ChannelManipulatorInterface::getFieldMapping

File

modules/entity_share_server/src/Service/ChannelManipulator.php, line 146

Class

ChannelManipulator
Class ChannelManipulator.

Namespace

Drupal\entity_share_server\Service

Code

public function getFieldMapping(ChannelInterface $channel) {
  $channel_entity_type = $channel
    ->get('channel_entity_type');
  $channel_bundle = $channel
    ->get('channel_bundle');
  $field_mapping = [];
  $field_keys = [
    'label',
    'changed',
  ];
  $entity_type = $this->entityTypeManager
    ->getStorage($channel_entity_type)
    ->getEntityType();
  $entity_keys = $entity_type
    ->getKeys();
  $resource_type = $this->resourceTypeRepository
    ->get($channel_entity_type, $channel_bundle);
  foreach ($field_keys as $original_field_key) {
    $field_key = $original_field_key;
    if (isset($entity_keys[$field_key])) {
      $field_key = $entity_keys[$field_key];
    }
    if ($resource_type
      ->hasField($field_key)) {
      $field_mapping[$original_field_key] = $resource_type
        ->getPublicName($field_key);
    }
  }
  return $field_mapping;
}