Related content block

Description

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

Set-up your test environment

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:
    "integrated/block-bundle": "~0.4",
    "integrated/content-bundle": "~0.4",
    "integrated/website-bundle": "~0.4",

  • 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
    theme: default

  • 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

Block options for block document

  • 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)

Handling of the block with type "Show items which have the current document linked"

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.

Handling of the block with type "Show items which share linked items with the current document"

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.

Technical tasks

None

Deployment actions

None

Activity

Show:
Marijn Otte
July 21, 2015, 9:27 AM

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?

Marcel
November 10, 2015, 9:56 AM

: 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.

Johan Liefers
December 14, 2015, 8:46 AM

This block doesn't support SOLR queries. Can this also be implemented? We need it for multiple issues in this weeks sprint.

Marijn Otte
December 14, 2015, 12:20 PM

can you tell me a bit more of what you need?

Johan Liefers
December 14, 2015, 12:31 PM

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.

Assignee

Unassigned

Client

None

Fix versions

Configure