/** * {@inheritdoc} */ public function findByIds($ids) { if (count($ids) === 0) { return []; } $parsed = $this->converter->convertIdsToGroupedIds($ids, ['a' => [], 'c' => []]); $accounts = $this->findAccountsByIds($parsed['a']); $contacts = $this->findContactsByIds($parsed['c']); $result = array_merge($accounts, $contacts); // the @ is necessary in case of a PHP bug https://bugs.php.net/bug.php?id=50688 @usort($result, function ($a, $b) use($ids) { return $this->comparator->compare($a['id'], $b['id'], $ids); }); return $result; }
/** * {@inheritdoc} */ public function getContentData(PropertyInterface $property) { $value = $property->getValue(); $locale = $property->getStructure()->getLanguageCode(); if ($value === null || !is_array($value) || count($value) === 0) { return []; } $ids = $this->converter->convertIdsToGroupedIds($value, ['a' => [], 'c' => []]); $accounts = $this->accountManager->getByIds($ids['a'], $locale); $contacts = $this->contactManager->getByIds($ids['c'], $locale); $result = array_merge($accounts, $contacts); @usort($result, function ($a, $b) use($value) { $typeA = $a instanceof Contact ? 'c' : 'a'; $typeB = $b instanceof Contact ? 'c' : 'a'; return $this->comparator->compare($typeA . $a->getId(), $typeB . $b->getId(), $value); }); return array_map(function ($entity) { $groups = ['fullContact', 'partialAccount']; if ($entity instanceof Account) { $groups = ['fullAccount', 'partialContact']; } return $this->serializer->serialize($entity, 'array', SerializationContext::create()->setGroups($groups)->setSerializeNull(true)); }, $result); }