OK, interesting! Thanks for these clues @Farmer-Ed and @pat. It makes me wonder if maybe the langcode is being saved to the log as en/no depending on what language the user is using when they save it? But then the API is trying to save it as the opposite, or something…
Are you creating AND updating the log both through the API? Or was it created through the UI and then being updated through the API? (Or some other combination of things?)
Reading through it now to see if I can find any potential clues…
One thing that would be useful @pat … could you paste the JSON representation of the log you are trying to PATCH? Or at least the top bit (don’t need all the attributes and relationships I don’t think).
The condition is pretty simple, so I bet we can figure out what’s failing…
if ($method === 'PATCH' && $entity->language()->getId() !== $current_content_language) {
$available_translations = implode(', ', array_keys($entity->getTranslationLanguages()));
throw new MethodNotAllowedHttpException(['GET'], sprintf('The requested translation of the resource object does not exist, instead modify one of the translations that do exist: %s.', $available_translations));
}
Right above that $current_content_language gets set:
I’m curious what $entity->language()->getId() is… I’m guessing en… @pat (or @Farmer-Ed) could you confirm what the langcode is on the log before you try to PATCH it?
So maybe the question is: why is $current_content_language set to nb? Maybe that should always be en if we aren’t using the content translation module? Perhaps the farm_l10n module could force that?
@pat One idea for a workaround while we continue to investigate this… I think if you created a dedicated API user in your instance, with a language of English, you could use that for API requests and it would work.
This is interesting, and suggests that Drupal core is still working through all the different ways that JSON:API could/should work with translations. This sums it up:
The problem with this is that it depends on and varies by each site’s language negotiation configuration. This means translations may behave differently on Drupal-powered JSON:API instances A versus B.
I think that’s basically what we’re running into here. Although I’m curious if we can solve this with a simple hack/override in farm_l10n… with the understanding/assumption that farmOS does NOT support support content translations and the default language is always en. Like I said above…
These assumptions may not be “forever”, though, so would this create roadblocks for some of those next steps… ? Seems like they would.
Allowing other languages to be the “default” (referring specifically to what was decided upon here, which refers to a very specific configuration, mind you: https://www.drupal.org/project/farm/issues/3257430)
Allowing use of the content translation modules.
Neither of those are priorities for future farmOS development, so it would only be creating roadblocks for developers/hackers who wanted to go farther on their own.
I think if you don’t support translations in content that you shouldn’t use the "langcode": "en" it should be "langcode": "und"
It works with Logs created through the API and UI and regardless of the Users Language.
Not sure where the existing logs(and other entities?) would stand though if this change was made to existing sites? I can modify them manually one at a time from UI but get not allowed from API