public function testGetContentDataWrongType() { $type = new ContactSelectionContentType($this->template, $this->contactManager->reveal(), $this->accountManager->reveal(), $this->serializer->reveal(), new CustomerIdConverter(), new IndexComparator()); $this->property->getValue()->willReturn('blabla'); $this->contactManager->getById(Argument::any(), Argument::any())->shouldNotBeCalled(); $this->accountManager->getById(Argument::any(), Argument::any())->shouldNotBeCalled(); $result = $type->getContentData($this->property->reveal()); $this->assertCount(0, $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); }