I am trying to access a static method of a controller class from a module, but my code doesn't work.
This is the controller class.
namespace Drupal\content_statistics\Controller;
use Drupal\Core\Controller\ControllerBase;
class ContentStatisticsCount extends ControllerBase {
public static contentStatisticsCount() {
$value = $this->t('hi');
return $value;
}
}
This is the module code.
use Drupal\Core\Controller\ControllerBase;
use Drupal\content_statistics\Controller;
/**
* Implements hook_node_view().
*/
function content_statistics_node_view($node, $display, $view_mode, $langcode) {
$value = ContentStatisticsCount::contentStatisticsCount();
print_r($value);
die;
}
This is giving me the following PHP error:
PHP Fatal error: Class 'ContentStatisticsCount' not found in /home/qbuser/Projects/test/modules/custom/content_statistics/content_statistics.module on line 15
use Drupal\content_statistics\Controller;
needs to beuse Drupal\content_statistics\Controller\ContentStatisticsCount
;