I thought we have a priority problem even leading to a fatal error, but i'm unsure now about the origin.
Related #1694480: Implement hook_module_implements() instead of relying on the module weight

In entity_translation_menu_alter() you're iterating over entity_get_info() where entity_translation_enabled().
Then you're setting $edit_item to NULL

     foreach ($et_info['path schemes'] as $scheme) {
        $translate_item = NULL;
        $edit_item = NULL;

Below you're doing unconditionally

          $original_item = $edit_item;
...
          $items["$edit_path/%entity_translation_language"] = array(
            'type' => MENU_DEFAULT_LOCAL_TASK,
...
          )
          // We need to inherit the remaining menu item keys, mostly 'module'
          // and 'file' to keep ajax callbacks working (see form_get_cache() and
          // drupal_retrieve_form()).
          + $original_item;

          // Add translation callback.
          $add_path = "$edit_path/add/%entity_translation_language/%entity_translation_language";
          $source_position = count($edit_path_parts) + 1;
          $target_position = count($edit_path_parts) + 2;
          $args = array($entity_type, $entity_position, $source_position, $target_position, $original_item);
          $items[$add_path] = array(
            'title callback' => 'Add translation',
...
          ) + $original_item;
        }

There are conditions (and i'm in one of them) where origina_item is still NULL. PHP explodes.

PHP Fatal error:  Unsupported operand types in /var/www/.../sites/all/modules/contrib/entity_translation/entity_translation.module on line 454
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

miro_dietiker’s picture

FileSize
924 bytes

Attaching a patch that tries to catch this ugly situation. Protection seems needed in entity_translation although the origin might be an unclean other module.

miro_dietiker’s picture

FileSize
959 bytes

Oopsie, better patch :-)

plach’s picture

Status: Active » Reviewed & tested by the community

Makes sense to me. Benedikt?

bforchhammer’s picture

Status: Reviewed & tested by the community » Postponed (maintainer needs more info)

Hm, we could use the provided patch for a quick fix, but I'm wondering whether there's actually something else going wrong... as far as I can see $edit_item (hence also $original_item) is always set in the following lines of code:

         do {
            $edit_item = &$items[implode('/', $edit_path_parts)];
            array_pop($edit_path_parts);
          }
          while (!empty($edit_item['type']) && $edit_item['type'] == MENU_DEFAULT_LOCAL_TASK);

The only case I see where this wouldn't be the case is if the respective menu item for the edit path doesn't exist. IMO that is something that should be taken care of during _entity_translation_validate_path_schemes()...

@miro_dietiker: I'm curious about the path/menu-item causing the error... could you try to find out the runtime values of $scheme, $edit_path_parts, and possibly $items for the item causing problems?

bforchhammer’s picture

miro_dietiker’s picture

Status: Postponed (maintainer needs more info) » Active

In my case this is NULL:
&$items[implode('/', $edit_path_parts)];
Because entity created
admin/config/services/sharemessage/manage/%entity_object/edit
and entity translation expects to see
admin/config/services/sharemessage/manage/%sharemessage/edit
And the loop immediately terminates.

If that missing "path wildcard" is the issue i don't see why entity_translation tries to query for "%sharemessage".

Yes it is related and that issue was the origin. However, there's no reason to produce a PHP fatal error in such an issue.

bforchhammer’s picture

If that missing "path wildcard" is the issue i don't see why entity_translation tries to query for "%sharemessage".

Well, that's just the default value; we need something to work with, so if you don't specify it then we try to guess it; core uses wildcards like %node or %user, so we use %[entity-type] as the default pattern.

So does adding a path wildcard solve this issue?

If yes, attached patch should help with avoiding the fatal error.

bforchhammer’s picture

Status: Active » Needs review

Setting NR.

plach’s picture

Status: Needs review » Needs work

I've been able to reproduce this, but #7 does not seem to fix the issue. To see the fatal just change the taxonomy base path from taxonomy/term/%taxonomy_term to taxonomy/term/%term. I think it's correct that this path passes validation because it's compatible with the actual one. The % replacement was introduced exactly to handle situations where the menu loader has been replaced but the router path structure remains the same. For instance when Views takes over the taxonomy/term/% path. We should make sure this works again as it's a regression wrt alpha2, I think.

plach’s picture

Issue tags: +Needs tests

tagging

plach’s picture

Status: Needs work » Needs review
FileSize
3.28 KB

I tried this with Views replacing taxonomy listings + a bougs base path ('taxonomy/term/%term') and things didn't break, except that the menu loader didn't exist and yielded to another fatal, but that's the expected behavior.

bforchhammer’s picture

Assigned: Unassigned » bforchhammer

I'm still not quite sure what the views-taxonomy thing actually means; I'll try to reproduce and confirm the patch now.

Also, it's a slightly different issue, but I'm still thinking that the stricter path wildcard validation (patch #5) also makes sense, because we need the path wildcard in the path in order to be able to determine the position of the entity id (we have code like $entity_position = array_search($wildcard, $path)).

plach’s picture

Actually Views doesn't break because it replaces only the base/view path, but if it replaced also the edit path we would have the same fatal reprted in the OP.

plach’s picture

Actually this is not a regression since replacing taxonomy listings with Views is still working. I'd like to release beta1 with this one fixed, but I won't consider this a blocker.

plach’s picture

Any news here?

bforchhammer’s picture

Here's a new patch based on the previous two.

I added the code from patch #7, because the way hook_menu_alter() is written at the moment, the existence of a matching wildcard is definitely required -- if we want to change that, we also need to adjust respective bits in hook_menu_alter().

+++ b/entity_translation.module
@@ -412,8 +419,8 @@ function entity_translation_menu_alter(&$items) {
+          $edit_path = $scheme['real edit path'];

I changed this back to 'edit path'. Mainly for consistency as we use the "non real" path for the other menu items as well; if there's a reason to use the real one instead we should probably document it and add some tests.

I also moved a few things around in the validation function in an attempt to make it easier to read through and understand (and to remove some duplicate code); added some comments as well.

Attached patch should still solve the issue of the OP, and also keep things working with the views-taxonomy listing.

bforchhammer’s picture

Assigned: bforchhammer » Unassigned
plach’s picture

Thanks!

@miro_dietiker:

Can you confirm the issue is fixed?

plach’s picture

Status: Needs review » Needs work

The bug is still there :(

I applied the patch, renamed the taxonomy base path from taxonomy/term/%taxonomy_term to taxonomy/term/%term and cleared the caches. Boom.

bforchhammer’s picture

Hm, there was a typo in a variable name. Also cleaned up some whitespace.

plach’s picture

Status: Needs review » Fixed

Looks good, fixes the issue and works with Views replacing taxonomy listings!

Committed and pushed, thanks!

miro_dietiker’s picture

Status: Fixed » Needs review

Much much better!
(But not perfect yet ;-) )

In addition i think for consistency, we should set the translation status to TRUE for all new nodes. not query for the node status.

Inconsistency example:
Compare case A
Create a node, unpublished
=> status of first translation is UNPUBLISHED
publish the node
=> status of first translation is PUBLISHED
unpublish the node
=> status of first translation is PUBLISHED

If we make the first translation record implicit, we rely on the node "published" state and we rely on the default (source) language.
I thus suggest to make this published as the source language is the initial reference.

The rest seems fine, test coverage is insufficient. Tests pass still without any change. :-)

miro_dietiker’s picture

FileSize
619 bytes

Hmm... where is my patch?!

plach’s picture

Er, wrong issue?

plach’s picture

Status: Needs review » Fixed

Automatically closed -- issue fixed for 2 weeks with no activity.

  • Commit 0741fbd on 7.x-1.x, et-permissions-1829630, factory, et-fc, revisions authored by bforchhammer, committed by plach:
    Issue #1818440 by bforchhammer, plach, miro_dietiker: Fixed Fatal error...

  • Commit 0741fbd on 7.x-1.x, et-permissions-1829630, factory, et-fc, revisions, workbench authored by bforchhammer, committed by plach:
    Issue #1818440 by bforchhammer, plach, miro_dietiker: Fixed Fatal error...