Problem/Motivation

Unable to create New Content Types on a fresh drupal site which is installed using a Minimal Installation Profile.

Fatal error: Call to a member function setDefaultLangcode() on a non-object in /home/s239c0a1a65252cc/www/core/modules/language/language.module on line 218

Screenshot :

Screen capture that reproduces this error : http://youtu.be/ESTa2xbo-VI

Proposed resolution

Remaining tasks

  • Identify the which causes the bug
  • Create a Patch
  • Commit it

the

User interface changes

None

API changes

Language Module

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

lahoosascoots’s picture

Stack Trace:

Fatal error: Call to a member function setDefaultLangcode() on a non-object in /Users/matthew.lucasiewicz/src/beta_test/core/modules/language/language.module on line 218 Call Stack: 0.0002 252392 1. {main}() /Users/matthew.lucasiewicz/src/beta_test/index.php:0 0.0111 1675248 2. Drupal\Core\DrupalKernel->handle() /Users/matthew.lucasiewicz/src/beta_test/index.php:24 0.0344 4158144 3. Stack\StackedHttpKernel->handle() /Users/matthew.lucasiewicz/src/beta_test/core/lib/Drupal/Core/DrupalKernel.php:565 0.0344 4158192 4. Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle() /Users/matthew.lucasiewicz/src/beta_test/core/vendor/stack/builder/src/Stack/StackedHttpKernel.php:23 0.0344 4158400 5. Drupal\Core\StackMiddleware\PageCache->handle() /Users/matthew.lucasiewicz/src/beta_test/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php:58 0.0484 5359912 6. Drupal\Core\StackMiddleware\PageCache->pass() /Users/matthew.lucasiewicz/src/beta_test/core/lib/Drupal/Core/StackMiddleware/PageCache.php:105 0.0484 5359960 7. Drupal\Core\StackMiddleware\KernelPreHandle->handle() /Users/matthew.lucasiewicz/src/beta_test/core/lib/Drupal/Core/StackMiddleware/PageCache.php:126 0.0693 8338232 8. Symfony\Component\HttpKernel\HttpKernel->handle() /Users/matthew.lucasiewicz/src/beta_test/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php:53 0.0693 8338312 9. Symfony\Component\HttpKernel\HttpKernel->handleRaw() /Users/matthew.lucasiewicz/src/beta_test/core/vendor/symfony/http-kernel/Symfony/Component/HttpKernel/HttpKernel.php:66 0.1456 14487696 10. call_user_func_array() /Users/matthew.lucasiewicz/src/beta_test/core/vendor/symfony/http-kernel/Symfony/Component/HttpKernel/HttpKernel.php:145 0.1456 14488120 11. Drupal\Core\Controller\FormController->getContentResult() /Users/matthew.lucasiewicz/src/beta_test/core/vendor/symfony/http-kernel/Symfony/Component/HttpKernel/HttpKernel.php:145 0.1579 16344368 12. Drupal\Core\Form\FormBuilder->buildForm() /Users/matthew.lucasiewicz/src/beta_test/core/lib/Drupal/Core/Controller/FormController.php:79 0.2264 22101360 13. Drupal\Core\Form\FormBuilder->processForm() /Users/matthew.lucasiewicz/src/beta_test/core/lib/Drupal/Core/Form/FormBuilder.php:247 0.2438 22876184 14. Drupal\Core\Form\FormSubmitter->doSubmitForm() /Users/matthew.lucasiewicz/src/beta_test/core/lib/Drupal/Core/Form/FormBuilder.php:481 0.2438 22876392 15. Drupal\Core\Form\FormSubmitter->executeSubmitHandlers() /Users/matthew.lucasiewicz/src/beta_test/core/lib/Drupal/Core/Form/FormSubmitter.php:56 0.4404 27478680 16. call_user_func_array() /Users/matthew.lucasiewicz/src/beta_test/core/lib/Drupal/Core/Form/FormSubmitter.php:116 0.4404 27478760 17. language_configuration_element_submit() /Users/matthew.lucasiewicz/src/beta_test/core/lib/Drupal/Core/Form/FormSubmitter.php:116

lahoosascoots’s picture

So the Fatal is being thrown in language.module inside language_configuration_element_submit()

<?php
$bundle = $values['bundle'];
$form_object = $form_state->getFormObject();
if ($form_object instanceof EntityFormInterface && !$form_object->getEntity()->isNew() && in_array($form_object->getOperation(), ['default', 'edit'])) {
  /** @var EntityFormInterface $form_object */
  $entity = $form_object->getEntity();
  if ($entity->getEntityType()->getBundleOf()) {
    $bundle = $entity->id();
  }
}
$config = ContentLanguageSettings::loadByEntityTypeBundle($entity_type_id, $bundle);
$config->setDefaultLangcode($form_state->getValue(array($element_name, 'langcode')));
?>

$values['bundle'] is coming back NULL. loadByEntityTypeBundle returns NULL if $entity_type_id or $bundle is NULL thus making $config NULL which causes the fatal when we try to setDefaultLangcode().

I tried to tap into the same process on a standard install instead of minimal and language_configuration_element_submit doesn't seem to be called calling field_ui_form_node_type_form_submit instead, which is confirmed by tapping into the submit handlers of the form.

lahoosascoots’s picture

Disabling Field UI removes the field_ui_form_node_type_form_submit handler and adds in the language_configuration_element_submit.

lahoosascoots’s picture

Disabling Field UI also introduces the error.

lahoosascoots’s picture

So it looks like the save handler in core/modules/node/src/NodeTypeForm.php doesn't go back and update the bundle name in the language configuration in form_state after the content type is created caused the language module to get a null value for the bundle.

This patch fixes the issue. Whether it is correctly done or not and in the the right place? I'll need some extra eyes.

lahoosascoots’s picture

Status: Active » Needs review
dawehner’s picture

Issue tags: +Needs tests

It would be nice to have tests for this bug!

rpayanm’s picture

Version: 8.0.0-beta6 » 8.0.x-dev
Issue tags: +D8MI
rpayanm’s picture

Status: Needs review » Closed (duplicate)