* {organization} * * * @package Opentalent\OtTemplating\ViewHelpers */ class GetByIdViewHelper extends AbstractViewHelper implements LoggerAwareInterface { use LoggerAwareTrait; use TemplateVariableViewHelperTrait; /** * >> Required to prevent typo3 to escape the html output * @var boolean */ protected $escapeOutput = false; /** * @var OrganizationRepository * */ protected $organizationRepository; /** * -- This method is expected by Fluid -- * Declares the viewhelper's parameters */ public function initializeArguments() { $this->registerArgument( 'as', 'string', 'Name of the returned array', true ); $this->registerArgument( 'organizationId', 'integer', 'Id of the organization', true ); } /** * -- This method is expected by Fluid -- * Renders the content as html * * @return string * @throws ApiRequestException */ public function render() { $as = $this->arguments['as']; $organizationId = $this->arguments['organizationId']; try { $organization = $this->organizationRepository->findById($organizationId); } catch (ApiRequestException $e) { $this->logger->error(sprintf('API Error: %s', $e->getMessage())); $organization = new Organization(); $organization->setName(""); } $variables = [$as => $organization]; return $this->renderChildrenWithVariables($variables); } /** * @param OrganizationRepository $organizationRepository */ public function injectOrganizationRepository(OrganizationRepository $organizationRepository) { $this->organizationRepository = $organizationRepository; } }