I'm building a site that has rather large content types that produce nodes with multiple field collections. The site is multilingual and our translators prefer to make their translations by clicking on the "Edit" link for each Field collection item rather than translating the entire node all at once. The problem is, every time they save the Field Collection item, it seems to turn on the "Generate automatic URL alias" setting for the node and changes the URL. We need to keep the URLs as they are in English so this bug is preventing us from using the "Edit" feature of the individual items.

Is there a solution? Thanks.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jaydee1818’s picture

Issue summary: View changes

typo fix

mawint’s picture

Issue summary: View changes

This is also an issue with version 7.x-1.0-beta7.

Just upgraded and still having this issue.

I have not found a solution yet though.

mawint’s picture

FileSize
1.73 KB

I hope I did this right since this is the first time I have done this.

In the save function for field collections, just before entity_save I added the path auto function to ignore resetting the url.

jmuzz’s picture

Patch files should contain the output of a 'git diff' command so we can see exactly what changed. Please see https://www.drupal.org/node/707484 for details.

mawint’s picture

Thanks for the link, does this work?

jaydee1818’s picture

I was able to successfully apply the patch.

I tested by going to an English node, and switching to Japanese via our language selector. In the Japanese node, I edited one of the Field Collection items and saved. It successfully updated the item without altering the node url. However, the Japanese node seemed to lose its relationship to the English version (and other languages).

After the initial save, the language selector was set to English, even though the node was definitely in the Japanese node. If I returned to the English node by removing the "ja" identifier from the url, Japanese was no longer listed as an option to change to. I could return by re-adding the "ja" to the url, but as I said, it seems the link has been severed.

This patch may be on the right track, but not the final solution I'm afraid.

mawint’s picture

That's good news.

I'm not using a language selector on our website so I only needed it to fix the problem of re-enabling the auto generation of the urls and resetting the URLs.

I have never used the language selector on a site however.

jmuzz’s picture

a.ross’s picture

This is not as easy at it looks at first sight. See: #1576552: Prevent PHP notices in path_node_insert/update if $node->path is defined but $node->path['alias'] is not.. The patch in #4 naively assumes that you wouldn't want to update the node's path alias. That's probably correct in most scenarios, as path aliases are, by default, only based on node title. It's easy to imagine someone using the value of a field inside a field collection in the Pathauto pattern.

Probably the best way to handle this would be to replicate what pathauto does when it creates the HTML for the Auto Alias checkbox. That appears to be the following (not available as a function):

  if (!isset($entity->path['pathauto'])) {
    if (!empty($id)) {
      module_load_include('inc', 'pathauto');
      $uri = entity_uri($entity_type, $entity);
      $pathauto_alias = pathauto_create_alias($entity_type, 'return', $uri['path'], array($entity_type => $entity), $bundle, $langcode);
      if ($pathauto_alias === FALSE) {
        // If Pathauto is not going to be able to generate an alias, then we
        // should not bother to show the checkbox since it wouldn't do anything.
        // Note that if a pattern does apply, but all the tokens currently
        // evaluate to empty strings, then $pathauto_alias would equal null and
        // not false.
        return;
      }
      else {
        $path = drupal_get_path_alias($uri['path'], $langcode);
        $entity->path['pathauto'] = ($path != $uri['path'] && $path == $pathauto_alias);
      }
    }
    else {
      $entity->path['pathauto'] = TRUE;
    }
  }
earthday47’s picture

Updating the patch in #4 for the latest beta, 7.x-1.0-beta10.

Keeping the status quo, abstaining from the bigger discussion here. :)

nico.knaepen’s picture

Status: Active » Needs work

When applying a new patch, it is required to set the status to "Needs review".

Some coding standard issues:

  1. +++ b/field_collection.entity.inc
    @@ -415,6 +415,9 @@ class FieldCollectionItemEntity extends Entity {
    +      if(module_exists('pathauto')){
    

    Put space between if and (.

  2. +++ b/field_collection.entity.inc
    @@ -415,6 +415,9 @@ class FieldCollectionItemEntity extends Entity {
    +        $host_entity->path['pathauto'] = false;
    

    false should be in uppercase

betz’s picture

Patch rebuild for 7.x-1.x, taking into account coding standards.

betz’s picture

Status: Needs work » Needs review
betz’s picture

nico.knaepen’s picture

Status: Needs review » Reviewed & tested by the community

@betz, Thanks for taking care of the coding standards.

jmuzz’s picture

Status: Reviewed & tested by the community » Needs work

I agree with #8, it isn't sufficient to just deactivate path auto when editing field collection items. I don't think it is necessary to duplicate the option on the field collection item form but it should at least use the setting for the node, so if it's set up to use a generated URL alias the alias should be updated whenever the node is saved, even if it's done via editing one of its field collection items.

What about the issues mentioned in #5? Do they no longer occur with this patch?

jmuzz’s picture

Are you using the latest version of pathauto? This apparently happened when using pathauto with any module that would save nodes, but it's supposed to be fixed now. #936222: Merge in pathauto_persist module functionality to prevent losing manual aliases with node_save() calls