Updated: Comment #58
Problem/Motivation
The problem is caused when the language defaults for any content type is missing. Any entity that is created programmatically will not set the default language.
Steps to replicate
- Create a new content type.
- Specify the machine name for content type.
- Choose default language as Not Specified from language settings tabs.
- Programatically try to create the entity, the default language will be missing
Proposed resolution
- The correct place to set the default language for EntityNG would be LanguageItem::applyDefault().
- The easiest way would be a if language module exists check there
- if module exists then set language code from the entity using language_get_default_langcode else it will set the language code to LANGCODE_NOT_SPECIFIED.
- There is a possibilty of function setValue is getting moved into the language manager service defined under core/lib/Drupal/Core/Entity/Plugin/DataType/LanguageItem.php
Remaining tasks
- The patch is ready for review.
- also #122 needs addresses.
Related Issues
http://drupal.org/node/1869562#comment-7280616.
Original report by @fago
I just ran into a problem caused by language defaults missing, see http://drupal.org/node/1869562#comment-7280616.
I think that language module should use hook_entity_create() to set the default language, that way any programmatically created entity will get the usual defaults as well.