protected function addAction(CompiledResourceDefinitionInterface $resourceDefinition, CompiledActionDefinitionInterface $action, $instance = null) { $fields = []; $links = []; $operation = $action->getHttpMethod() === Request::METHOD_GET ? GetterField::OPERATION : SetterField::OPERATION; $transform = $action->getTransform(); $transformMapping = $action->getTransformMapping(); $url = $this->urlGenerator->route($action->getRouteName()); // FIXME: refactor so that this runs when the action is compiled $modelFields = $transformMapping->executeFieldFilterCallback($operation, $instance); foreach ($modelFields as $field) { $fields[] = $this->processField($field); $links = array_merge($links, $transformMapping->getLinks()); } if ($action->getType() !== ActionDefinition::TYPE_CREATE) { $instanceAction = $resourceDefinition->findFirstAction(ActionDefinition::TYPE_INSTANCE); $url = $this->urlGenerator->route($action->getRouteName(), ['id' => $transform->retrieveIdFromInstance($instanceAction->getTransformMapping(), $instance)]); } $this->data['_actions'][] = ['fields' => $fields, 'href' => $url, 'id' => $action->getId(), 'method' => $action->getHttpMethod(), 'type' => $action->getAcceptedContentType()]; return $links; }
protected function makeUrlForInstance(CompiledResourceDefinitionInterface $resourceDefinition, $instance) { $action = $resourceDefinition->findFirstAction(ActionDefinition::TYPE_INSTANCE); return $this->urlGenerator->route($action->getRouteName(), ['id' => $this->retrieveIdFromInstance($action->getTransformMapping(), $instance)]); }