protected function getOptions() { $representer = $this->registry->getEntityRepresenter($this->entityClass); $options = []; foreach ($this->getEntityList() as $entity) { $options[(string) $representer->getProperties($entity)[$representer->keyProperty()]->get($entity)] = $representer->toString($entity); } return $options; }
/** * @param ActionRepresenter $representer * @param null|callable $predicate * @param null|callable $arguments * @return ActionRepresenter */ public function add(ActionRepresenter $representer, $predicate = null, $arguments = null) { $this->registry->register($representer); $predicate = $predicate ?: function () { return true; }; $arguments = $arguments ?: function ($entity) { $representer = $this->registry->getEntityRepresenter($entity); $key = $representer->keyProperty(); $properties = $representer->getProperties($entity); if (!$properties->has($key)) { return []; } return [$key => (string) $properties[$key]->get($entity)]; }; $this->actions[$representer->getClass()] = [$predicate, $arguments]; return $representer; }
protected function assembleValueWithActions($entity, Property $property, $value) { if (is_object($value)) { $entityRepresenter = $this->registry->getEntityRepresenter($entity); $propertyRepresenter = $this->registry->getEntityRepresenter($value); return ['caption' => $propertyRepresenter->render($value), 'actions' => array_merge($this->assembleActions($propertyRepresenter->getActions($value)), $this->assembleActions($entityRepresenter->getPropertyActions($entity, $property->name(), $value)))]; } return ['caption' => $this->toString($value), 'actions' => null]; }
function testRegisterEntityRepresenter() { $this->assertSame($this->registrar->getRepresenter(), $this->registry->getEntityRepresenter(\DateTime::class)); }