Not sure if this is an issue for anyone, but I noticed my feed content type had extended languages enabled from i18n but the FeedsNodeProcessor plugin did not account for this, so I could not import feeds of languages that were not enabled on my site.

I assume nobody else would run into this, but I made a quick-and-dirty patch to do the check. It does not utilize ajax at all, though, so once you choose the Bundle in the Node Processor settings, you need to save the form in order to see the full list of available languages.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

PaulDinelle created an issue. See original summary.

PaulDinelle’s picture

Oops, just realized I didn't confirm i18n was enabled before doing this.

PaulDinelle’s picture

Turns out this did not solve the problem completely. It was showing up in the UI but would not respect the field when saved. I relocated the code to FeedsProcessor as the language and bundle are set there originally anyway and I had to add a fix to the validator.

PaulDinelle’s picture

Title: Node Processor not respecting bundle i18n language settings » FeedsProcessor not respecting bundle i18n language settings
MegaChriz’s picture

Status: Active » Needs work
+++ b/plugins/FeedsProcessor.inc
@@ -152,9 +152,19 @@ abstract class FeedsProcessor extends FeedsPlugin {
+      $languages = i18n_node_language_list($entity);

@@ -858,9 +868,20 @@ abstract class FeedsProcessor extends FeedsPlugin {
+        $languages = i18n_node_language_list($node);

It looks like the "alternative" language list is specific to node. Therefore I think we should only show the additional languages for the node processor.

I think we need an additional method on the processor class that returns the available languages. The node processor class can then override that method. There is a method called bundleOptions(), so maybe we should call this method languageOptions()?

Just to let you know: there are more specific i18n settings that Feeds doesn't respect currently (like "Require language" or "Lock language"). We deliberately didn't add support for them because that would have made multilingual support in Feeds even further away (and it took already 4+ years to get the thing done). See #1183440: Multilingual Feeds - Make field import language-aware.

PaulDinelle’s picture

I agree it should be in the node processor, I'm just not familiar enough with feeds to implement it properly, and the fix I made was for a specific project with a tight deadline so I couldn't spend a lot of time on it (in fact, spending the 3-4 hours I did to locate where the problem even started was too much, haha).

I did read the thread you posted before adding this one and it said in the i18n description that additional features should have new issues created for them which is why I made this.

The language list is actually specific to the bundle, I just couldn't figure out how to get i18n to return me a list of allowed languages without passing in a node (hence why I create a fake one to get the list). I originally included it in FeedsNodeProcessor, but to make it actually work I had to modify the validator in FeedsProcessor, so I moved the fix there since that's where it's defining the bundle settings anyway. I wasn't sure how to rig the validator into the FeedsNodeProcessor as it only passes the entity and the FeedsProcessor completely wipes the language setting out if it's not in the list, so FeedsNodeProcessor would only get the entity AFTER the language was removed and with no indication of what it used to be, I couldn't figure out how to add it back.

If someone with more technical knowledge feels like implementing it, that works for me. If I run into the issue again or come up with use-case problems, I'll resubmit a fix (hopefully one that's more accurate on the implementation).

MegaChriz’s picture

I did read the thread you posted before adding this one and it said in the i18n description that additional features should have new issues created for them which is why I made this.

Creating a new issue is correct. I thought I should just warn you that you could possibly face more road blocks between Feeds and i18n.

If the language list is specific to bundle and a node is needed to get that list, then creating a dummy node looks fine to me.

When adding a method that returns the available languages, the validator should use that information as well to validate the language. Therefore moving the validator to the node processor would not be needed.
The code in FeedsProcessor::entityValidate() would look then something like this:

// Ensure that a valid language is always set.
$key = $info['entity keys']['language'];
$languages = $this->languageOptions();

if (empty($entity->$key) || !isset($languages[$entity->$key])) {
   $entity->$key = $this->entityLanguage();
}

FeedsProcessor::languageOptions() would then return the available languages using language_list() and/or locale_language_list(). FeedsNodeProcessor::languageOptions() would return the i18n node languages (if available) or else leaves it to FeedsProcessor to provide available languages using the following code:

return parent::languageOptions();
PaulDinelle’s picture

I rebuilt the patch the way you mentioned. Looks much better imo! I updated a couple other places that were using language_list to test against language keys.

MegaChriz’s picture

Status: Needs work » Needs review

I set the issue status to "Needs review", so the testbot will evaluate the patch. I have not examined your patch in detail yet, but at first glance it seems to me that LANGUAGE_NONE should be one of the options returned by languageOptions() (I could be wrong though). Other than that code-wise it looks like it is heading in the right direction. Good work!

MegaChriz’s picture

Hm, the testbot seems to ignore the patch. Re-uploading so the testbot will pick it up.

Status: Needs review » Needs work
PaulDinelle’s picture

As expected it failed the test because I patched it against the current stable release, not dev. When I get some time I'll try to patch it against dev, but if someone else needs it beforehand, please add the changes into dev and create a patch. :)

MegaChriz’s picture

The patch applies cleanly against the latest dev, so it seems. Else the testbot would have said "Patch failed to apply". Glancing over the test results, the patch seems to break importing multilingual terms using the Taxonomy term processor. Additionally, there are some failures with importing values using entity translation also involving taxonomy.
I think the bug is something simple: for example a language check that is based on the output of language_list() instead of FeedsProcessor::languageOptions().

MegaChriz’s picture

Though it seems like a lot is failing, there are only two tests failing here:

  1. Feedsi18nTaxonomyTestCase::testAvailableProcessorLanguageSetting()
  2. FeedsMapperMultilingualFieldsTestCase::testAutocreatedTermLanguage()
MegaChriz’s picture

@PaulDinelle
Would you like to improve your patch and investigate the two failing tests? The changes provided in this patch would be useful to have for finalizing #2320781: Validate feed importer configuration: check for invalid bundle and invalid language.

MegaChriz’s picture

Version: 7.x-2.0-beta2 » 7.x-2.x-dev
Status: Needs work » Needs review
FileSize
4.48 KB

Reroll. Probably still needs work though.

Status: Needs review » Needs work
MegaChriz’s picture

When running the Feedsi18nTaxonomyTestCase::testAvailableProcessorLanguageSetting() locally, it appears that it failed because of the following error:

Fatal error: Call to undefined function i18n_node_language_list() in /Users/youri/Sites/devdesktop/drupal7/sites/all/modules/workinprogress/feeds_dev/feeds/plugins/FeedsNodeProcessor.inc on line 45

The i18n_node_language_list() is in the submodule i18n_node, not i18n!

New patch.

Status: Needs review » Needs work
MegaChriz’s picture

Status: Needs work » Needs review

A random test failure. Back to "Needs review".

MegaChriz’s picture

This adds LANGUAGE_NONE as one of the options returned by languageOptions(). Also some small code cleanups.

I wonder if LANGUAGE_NONE as one of the options has any unknown impact. The tests will tell.

MegaChriz’s picture

This adds a node_object_prepare() call for the dummy node. This is safer for modules that implement NODE_TYPE_BASE_language_list() (which is indirectly invoked by i18n_node_language_list()).

  • MegaChriz committed 48973a2 on 7.x-2.x authored by PaulDinelle
    Issue #2788125 by MegaChriz, PaulDinelle: Added support for i18n_node...
MegaChriz’s picture

Status: Needs review » Fixed

Committed #22 with a tiny change in FeedsProcessor::languageOptions(): when language_list() would return an empty result, no options would have been returned at all. Now at least LANGUAGE_NONE is still returned.

Status: Fixed » Closed (fixed)

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