Iam currently evaluating a switch to drupal commerce for Drupal 7. When installing the dependencies and attempting a basic setup I encountered the following error:
Fatal error: Call to undefined function entity_language() in /home/jpluijmers/projects/sites-drupal-7.8/mysite.x/modules/commerce/modules/product/includes/commerce_product.forms.inc on line 43 Call Stack: 0.0001 56420 1. {main}() /home/jpluijmers/libraries/drupal-7.8/index.php:0 0.0674 14547024 2. menu_execute_active_handler() /home/jpluijmers/libraries/drupal-7.8/index.php:21 0.0676 14563544 3. call_user_func_array() /home/jpluijmers/libraries/drupal-7.8/includes/menu.inc:516 0.0676 14563856 4. commerce_product_ui_product_form_wrapper() /home/jpluijmers/libraries/drupal-7.8/includes/menu.inc:516 0.0679 14618152 5. drupal_get_form() /home/jpluijmers/projects/sites-drupal-7.8/mysite.x/modules/commerce/modules/product/includes/commerce_product_ui.products.inc:66 0.0679 14618816 6. drupal_build_form() /home/jpluijmers/libraries/drupal-7.8/includes/form.inc:131 0.0679 14620420 7. drupal_retrieve_form() /home/jpluijmers/libraries/drupal-7.8/includes/form.inc:339 0.0682 14623808 8. call_user_func_array() /home/jpluijmers/libraries/drupal-7.8/includes/form.inc:795 0.0682 14624200 9. commerce_product_product_form() /home/jpluijmers/libraries/drupal-7.8/includes/form.inc:795
When adding a product (/admin/commerce/products/add/product).
When I investigated the issue I found out that the entity_language function was only added to the core's common.inc after 7.15, while I am not that far out of date with 7.14.
Comments
Comment #1
joostpluijmers commentedcommerce_product.forms.inc:43 is the only reference to entity_language() that I could find.
Comment #2
joostpluijmers commentedI have confirmed that upgrading to 7.15 and above fixes this issue.
Comment #3
jsolanaGBT commentedThis error comes when missing entity_language method in includes/common.inc file.
For me it was solved just adding this method after the archiver_get_info() method:
Comment #4
joshmillerLinked to this post from http://www.drupalcommerce.org/discussions/4627/error-message-language-af...
Bojanz was nudged on this issue from within IRC and had this to say...
jostie: there is one reference in the bundled product module
As far as i could find thats the only one.
And I don't use kickstart for site creation
I don't know the core update policies all that well, but isnt te core api supposed to be locked after release?
bojanz: no. API additions are allowed
you're right, we added entity_language() to Commerce, so a note on the project page should be fine
there was a security release after 7.15 anyway, so everyone should have updated anyway (otherwise entity_language is the least of their problems)
Comment #5
damien tournoud commentedUpdated the project page and the release node.
Comment #6
rszrama commentedReprioritizing this as Bojan is right - with security updates, people should be updating, but it is a feasible update strategy to only patch the security holes. That said, there isn't a great way to declare core Drupal version dependencies - the only solution involves breaking sites that may be deployed from Git or Drupal 7.x-dev. The release notes for Commerce 1.4 are still forthcoming, so I'll be sure to document the requirement there - we had another one for hook_field_widget_form_alter() anyways.
If we really want to support earlier versions, we can revert that line from using entity_language() to $product->language, but I'm not sure we really want to support versions of Drupal the pre-exist security releases. We can discuss further.
Comment #7
joostpluijmers commentedI manage, build and support drupal websites for a living. And since clients wont upgrade websites for themselves this falls to me. When doing my upgrade rounds, I make the distinction between function and security. Security gets updates and function doesn't. This is the case for a lot of companies managing large amount of sites because function upgrades may break the website.
Comment #8
bojanz commentedOf course we don't want to support Drupal versions from before security releases.
As I said a few days ago, I think it would be fine to declare a specific dependency on a Drupal core version (so > 15 or something like that).
We've always had it (7.2, then 7.4 then 7.8 if memory serves me), but it was never explicitly defined.
Sure, it will cause problems for people using Drupal core straight out of git, but I think those cases are very rare today.
Comment #9
joostpluijmers commentedTo force users to be on "the bleeding edge" is fine for people managing their own (single) site. For commercial users, this will in most cases not be acceptable since upgrading in some cases isn't easy and especially in web shops where money is directly involved. So I say less dependencies => less documenting, less problems. But of course the last say goes to the programmers.
Comment #10
bojanz commentedWeb shops where money is involved don't want to have well known and publicized security holes either, so your point is moot. The last security release will always be an acceptable minimal dependency.
Comment #11
joostpluijmers commentedI don't think iam getting my point over very well. So at the risk of regressing: there is (and should be) a big difference between patching security and upgrading your entire system. With that said, I look forward to using commerce in the future, its a great improvement!
Comment #12
Abhinesh Sharma commentedHi
It's Drupal version problem . entity_language function not use in some low level drupal version like Drupal 7.13.
If you use Drupal 7.16 then function entity_language($entity_type, $entity) by default in includes/common.inc file. but Drupal 7.13 version module missing entity_language method in includes/common.inc file.
So add below function for includes/common.inc file after function entity_label
/**
* Returns the language of an entity.
*
* @param $entity_type
* The entity type; e.g., 'node' or 'user'.
* @param $entity
* The entity for which to get the language.
*
* @return
* A valid language code or NULL if the entity has no language support.
*/
function entity_language($entity_type, $entity) {
$info = entity_get_info($entity_type);
// Invoke the callback to get the language. If there is no callback, try to
// get it from a property of the entity, otherwise NULL.
if (isset($info['language callback']) && function_exists($info['language callback'])) {
$langcode = $info['language callback']($entity_type, $entity);
}
elseif (!empty($info['entity keys']['language']) && isset($entity->{$info['entity keys']['language']})) {
$langcode = $entity->{$info['entity keys']['language']};
}
else {
// The value returned in D8 would be LANGUAGE_NONE, we cannot use it here to
// preserve backward compatibility. In fact this function has been
// introduced very late in the D7 life cycle, mainly as the proper default
// for field_attach_form(). By returning LANGUAGE_NONE when no language
// information is available, we would introduce a potentially BC-breaking
// API change, since field_attach_form() defaults to the default language
// instead of LANGUAGE_NONE. Moreover this allows us to distinguish between
// entities that have no language specified from ones that do not have
// language support at all.
$langcode = NULL;
}
return $langcode;
}
Then above fetal error will not come in drupal commerce
Comment #13
joostpluijmers commented@Abhinesh Sharma I find that its the best policy to refrain from altering Drupal core directly, since it could break updates in the future.
Comment #14
rszrama commentedThe release notes and project page have been updated to indicate the dependency.
Comment #16
Abhinesh Sharma commented@joostpluijmers No problem if you update drupal in future then this functions are available in drupal latest version.