.. _ext-based-on-news: Extensions based on EXT:news ============================ If you are using news records but need custom configuration and custom settings, you should think of creating a separate extension. This is really simple, just take a look at the following example. .. contents:: :local: :depth: 1 Setup of the extension ---------------------- As a demonstration, a new extension with the extension key ``news_filter`` will be created. The following files and its content is required. ext_emconf.php ^^^^^^^^^^^^^^ This file contains the basic information about its extension like name, version, author... .. code-block:: php 'News Filter', 'description' => 'News filtering', 'category' => 'fe', 'author' => 'John Doe', 'author_email' => 'john@doe.net', 'author_company' => '', 'state' => 'stable', 'uploadfolder' => 0, 'clearCacheOnLoad' => 1, 'version' => '1.0.0', 'constraints' => [ 'depends' => [ 'typo3' => '7.6.0-8.9.99', ], 'conflicts' => [], 'suggests' => [], ], ]; ext_localconf.php ^^^^^^^^^^^^^^^^^ Create a basic plugin with one action called ``list``. .. code-block:: php 'list', ] ); }; $boot(); unset($boot); Configuration/TCA/Overrides/tt_content.php ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Register the plugin: .. code-block:: php newsRepository = $newsRepository; } public function listAction() { $demand = $this->createDemandObject(); $this->view->assignMultiple([ 'news' => $this->newsRepository->findDemanded($demand) ]); } protected function createDemandObject(): NewsDemand { $demand = new NewsDemand(); $demand->setLimit(10); return $demand; } } Resources/Private/Templates/Filter/List.html ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Create the template: .. code-block:: html
{newsItem.title}
No news found
Setup ----- After enabling the extension in the Extension Manager and creating a plugin "Filter" on a page, you will see up to 10 news records of your system. .. hint:: If your installation is based on composer, you need to add the classes to the PSR-4 section. .. code-block:: js "autoload": { "psr-4": { "GeorgRinger\\NewsFilter\\": "path/to/news_filter/Classes/" } } Configuration ------------- There are multiple ways how to configure which news records should be shown. The fastest way is to hardcode the configuration. Hardcode it ^^^^^^^^^^^ By modifying the controller with the following code, you will change the output to show only those news records which fulfill the following requirements: - The pid is ``123`` - The author is ``John`` - The id of the records is neither ``12`` nor ``45``. .. code-block:: php protected function createDemandObject(): NewsDemand { $demand = new NewsDemand(); $demand->setStoragePage('123'); $demand->setAuthor('John'); $demand->setHideIdList('12,45'); return $demand; } Use FlexForms ^^^^^^^^^^^^^ FlexForms are a powerful tool to let editors configure plugins. Configuration/TCA/Overrides/tt_content.php """""""""""""""""""""""""""""""""""""""""" Exchange the existing file with the following content. .. code-block:: php LLL:EXT:news/Resources/Private/Language/locallang_be.xlf:flexforms_tab.settings array group pages 3 50 0 suggest 1 Important is that each element's name is prepended with ``settings.``. .. hint:: Take a look at the FlexForms of the news extension for inspiration. You can even just copy & paste settings from there. The file can be found at ``EXT:news/Configuration/FlexForms/flexform_news.xml``. Classes/Controller/FilterController.php """"""""""""""""""""""""""""""""""""""" Adopt the controller to use the settings instead of the hardcoded ones. .. code-block:: php protected function createDemandObject(): NewsDemand { $demand = new NewsDemand(); // Because of the naming "", you can use $this->settings['startingPoint'] $demand->setStoragePage($this->settings['startingPoint']); $demand->setLimit(10); return $demand; }