Tagger can not be initialized in custom snippet - MODX 3.0.1

Hello everyone,

After we updated the website from MODX 2.8.5 tot MODX 3.0.1. we have a issue regarding a custom snippet. In this snippet we are trying to render the filter based on tags installed from pages on a selected template.

After we tried to debug the snippet, we came to the conclusion that Tagger is not initiated/included on the line “if (!($tagger instanceof Tagger)) return ‘Tagger is not included’;”. The var dump above is showing boolean false. When i var dump on MODX 2.8.7 the boolean is giving true.

We checked the path of tagger, but we can’t find why Tagger is not included.

Code of the snippet:

<?php // Include Tagger service. $tagger = $modx->getService('tagger','Tagger',$modx->getOption('tagger.core_path',null,$modx->getOption('core_path').'components/tagger/').'model/tagger/', $scriptProperties); var_dump($tagger instanceof Tagger); if (!($tagger instanceof Tagger)) return 'Tagger is not included'; $id = $modx->resource->id; $parent = $modx->resource->parent; if ($parent !== 0) { $parent = $modx->getParentIds($parent, 1)[0]; $id = $parent; } $productsContainer = $modx->getObject('modResource', [ 'parent' => $id, 'class_key' => 'Collections\Model\CollectionContainer' ]); $categoryResource = $modx->getObject('modResource', $id); $groups = $modx->getCollection('TaggerGroup'); $output = ''; foreach ($groups as $group) { if (! in_array((int) $categoryResource->getTVValue('filterTemplate'), explode(',', $group->show_for_templates))) { continue; } $output .= $modx->getChunk('filterBlock', [ 'group_name' => $group->name, 'group' => $group->id, 'parent' => $productsContainer->id ]); } return $output;

In MODX 3, you have to add the namespace. The class Tagger is now Tagger\Tagger, TaggerGroup is Tagger\Model\TaggerGroup, etc.


Also, the way to access services in MODX has changed.
Tagger is added as a service here in the file bootstrap.php:

So in your code use $modx->services->get() instead of $modx->getService()