I am using composer for managing dependencies in my drupal module. I specified my dependency in the composer.json file placed in my module's root directory. After running the composer install
comand it installs all the dependencies correctly; however, the autoloading does not seem to work.
I have checked several threads here that deal with the problem and found that most of them suggest using the composer manager module that's available even though on the module's page on drupal.org it says that it's deprecated due to Drupal's improved use of composer since version 8.1
Here's my composer.json file in my module's root diretory:
{
"name": "activit/facebook_ratings",
"description": "Display a feed of your Facebook fanpage's ratings on your website.",
"type": "drupal-module",
"require": {
"facebook/graph-sdk": "^5.4"
},
"license": "MIT",
"authors": [
{
"name": "Robert Balasko",
"email": "[email protected]"
}
]
}
and a factory class in the root of src directory that tries to load a class from the graph-sdk.
<?php namespace Drupal\facebook_ratings;
use Drupal\Core\Logger\LoggerChannelFactoryInterface;
use Facebook\Facebook;
class FacebookConnectorFactory {
private $logger_factory;
public function __construct(LoggerChannelFactoryInterface $logger_factory) {
$this->logger_factory = $logger_factory;
}
public function getFacebookService($app_id, $app_secret) {
if (!$app_id || !$app_secret) {
$this->logger_factory
->get('facebook_ratings')
->error('Undefined App ID or App secret');
return FALSE;
}
return new Facebook([
'app_id' => $app_id,
'app_secret' => $app_secret,
'default_graph_version' => 'v2.6',
]);
}
}
The result is a class not found
error when I run my code. Shouldn't the dependency be autoloaded or am I doing anything wrong?
Thanks a lot.