/** * Render the form. * * @return string * @api */ public function render() { $categories = array(); if ($this->arguments['categoryArr'] !== NULL) { foreach ($this->arguments['categoryArr'] as $categoryId) { $category = $this->newsCategoryRepository->findByIdentifier($categoryId); if ($category !== NULL) { $categories[] = $category; } } } $this->templateVariableContainer->add($this->arguments['as'], $categories); return $this->renderChildren(); }
/** * Get data * * @param NodeInterface $node The node that is currently edited (optional) * @param array $arguments Additional arguments (key / value) * @return array JSON serializable data */ public function getData(NodeInterface $node = NULL, array $arguments) { if ($this->newsCategoryRepository->countAll() === 0) { $category = new NewsCategory(); $category->setName('test'); $this->newsCategoryRepository->add($category); $this->persistenceManager->persistAll(); } $categories = array(); foreach ($this->newsCategoryRepository->findAll() as $category) { $categories[$category->getId()] = array('label' => $category->getName(), 'group' => substr($category->getName(), 0, 1), 'icon' => 'icon-key'); } return $categories; // return (array( // 'key' => array('label' => 'Foo', 'group' => 'A', 'icon' => 'icon-key'), // 'key2' => array('label' => 'Foo2', 'group' => 'A', 'icon' => 'icon-key'), // 'legal' => array('label' => 'Legal', 'group' => 'B', 'icon' => 'icon-legal'), // 'legal2' => array('label' => 'Legal2', 'group' => 'B', 'icon' => 'icon-legal'), // 'legal3' => array('label' => 'Legal3', 'group' => 'B', 'icon' => 'icon-legal'), // 'legal4' => array('label' => 'Legal4', 'group' => 'C', 'icon' => 'icon-legal') // )); }