This extension contains a simple implementation of multiple rss feeds.
It provides an example of API which should be used to add new RSS feed from third-party module. Also it is provides an API to access available RSS feeds from anywhere.
The list of feeds can be accessed at the following url:
<magento2-url>/sampleservicecontractnew
To demonstrate how to provide a new service contract in Magento.
In Magento, if module declares service contract which can be used in other modules, it provides an API directory with contains public interfaces.
Generally API consists of two parts: public interfaces which provides access to module's data (FeedRepositoryInterface) and the Data API, which located in API/Data and declares interfaces which should be used as a module's data FeedInterface.
The main workflow of providing new API is to create public interfaces in API directory and provide it's implementation
inside Model directory, which should be declared as a preference
for this API through etc/di.xml.
View-related files in Magento are based on "application area." For instance, if the user browsing the website is in the "frontend" area - such as a customer purchasing a product - pages in the admin area cannot be loaded. The view folder contains subdirectories named by application area, which contain files only relevant to that area. This extension only deals places content on the frontend, so it only has a frontend directory.
The route config file maps the frontname "sampleservicecontractnew" to this extension, so the application looks in the extension to find the layout file describing the page.
There are three routing parameters used to determine which layout file must be loaded.
The general form of the url is <magento2-url>/<extension>/<action path>/<action name>/
.
Because the page is accessed at <magento2-url>/sampleservicecontractnew
, the routing parameters are:
- extension: "sampleservicecontractnew"
- action path: "index"
- action name: "index"
The index values are provided as defaults when none are explicitly provided.
The application thus looks in <extension-root>/view/frontend/layout
for a file called sampleservicecontractnew_index_index.xml
.
The layout file defines two things: a title (in the head/title element) and a block class to fill the page with content.
There can be custom or specialized block classes for sophisticated extensions, but here we use the most basic block class, Magento\Framework\View\Element\Template, to handle plain html content.
The block's template defines exactly what that content will be. The layout file defines which module contains the
template, and what its name is. Based on that, the application will look in <extension-root>/view/frontend/templates
for feed_list.phtml
. The block uses its toHtml()
method to process the template file and generate output html.
This module is intended to be installed using composer.
After the code is marshalled by composer, enable the module by adding it the list of enabled modules in the config or, if that file does not exist, installing Magento.
After including this component and enabling it, you can verify it is installed by going the backend at:
STORES -> Configuration -> ADVANCED/Advanced -> Disable Modules Output
Once there check that the module name shows up in the list to confirm that it was installed correctly.
Unit tests are found in the Test/Unit directory.
Magento Core team