I think we should make use of the Drupal plugin system, so we can track all entities(currently only nodes, taxonomy term, and user is supported).The module should support plugins so you can write custom plugins to track custom entities(there is some pending feature requests for this).

Comments

nkoporec created an issue. See original summary.

nkoporec’s picture

Status: Active » Needs review
StatusFileSize
new54.37 KB

Created a patch which adds plugins support.Created basic plugins (node,user,taxonomy_terms).Under configuration, you can select to enable certain plugins.Also changed some functionality so that the module can track any enabled plugin.To add support for new entity just create a new plugin with plugin id(tracked entity id) and label then enabled it the configuration.

useernamee’s picture

Hey,
I have tested your patch. It applies and works. However it adds another step at enabling entity type for recently read (first you have to enable plugin then you have to enable it in list '/admin/config/system/recently-read'). This might be a bit counterintuitive. I've also tried to add poll as plugin. I have created new custom module with Poll class in 'my-new-module/src/Plugin/RecentlyReadType' and it was show in configuration afterwards.

However I did not menage to show recently viewed polls in views block. This might however be separate issue since I didn't find a way to show neither users nor taxonomy_terms which are already recognised via recently read type manager.

a.sinitsa’s picture

Test patch with commerce 2 products. Works as expected.

a.sinitsa’s picture

Status: Needs review » Reviewed & tested by the community

Tested on three different projects

mbatterton’s picture

Thanks for the patch @nkoporec this is just what I am looking for but I can't get it working. I have used composer to install the dev version and added the patch which has gone smoothly, but I don't see how @a.sinitsa has been able to get this working with commerce 2. I don't see "Products" listed in the list of Plugins. Please, can you advise what I am missing?

nkoporec’s picture

@mbatterton after applying the patch, you must create a plugin for commerce(for example you can see how taxonomy, node or user plugins are made). The patch doesn't contains the commerce plugin by default you must create it yourself.

a.sinitsa’s picture

Hi @mbatterton!
You should create new module Ex. recently_read_products with Commerce_product.php inside recently_read_products/src/Plugin/RecentlyReadType/

with this code:

<?php
namespace Drupal\recently_read\Plugin\recently_read\RecentlyReadType;

use Drupal\recently_read\Plugin\RecentlyReadTypeBase;

/**
 * Product recently read type.
 *
 * @RecentlyReadType(
 *   id = "commerce_product",
 *   label = @Translation("Product"),
 * )
 */
class commerce_product extends RecentlyReadTypeBase {}
mbatterton’s picture

@nkoporec and @a.sinitsa thank you, guys. This is exactly what I need thank you for getting back to quickly.

kmajzlik’s picture

i am unable to apply against 8.x-1.0 :-(

bgronek’s picture

Likewise. Unable to apply this patch.

bgronek’s picture

Version: 8.x-1.x-dev » 8.x-1.0
Status: Reviewed & tested by the community » Needs work

It looks like this patch needs to be re-rolled against the current 8.x-1.0 version of this module. Changing status to "Needs Work".

nkoporec’s picture

Version: 8.x-1.0 » 8.x-1.x-dev
Status: Needs work » Needs review

This patch still applies to the 8.x-1.x-dev.Patches should apply to dev(8.x-1.x-dev) branch and not to the release branch(8.x-1.0).

If you want to use this patch, clone the dev(8.x-1.x-dev) branch of the module and apply it.

bgronek’s picture

@nkoporec My bad. Thank you!

introfini’s picture

The patch seems to be working, but I can't seem to add the relationship to the views block when the base table is Products.

Am I missing something obvious or the patch doesn't have it yet?

Thanks!

nkoporec’s picture

@introfini this patch does not create a relationship. It provides a plugin system so you can create your own plugin for a custom entity. In order to track products, you need to create a new plugin (via a custom module), see #7 and #8 comments.

The patch only contains plugins for node, taxonomy and user entities, but can be extended to any kind of entity you want.

introfini’s picture

StatusFileSize
new165.37 KB

@nkoporec I understood that. I've the module with your patch and created a new plugin module as instructed in #8. This is what I have:

screenshot form

But from what I understood of the module in D8 it's needed to add a relationship "Recently read" like in the default /admin/structure/views/view/recently_read_content: When I try to that with a base table of Products (because my plugin is for Drupal Commerce products) no relationship of that type appears.

Do I need something more in my plugin?

bzoks’s picture

StatusFileSize
new20.44 KB

While testing patch #2 and trying to explain it's usage for @introfini, I realized that it does work with some adjustments and quirks, but it is only useful with further development (of plugins), just to fulfill a simple requirement of being able to track ANY Entity Type.
That's why I refactored it in such a way that Administrator can just tick checkboxes in a list of all (content) Entity Types and that's it... no need for custom plugin development. I tested it with core Entity Types (nodes, taxonomies), and also with module-provided Entity Types, for example, Product from commerce module.
I also developed an upgrade path from the 8.x-1.0 version and from the patch #2 version.

strozx’s picture

Status: Needs review » Reviewed & tested by the community

I have tested this and looked at the code and everything appears to be in order and working. Thanks, bzoks.

dunot’s picture

> it's needed to add a relationship "Recently read"
> like in the default /admin/structure/views/view/recently_read_content
After #18 and run /update.php in module` recently_read_content view relationship will be "Broken/missing handler".
But you can add the relationship in any other views.

zterry95’s picture

@nkoporec
Thanks for your great works on this module. I have add you as module maintainer.
You can commit it to the latest code and make new release.

Cheers!

nkoporec’s picture

@zterry95 Thank you!

nkoporec’s picture

I have reviewed the patch from #18, the code needed some cleanup and certain bug fixes (as per comment #20), also the tracking was not working with media entity due to not using type in the views query, so I have converted the query to use bundle field instead.

  • nkoporec committed 0f1d2fe on 8.x-1.x
    Issue #2962741 by nkoporec, bzoks, introfini: Add plugin support
    
nkoporec’s picture

Status: Reviewed & tested by the community » Fixed

Comitted to dev, please test it out and open a new issue if any errors appears.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

tm01xx’s picture

I installed latest dev 8.x-1.1+7-dev. After installing I went to admin/config/system/recently-read/config to uncheck the default Content (node) then checked for Commerce product. I then went to here admin/structure/views/view/recently_read_content/edit/block_1 -> The views relationship is broken.

nkoporec’s picture

@tm01xx The Recently Read Content view is meant to be used to render recently read content but since you disabled the Content in the recently read settings the view relationship will not be created. If you want to have a recently read commerce product then you will need to create a new view of Commerce products and add the relationship there.

sahilgidwani’s picture

This patch is not working in Drupal 9.1.0 because in the RecentlyReadRelationship.php the following line of code is using the bundle column but the table actually has the type column. So I request to open the issue again so that the patch can updated and tested.

Code in the patch

$this->query->addWhere('recently_read', "$basetable.bundle", array_filter(array_values($this->options['bundles'])), "IN");

Actual code should be

$this->query->addWhere('recently_read', "$basetable.type", array_filter(array_values($this->options['bundles'])), "IN");

sahilgidwani’s picture