You are here

public function ChannelManipulator::getSearchConfiguration in Entity Share 8.2

Same name and namespace in other branches
  1. 8.3 modules/entity_share_server/src/Service/ChannelManipulator.php \Drupal\entity_share_server\Service\ChannelManipulator::getSearchConfiguration()

Get field mapping.

Parameters

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

Return value

array The field mapping used for text search.

Overrides ChannelManipulatorInterface::getSearchConfiguration

File

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

Class

ChannelManipulator
Class ChannelManipulator.

Namespace

Drupal\entity_share_server\Service

Code

public function getSearchConfiguration(ChannelInterface $channel) {
  $channel_entity_type = $channel
    ->get('channel_entity_type');
  $channel_bundle = $channel
    ->get('channel_bundle');
  $entity_type = $this->entityTypeManager
    ->getStorage($channel_entity_type)
    ->getEntityType();
  $entity_keys = $entity_type
    ->getKeys();
  $resource_type = $this->resourceTypeRepository
    ->get($channel_entity_type, $channel_bundle);
  $search_configuration = [];
  if (isset($entity_keys['label']) && !empty($entity_keys['label'] && $resource_type
    ->hasField($entity_keys['label']))) {
    $search_configuration['label'] = [
      'path' => $resource_type
        ->getPublicName($entity_keys['label']),
      'label' => $this
        ->t('Label'),
    ];
  }

  // Get the searches from configuration.
  if (!is_null($channel
    ->get('channel_searches'))) {
    foreach ($channel
      ->get('channel_searches') as $search_id => $search) {
      $search_configuration[$search_id] = [
        'path' => $search['path'],
        'label' => $search['label'],
      ];
    }
  }
  return $search_configuration;
}