I'm writing a new module for the community and I have this error and I'm not understand what's going on.
The error:
Mensaje TypeError:
Drupal\view_mode_by_owner_role\Functors\ListOfNodeBundles::__construct():
Argument #1 ($config_factory) must be of type
Drupal\Core\Config\ConfigFactoryInterface, array given, called in
/var/www/html/web/core/lib/Drupal/Component/DependencyInjection/Container.php
on line 259 en
Drupal\view_mode_by_owner_role\Functors\ListOfNodeBundles->__construct()
(línea 20 de
/var/www/html/web/modules/custom/view_mode_by_owner_role/src/Functors/ListOfNodeBundles.php)
My functor class:
<?php
namespace Drupal\view_mode_by_owner_role\Functors;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
final class ListOfNodeBundles implements ContainerInjectionInterface {
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
public function __construct(ConfigFactoryInterface $config_factory, EntityTypeManagerInterface $entity_type_manager, ){
$this->view_mode_by_onwer_role = $config_factory->get('view_mode_by_owner_role.settings');
$this->entityTypeManager = $entity_type_manager;
}
public static function create (ContainerInterface $container){
return new static (
$container->get('config.factory'),
$container->get('entity_type.manager'),
);
}
public function __invoke(): array {
$nodes = $this->entityTypeManager->getStorage('node_type')->loadMultiple();
$bundle_list = [];
foreach ($nodes as $bundle) {
$bundle_list[$bundle->id()] = $bundle->label();
}
return $bundle_list;
}
}
My service.yml
services:
view_mode_by_owner_role.functors_list_of_node_bundles:
class: Drupal\view_mode_by_owner_role\Functors\ListOfNodeBundles
arguments:
- ['@config.factory', '@entity_type.manager']
And How I try to implement in a form:
<?php
namespace Drupal\view_mode_by_owner_role\Form;
use Drupal\view_mode_by_owner_role\Form\BasicSettingsForm;
use Drupal\Core\Form\FormStateInterface;
use Drupal\view_mode_by_owner_role\Functors\ListOfNodeBundles;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Configure View mode by owner role settings for this site.
*/
class SettingsChooseRoleForm extends BasicSettingsForm {
/**
* @var \Drupal\view_mode_by_owner_role\Functors\ListOfNodeBundles
*/
private $listOfNodeBundles;
public function __construct(ListOfNodeBundles $list_of_nodes_bundles){
parent::__construct($config_factory);
$this->listOfNodeBundles = $list_of_nodes_bundles;
}
public static function create(ContainerInterface $container){
return new static(
$container->get('view_mode_by_owner_role.functors_list_of_node_bundles'),
);
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'view_mode_by_owner_role_settings_choosed_roles';
}
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return ['view_mode_by_owner_role.settings'];
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$listado = $this->listOfNodeBundles;
$role_list = $this->listOfRoles();
$config = $this->config('view_mode_by_owner_role.settings');
$form['choosed_roles'] = [
'#required' => TRUE,
'#type' => 'checkboxes',
'#options' => $role_list,
'#title' => $this->t('Role list'),
'#default_value' => $config->get('choosed_roles')
];
// Add a submit button that handles the submission of the form.
$form['actions']['submit'] = [
'#type' => 'submit',
'#value' => $this->t('Submit'),
'#description' => $this->t('Submit'),
];
return $form;
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$config = $this->config('view_mode_by_owner_role.settings')
->set('choosed_roles', array_filter($form_state->getValue('choosed_roles')))
->save();
parent::submitForm($form, $form_state);
}
}
I have read some questions, but I don't understand why I have this error.