1

Last week I started with TYPO3 and now I have to make an extension (widget) for a Dashboard plugin (where in the FE the User can select from a list of specific widgets and place them on this Dashboard).

The widget should be able to display the latest 5 of all news and (via dropdown) be able to show only the latest 5 news of a specific category.

For the News we're using EXT:news.

And that's where I'm stuck now.

In my custom extension, how can I access the deserved data (title, category and body) from the news-extension to pass it into my template?

Georg Ringer
  • 7,779
  • 1
  • 16
  • 34

1 Answers1

2

This is pretty easy to do as you can completly reuse the NewsDemand object for filtering. An example looks like this:

$newsRepository = $this->objectManager->get(NewsRepository::class);
$demand = $this->objectManager->get(NewsDemand::class);
$demand->setStoragePage('123');
$demand->setLimit(3);
$demand->setCategories(['12', '34']);
$demand->setCategoryConjunction('or');
$items = $newsRepository->findDemanded($demand);
$this->view->assign('items', $items);

Take a look at the NewsRepository which handles all the possibilities of the demand object.

andreas
  • 16,357
  • 12
  • 72
  • 76
Georg Ringer
  • 7,779
  • 1
  • 16
  • 34
  • For someone who's new to TYPO3, your answer's a bit cryptic, but after a bit research I guess I know what to do. Thank you :) – codeFareith Aug 29 '16 at 13:26
  • If you got any other questions, feel free to ask - however more information is then needed, like how does your extension is done (using extbase or not) ... – Georg Ringer Aug 29 '16 at 13:29
  • 1
    At first I've got problems with the objectManager. I couldn't use `$this->objectManager->...`, but have to instantiate it via `\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(...)`. But it works now. What I'd like to know now is: is there a way to get just all categories? I have to create a dropdown in the frontend, which lists categories and subcategories, to filter the result. For example we have a category called _Unternehmen_ which is a subcategory of _Unternehmensmitteilungen_ Btw: we're using extbase and fluid – codeFareith Aug 29 '16 at 14:21
  • 1
    Think I find it myself. I did it this way: `$categoryRepository = $objectManager->get('GeorgRinger\\News\\Domain\\Repository\\CategoryRepository'); $categories = $categoryRepository->findAll();` – codeFareith Aug 29 '16 at 15:13