Fatal error: Class name must be a valid object or a string in (...)/sites/all/modules/entity_translation/entity_translation.module on line 495

This happens when I try to translate some content baseUrl/fr/node/3/translate

I'm investigating the cause of this issue. My first lead is that I use auto_nodetitle but I don't know yet what's causing this.
I could also be my synchronise translation settings, I don't know yet. If someone has the same error, please describe what you did. This is not coming by itself out of the box.

the actual line 495:
$handler = new $class($entity_type, $entity_info, $entity, $entity_id);

Comments

Jerome F’s picture

There's a bunch of other errors coming along with this one on every page in a non default language, (once you switch to english it's gone, you can then go back to your foreign language with no error displayed, but when you check for updates in admin/reports/updates for example or after cache flush, it's displayed again):

Warning : Missing argument 2 for entity_translation_overview() dans entity_translation_overview() (ligne 55 dans (...)/sites/all/modules/entity_translation/entity_translation.admin.inc).
Notice : Undefined variable: entity dans entity_translation_overview() (ligne 57 dans (...)/sites/all/modules/entity_translation/entity_translation.admin.inc).
Notice : Undefined variable: entity dans entity_translation_overview() (ligne 68 dans (...)/sites/all/modules/entity_translation/entity_translation.admin.inc).
Warning : Illegal offset type in isset or empty dans entity_get_info() (ligne 7333 dans (...)/includes/common.inc).
Jerome F’s picture

What's the status of this module is there overlapping between internationalisation's content translation that can cause that kind of errors?

plach’s picture

There should not be, if there is we must fix it. The intended behavior is that the translation overview page for any entity is provided only if the /translate path is not already "taken" by i18n.

Jerome F’s picture

Status: Postponed (maintainer needs more info) » Active

Thank you for your answer @plach.
I tried to uninstall entity translation - internationalisation content translation works. So there is an issue causing the fatal error with entity translation. I still have to test if that's not because I use auto_nodetitle and/or because I miss title module is missing (but if that's the cause, title should be mandatory imo).

plach’s picture

Status: Active » Postponed (maintainer needs more info)

Can you describe your setup and how to reproduce the issue? Is enabling ET + i18n enough or do you performed some particular configuration?

Jerome F’s picture

Status: Active » Postponed (maintainer needs more info)

As soon as I can reproduce this on a simple test site I let you know, thank you.

Jerome F’s picture

I can say that the lead about automatic node title is the wrong one. In a test environment, there's no problem with it. So I will look at Node location module which might be untranslatable by entity translation. EDIT: location is not the problem.
It's Multilingual content module OR translation overview module which needs to be disabled in my installation, but I still can't reproduce this in my test site.

Jerome F’s picture

Status: Postponed (maintainer needs more info) » Active

Here it is !

To reproduce these errors, enable :

  • Translation overview
  • Entity translation
  • Internationalization
  • Multilingual content

generate content and try to translate it

plach’s picture

Module versions? ;)

Jerome F’s picture

Drupal core 7.2
Entity translation 7.x-1.x-dev (2011-May-25)
Internationalization 7.x-1.0-beta6
Translation Overview 7.x-2.0-beta1
Variable 7.x-1.0

omercioglu’s picture

I can confirm that enabling Translation Overview 7.x-2.0-beta1 is causing this problem, in my case.

webmestre’s picture

Disabling this module does the translation possible again.
Nothing better when installing the 7.x-2.x-dev version !

mvc’s picture

I have this problem too. On the next page load I get the following error messages which I believe are related:

Warning: Missing argument 2 for entity_translation_overview() in entity_translation_overview() (line 55 of /home/mvc/Work/sprint/entity_translation/entity_translation.admin.inc).
Notice: Undefined variable: entity in entity_translation_overview() (line 57 of /home/mvc/Work/sprint/entity_translation/entity_translation.admin.inc).
Notice: Undefined variable: entity in entity_translation_overview() (line 68 of /home/mvc/Work/sprint/entity_translation/entity_translation.admin.inc).
Warning: Illegal offset type in isset or empty in entity_get_info() (line 7351 of /home/mvc/Work/sprint/drupal/includes/common.inc).
Warning: Illegal offset type in isset or empty in entity_get_info() (line 7351 of /home/mvc/Work/sprint/drupal/includes/common.inc).
djac’s picture

Status: Active » Closed (duplicate)
Issue tags: +montreal

Reproduced with:

Drupal core 7.8
Entity translation 7.x-1.0-alpha1
Internationalization 7.x-1.0
Multilingual content (must be enabled to reproduce this error)
Translation Overview 7.x-2.0-beta1
Variable 7.x-1.1

The error is a result of conflicts between i18n_node, entity_translation and translation_overview. All 3 modules are implementing hook_form_alter and modifying the entry for 'node/%node/translate'.

I believe this issue should be fixed by #1172530: No way to assign existing nodes as translations with i18n_node, thus closing this issue as a duplicate.

djac’s picture

Status: Closed (duplicate) » Active

We may be able to fix this in entity_translation. Re-opening for further investigation.

djac’s picture

Status: Active » Needs review
StatusFileSize
new2.94 KB

Here's a first attempt at a patch which calls the appropriate callback after hook_menu and hook_menu_alter hooks run.

We may want to improve the filename handling. I'm not sure if the extension will always be .inc. Perhaps someone can comment.

plach’s picture

Status: Needs review » Needs work

Thanks!

+++ b/entity_translation.admin.inc
@@ -167,6 +160,17 @@ function entity_translation_overview($entity_type, $entity) {
+    $file_basename = basename($callback['file'], '.inc');
+    module_load_include('inc', $callback['module'], $file_basename);

I think these lines can be replaced with something like the following:

<?php
if (isset($callback['file'])) {
  $path = isset($callback['file path']) ? $callback['file path'] : drupal_get_path('module', $callback['module']);
  include_once DRUPAL_ROOT . '/' . $path . '/' . $callback['file'];
}
?>

See the related docs.

djac’s picture

Status: Needs work » Needs review
StatusFileSize
new3.11 KB

Thanks plach.

I've attached a second attempt.

plach’s picture

Status: Needs review » Needs work
+++ b/entity_translation.admin.inc
@@ -167,6 +160,22 @@ function entity_translation_overview($entity_type, $entity) {
+      $file = DRUPAL_ROOT . '/' . $path . '/' . $callback['file'];
+      if (is_file($file)) {
+        require_once $file;
+      }

I know this is how module_load_include(), does but I'd say this code triggers two I/O operations instead of one. What about the following?

<?php
@include_once DRUPAL_ROOT . '/' . $path . '/' . $callback['file'];
?>

After all avoiding to issue an error here is pretty useless since the execution is likely to terminate immediately after due to a fatal, since the page callback cannot be found.

djac’s picture

Status: Needs work » Needs review
StatusFileSize
new3.05 KB

Sounds good! I've attached another patch.

plach’s picture

Title: Fatal error: Class name must be a valid object or a string in (...)/entity_translation.module on line 495 » Properly override the node/%node/translate menu router path
Category: bug » task
StatusFileSize
new6.06 KB

@djac:

Sorry for the delayed feedback, but this revealed trickier than what I originally thought to address: I tested your patch with core content translation and it appeared not to work. The main reason is that by implementing hook_menu() we are not able to backup an existing node/%node/translate router path, since there is no way to tell if it's there, and we simply override it with the ET router path. To address this problem I moved everything to hook_menu_alter(). Moreover access callbacks were not proxied.

I tested the attached patch with core content translation and it seems to behave well. Would you please test it with i18n_node and translation_overview and report?

renat’s picture

Hello!
After applying the path against -dev version of Entity Translation, I received this error message:

Warning: require_once(/var/www/sky37.pp.ua/public_html//entity_translation.admin.inc) [function.require-once]: failed to open stream: No such file or directory in menu_execute_active_handler() (line 501 of /var/www/sky37.pp.ua/public_html/includes/menu.inc).

Obviously there should be public_html/SITES/ALL/MODULES/entity_translation.admin.inc, not public_html//entity_translation.admin.inc

plach’s picture

@djac:

Aside from #22, do you have anything else to report?

Status: Needs review » Needs work

The last submitted patch, et-1174242-21.patch, failed testing.

stevieb’s picture

Translation Overview 7.x-2.0-beta1 also caused the problem in my case

good_man’s picture

Status: Needs work » Needs review
StatusFileSize
new6.25 KB

The patch missed one thing which is the 'module' key, otherwise drupal will assume the file is in drupal root dir. After applying the patch, no error messages anymore. Now let's see how testbot will react.

good_man’s picture

One little effect, after changing the way you do menus in this module, other modules depending on it, like Translation Overview, needs an update, otherwise it won't work after applying this patch.

renat’s picture

Patch from #26 works fine for me. But I did not experienced any problems without it, so my result is not significant.

webcultist’s picture

#26 seems to work for me, too.
Thanks

plach’s picture

@good-man:

Thanks for working on this. The goal of the patch is to avoid the need for other modules to worry about ET, hence, unless I'm missing something, there should be no need to warn their maintainers.

good_man’s picture

StatusFileSize
new6.29 KB

I missed one 'module' key for the config page of ET (admin/config/regional/entity_translation) otherwise it'll display that fatal require_once error.

Re. Translation Overview, it's menu_alter() is executed before ET, therefore, ET will overwrite the previous TO path. Quoted from OT code:

function translation_overview_menu_alter(&$items) {
  // Replace the translation module's node tab with our own.
  // @todo this conflicts i18n_node and entity_translation

So I think that it's now up to them to solve this @todo.

plach’s picture

Status: Needs review » Fixed

The patch looks good, tests pass and I manually tested core node translation, i18n_node and translation overview successfully.

Thanks to everyone working on this! Committed to HEAD.

dhinakaran’s picture

Status: Fixed » Needs review

#31: et-1174242-31.patch queued for re-testing.

plach’s picture

Status: Needs review » Closed (fixed)

The patch has been committed. No point in retesting it.

batigol’s picture

Fatal error: Class name must be a valid object or a string in /home/prouser/drupal/sites/all/modules/entity_translation/entity_translation.module on line 495

with latest dev:
Warning: call_user_func_array() expects parameter 1 to be a valid callback, no array or string given in entity_translation_node_tab_access() (line 72 of \modules\entity_translation\entity_translation.node.inc).

with alpha-1:

Warning: Missing argument 2 for entity_translation_overview() in entity_translation_overview() (line 55 of /drupal/sites/all/modules/entity_translation/entity_translation.admin.inc).
Notice: Undefined variable: entity in entity_translation_overview() (line 57 of /drupal/sites/all/modules/entity_translation/entity_translation.admin.inc).
Notice: Undefined variable: entity in entity_translation_overview() (line 68 of /drupal/sites/all/modules/entity_translation/entity_translation.admin.inc).
Warning: Illegal offset type in isset or empty in entity_get_info() (line 7463 of /drupal/includes/common.inc).
Warning: Illegal offset type in isset or empty in entity_get_info() (line 7463 of /drupal/includes/common.inc).
plach’s picture

Please open a new issue.

int_ua’s picture

Was it ever opened?

Update: Component was changed automatically due to "Code" not being available anymore.

int_ua’s picture

Component: Code » Base system
fxarte’s picture

In my case, I got it working by enabling node entity in the config page: /admin/config/regional/entity_translation. For some reason taxonomy terms was the only entity type enabled. Version 7.x-1.0-alpha1
Thanks

  • Commit c52b590 on master, et-permissions-1829630, factory, et-fc, revisions authored by djac, committed by plach:
    Issue #1174242 by djac, good_man, plach | Jerome F: Properly override...

  • Commit c52b590 on master, et-permissions-1829630, factory, et-fc, revisions, workbench authored by djac, committed by plach:
    Issue #1174242 by djac, good_man, plach | Jerome F: Properly override...