Score:0

Argument 6 passed to Drupal\layout_builder\Plugin\Block\InlineBlock::__construct() must implement interface

cn flag

I was upgrading Drupal 8 to 9. I installed 'Upgrade Status' module and fixed as suggested by it. Now it was time to upgrade to D9. I changed on composer.json.

"drupal/core-composer-scaffold": "^8.9.0",
"drupal/core-recommended": "^8.9.0",

To

"drupal/core-composer-scaffold": "^9.1.0",
"drupal/core-recommended": "^9.1.0",

Then ran following command:

composer update
drush cr
drush updb -y

After running the update, I got the Drupal 9.2.6. When browsing the URL, it showed following error:

TypeError: Argument 6 passed to Drupal\layout_builder\Plugin\Block\InlineBlock::__construct() must implement interface Drupal\Core\Session\AccountInterface, instance of Drupal\Core\Logger\LoggerChannel given, called in /app/web/core/modules/layout_builder/src/Plugin/Block/InlineBlock.php on line 117 in Drupal\layout_builder\Plugin\Block\InlineBlock->__construct() (line 95 of core/modules/layout_builder/src/Plugin/Block/InlineBlock.php).

I googled but could not find out the solution. Any suggestion is really appreciated.

Score:-2
cn flag

It's due to parameters in the constructor

public function __construct(){}

replace

public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager, EntityDisplayRepositoryInterface $entity_display_repository, AccountInterface $current_user){}

with

public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager, EntityDisplayRepositoryInterface $entity_display_repository, LoggerInterface $logger, AccountInterface $current_user = NULL) {}

The changes are: LoggerInterface $logger and AccountInterface $current_user = NULL in the constructor.

During Drupal upgrade to 9, you will see a file InlineBlock.php.rej (core/modules/layout_builder/src/Plugin/Block/InlineBlock.php.rej) which provides detail to fix the issue.

JFI: I did the change directly to the InlineBlock.php, please suggest if there is an alternative way to patch it.

InlineBlock.php.rej file contains:

***************
*** 81,90 ****
     *   The entity type manager service.
     * @param \Drupal\Core\Entity\EntityDisplayRepositoryInterface $entity_display_repository
     *   The entity display repository.
     * @param \Drupal\Core\Session\AccountInterface $current_user
     *   The current user.
     */
-   public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager, EntityDisplayRepositoryInterface $entity_display_repository, AccountInterface $current_user = NULL) {
      parent::__construct($configuration, $plugin_id, $plugin_definition);
  
      $this->entityTypeManager = $entity_type_manager;
--- 89,100 ----
     *   The entity type manager service.
     * @param \Drupal\Core\Entity\EntityDisplayRepositoryInterface $entity_display_repository
     *   The entity display repository.
+    * @param \Psr\Log\LoggerInterface $logger
+    *   A logger instance.
     * @param \Drupal\Core\Session\AccountInterface $current_user
     *   The current user.
     */
+   public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager, EntityDisplayRepositoryInterface $entity_display_repository, LoggerInterface $logger, AccountInterface $current_user = NULL) {
      parent::__construct($configuration, $plugin_id, $plugin_definition);
  
      $this->entityTypeManager = $entity_type_manager;
***************
*** 98,103 ****
        $current_user = \Drupal::currentUser();
      }
      $this->currentUser = $current_user;
    }
  
    /**
--- 108,118 ----
        $current_user = \Drupal::currentUser();
      }
      $this->currentUser = $current_user;
+     if (!$logger) {
+       @trigger_error('The logger service must be passed to InlineBlock::__construct(). It was added in drupal:9.2.0 and will be required before drupal:10.0.0.', E_USER_DEPRECATED);
+       $logger = \Drupal::service('logger.channel.layout_builder');
+     }
+     $this->logger = $logger;
    }
  
    /**
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.