We need a block for related content. It is like the Content block, but the difference is that the content block shows fixed content list, while the related block shows content based on the article on the current page.
Make sure you know about creating blocks first: http://integratedfordevelopers.com/content/documentation/article/create-a-block-with-integrated-block-bundle
Blocks can be loaded on all pages, but the Related content block load content based on the current loaded content (for example article). So this block can only be used on article detail pages (this is not validated, the block will simply not give any output if you use it elsewhere). For the test set-up you need to have an article page.
Steps for the test set-up:
You should have loaded the datafixes first.
Update your composer.json with these versions and do a composer update:
After that add your local domain to a channel (if you have not already):
Go to Menu - Manage - Channels
Edit a channel (with the pencil icon)
For domains, enter: localhost
Add a website to the channel (if you have not already):
Go to Menu - Manage - Connectors
Choose Options - New website configuration
form.config.name: Website 2
form.config.channels: the channel you have chosen
Add an content item:
Go to Create new - Article
Enter some test content, the title is important, this will be the URL. Title: "Article page for block"
In the content add: [block id="my_first_related_block"]
Develop your new block
Go to /admin/block/ and create an instance of your block called My first related block
Now you'll see your new block
Title (will be available from the based content block by default I think)
Published title (like in Content block)
Type (select box):
Show items which have the current document linked
Show items which share linked items with the current document
(two other types will be added in a next release)
Relation (select box, choose from Integrated relations as show at /admin/relation/)
Sort by (select box, options: Publication date, more options will be added in a next release)
Items per page (like in Content block)
Max items (like in Content block)
Layout (will be available from the based content block by default I think)
You need to create a BlockHandler for the block (kind of controller). In the BlockHandler you need to know the active document. You can do this with:
$document = $this->blockManager->getDocument();
For the type "Show items which have the current document linked" you have to query the content from mongodb. Please use the repository for this (no queries in controllers/blockhandlers/etc.). You need to query the content for relations.references.$id = $document.getId() AND relations.relationId = the relation as chosen in the block form.
Example situation: your article is linked to keywords "apple" and "banana". The block will show other content that also has the keywords "apple" and "banana" links.
First you have to find the ID's of the items that are linked to the current document with $document->getReferencesByRelationId($relationId) ($relationId as chosen from the form).
After that you need to query the content for relations.references.$id = one of the ids from the previous line AND relations.relationId = the relation as chosen in the block form.
I suspect this block to be a list with content item. We need to write specifications about how related items are determined. By (which) taxonomy? Automatically by content? Other ways? Which block settings are available for the user?
: We have to build this for a customer. Together with the customer I decided that we decide the specs for this block and that we will release this in Integrated 0.5. We should consider the wishes from the customer, I will describe these wishes below:
The block should show related content based on taxonomy (for example keywords).
The block should automatically show related content based on taxonomy (for example keywords).
The block should show related content based on manually linked taxonomy (for example keywords).
The block should automatically show related content based on the content of the item itself that is shown at the page. So it should scan the content and show automatically which related content should be shown in the related block.
This block doesn't support SOLR queries. Can this also be implemented? We need it for multiple issues in this weeks sprint.
can you tell me a bit more of what you need?
Never mind, I don't think it is neccesary to get the results from SOLR, a database query will also be sufficiënt. Nevertheless it would be a nice feature to have in the future.