.. include:: /Includes.rst.txt
.. _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.
.. only:: html
.. 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 containts 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',
'shy' => '',
'dependencies' => '',
'conflicts' => '',
'priority' => '',
'module' => '',
'state' => 'stable',
'internal' => '',
'uploadfolder' => 0,
'modify_tables' => '',
'clearCacheOnLoad' => 1,
'lockType' => '',
'author_company' => '',
'version' => '1.0.0',
'constraints' => [
'depends' => [
'typo3' => '7.6.0-8.9.99',
],
'conflicts' => [],
'suggests' => [],
],
'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
createDemandObject();
$this->view->assignMultiple([
'news' => $this->newsRepository->findDemanded($demand)
]);
}
/**
* @return NewsDemand
*/
protected function createDemandObject()
{
$demand = $this->objectManager->get(NewsDemand::class);
$demand->setLimit(10);
return $demand;
}
/**
* @var \GeorgRinger\News\Domain\Repository\NewsRepository
* @inject
*/
protected $newsRepository;
}
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\\": "typo3conf/ext/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
/**
* @return NewsDemand
*/
protected function createDemandObject()
{
$demand = $this->objectManager->get(NewsDemand::class);
$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
arraygroupdbpages3500suggest1
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
/**
* @return NewsDemand
*/
protected function createDemandObject()
{
$demand = $this->objectManager->get(NewsDemand::class);
// Because of the naming "", you can use $this->settings['startingpoint']
$demand->setStoragePage($this->settings['startingpoint']);
$demand->setLimit(10);
return $demand;
}