Two Drupal 8 Core Bugs: Found and Fixed

Two Drupal 8 Core Bugs: Found and Fixed

default avatar
Pensé parJesus Olivas
Octobre 30, 2014
FFW Blog - illustration

While working on the console project I have found (so far) two Drupal 8 core bugs. In this blog post I will explain how I found these bugs and what I have done to fix them.

First bug - Wrong service definition

I found the first one when adding a command for debugging registered services within the container.

Using the console command:

$ bin/console container:debug

Problem

The service definition for “controller.entityform” on "core/core.services.yml" file was wrong. The configured arguments injected are not expected for the class when creating a new instance of the object.

The "core.services.yml" is where all Drupal core services are defined.

Current declaration:

controller.entityform:
class: Drupal\Core\Entity\HtmlEntityFormController
arguments: ['@class_resolver', '@controller_resolver',
'@service_container', '@entity.manager']

More information about which services are registered on Drupal 8: https://api.drupal.org/api/drupal/core!core.services.yml/8

How to reproduce:

$this->getContainer()->get($serviceId);

The line of code used to reproduce the error is part of the console project. As you can see it is in the project repository. https://github.com/hechoendrupal/DrupalAppConsole/blob/0.2.15/src/Command/ContainerDebugCommand.php#L39

The get($id) method returns the object associated service form the container. Using the $id parameter as the service identifier. You can see the code on the Symfony Dependency Injection Component repository: https://github.com/symfony/symfony/blob/2.5/src/Symfony/Component/DependencyInjection/Container.php#L273

The following error was given:

Recoverable fatal error: Argument 1 passed to Drupal\Core\Entity\HtmlEntityFormController::__construct() must implement interface Drupal\Core\Controller\ControllerResolverInterface, instance of Drupal\Core\DependencyInjection\ClassResolver given in Drupal\Core\Entity\HtmlEntityFormController->__construct() (line 39 of core/lib/Drupal/Core/Entity/HtmlEntityFormController.php).

Proposed Resolution

Inject the proper arguments on the service definition. Based on the API documentation for the class HtmlEntityFormController:

https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Entity%21HtmlEntityFormController.php/class/HtmlEntityFormController/8

Service declaration should look like this:

controller.entityform:
class: Drupal\Core\Entity\HtmlEntityFormController
arguments: ['@controller_resolver', '@entity.manager', '@form_builder', NULL]

Even when the final resolution was to remove the service definition for “controller.entityform”. Running the console command helped me find this bug in Drupal 8 core and have it fixed.

More information on the issue page:

  • Name: Remove service definition for controller.entityform from core/core.services.yml
  • Link: https://www.drupal.org/node/2303823 - Closed (fixed)

Second Bug - Invalid Composer Version

I found this bug when installing the Console project

$ COMPOSER_BIN_DIR=bin composer require --dev drupal/console:@stable

Problem

I was not able to complete the installation because the PHP version required on "composer.json" file was not valid.

Current declaration:

require": {
"php": ">5.4.4-13",

How to Reproduce:

A) Running the installation process of Console project, but not everyone is using the console project, even when Larry Garfield AKA @Crell recommended it on Twitter after seeing my Drupal 8 Console Lightning Talk at DrupalCon Amsterdam.

The D8 console from @jmolivas looks even better than before! Every D8 developer should use it. #DrupalCon

— Larry Garfield (@Crell) October 2, 2014

B) Validate a composer file running the composer validate command. The composer documentation also recommends using this command.

“You should always run the validate command before you commit your composer.json file, and before you tag a release. It will check if your composer.json is valid.” https://getcomposer.org/doc/03-cli.md#validate

$ composer validate

After running the validate command, the following error was given:

./composer.json is invalid, the following errors/warnings were found: require.php : invalid version constraint (Could not parse version constraint >5.4.4-13: Invalid version string "5.4.4-13")

Proposed Resolution

Drupal 8 requires PHP 5.4.5 at least, the recommendation was to update the "composer.json" file as follows:

require": {
"php": ">=5.4.5",

This time the patch was accepted and the bug was fixed.

More information on the issue page:

  • Name: Composer require.php : invalid version constraint
  • Link: https://www.drupal.org/node/2354301 - Fixed