J4 Issue ?
avatar brianteeman
brianteeman
28 Oct 2019

When you get an error using the api it is often made up of TWO strings

Expected result

Save failed with the following error: Another Contact from this category has the same alias (remember it may be a trashed item).

Actual result

Save failed with the following error: COM_CONTACT_ERROR_UNIQUE_ALIAS

Code

The relevant code is

// Attempt to save the data.
if (!$model->save($validData))
{
throw new Exception\Save(Text::sprintf('JLIB_APPLICATION_ERROR_SAVE_FAILED', $model->getError()));
}

I suspect it might be caused by my PR #26393

avatar brianteeman brianteeman - open - 28 Oct 2019
avatar joomla-cms-bot joomla-cms-bot - change - 28 Oct 2019
Labels Added: ?
avatar joomla-cms-bot joomla-cms-bot - labeled - 28 Oct 2019
avatar alikon
alikon - comment - 30 Oct 2019

it seems that adding the missing import of use Joomla\CMS\Language\Text; on #26393 should solve

avatar alikon alikon - change - 30 Oct 2019
Status New Closed
Closed_Date 0000-00-00 00:00:00 2019-10-30 08:44:26
Closed_By alikon
avatar joomla-cms-bot joomla-cms-bot - change - 30 Oct 2019
Closed_By alikon joomla-cms-bot
avatar joomla-cms-bot joomla-cms-bot - close - 30 Oct 2019
avatar joomla-cms-bot
joomla-cms-bot - comment - 30 Oct 2019

Set to "closed" on behalf of @alikon by The JTracker Application at issues.joomla.org/joomla-cms/26846

avatar alikon
alikon - comment - 30 Oct 2019

please test #26864


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/26846.

avatar alikon alikon - change - 30 Oct 2019
Status Closed Confirmed
Closed_Date 2019-10-30 08:44:26
Closed_By joomla-cms-bot
avatar joomla-cms-bot joomla-cms-bot - change - 30 Oct 2019
Status Confirmed New
Closed_Date 0000-00-00 00:00:00
avatar joomla-cms-bot joomla-cms-bot - reopen - 30 Oct 2019
avatar joomla-cms-bot
joomla-cms-bot - comment - 30 Oct 2019

Set to "open" on behalf of @alikon by The JTracker Application at issues.joomla.org/joomla-cms/26846

avatar alikon
alikon - comment - 30 Oct 2019

reopened cause #26864 don't solve the issue even if correct something


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/26846.

avatar brianteeman
brianteeman - comment - 30 Oct 2019

the problem is not with the use statement. In joomla we had 2 applications and therefore we had a language folder in each application (site and administrator). We now have an additional application (api) and so we should really have an application language folder. It is not enough to proxy to either the site or the administrator folder as the strings could be in either.

avatar manojLondhe
manojLondhe - comment - 2 Nov 2019

Instead of adding one more language file for API, which will have duplicate constants and values, what if we load the languages files needed (may it be the backend file or site file) ?

Eg: for above case load lang. file in save method.

/joomla-cms/api/components/com_contact/Controller/ContactController.php

protected function save($recordKey = null)
{
	$lang   = Factory::getLanguage();
	$lang->load('com_contact', JPATH_ADMINISTRATOR, null, false, true);

	// Other code below
}

3rd party ext. developers can choose which files to load - site or admin's in case of the APIs they build

avatar brianteeman
brianteeman - comment - 4 Nov 2019

@wilsonge thoughts?

avatar Quy Quy - change - 4 Nov 2019
Labels Added: J4 Issue
avatar Quy Quy - labeled - 4 Nov 2019
avatar wilsonge
wilsonge - comment - 4 Nov 2019

We already load the component specific language files that way in the ApiDispatcher https://github.com/joomla/joomla-cms/blob/4.0-dev/libraries/src/Dispatcher/ApiDispatcher.php#L65

Our problem is the core joomla files en-GB.ini and lib-joomla.en-GB.ini (or of course the translated version)

avatar brianteeman
brianteeman - comment - 4 Nov 2019

ok - i will dig into this as we discussed - tomorrow

avatar brianteeman
brianteeman - comment - 4 Nov 2019

@wilsonge
Doesn't the code that you point to only load the site language file and any language file in the admin component but not the admin language folder itself

??

avatar wilsonge
wilsonge - comment - 5 Nov 2019

Lib joomla always comes from admin https://github.com/joomla/joomla-cms/blob/4.0-dev/libraries/src/Application/CMSApplication.php#L741

So it’s just the main en-GB file here https://github.com/joomla/joomla-cms/blob/4.0-dev/libraries/src/Language/Language.php#L271 at language object first use

The code I pointed to was component files in both cases. It tries to load from active application language file (i.e. JPATH_BASE which here is JPATH_API). We don’t fall back the en-GB.ini as that’s handled in the library for language on the lines just above here

avatar brianteeman
brianteeman - comment - 5 Nov 2019

So the problem then is that we want to be loading the component language file from the admin and its not

avatar wilsonge
wilsonge - comment - 5 Nov 2019

We're loading the component language file just fine - at least that was my read. The issue I understood from our discussion was around the en-GB.ini (https://github.com/joomla/joomla-cms/blob/staging/language/en-GB/en-GB.ini) which needed to go in the language folder of the API. It was the strings like JCategory that didn't translate in the API https://github.com/joomla/joomla-cms/blob/staging/language/en-GB/en-GB.ini#L61

avatar brianteeman
brianteeman - comment - 5 Nov 2019

turned out there are two different issues

  1. Save failed with the following error: COM_CONTACT_ERROR_UNIQUE_ALIAS
  2. Field required: JCATEGORY
avatar manojLondhe
manojLondhe - comment - 5 Nov 2019

For me

  1. com_contact backend lang. file was not loaded
  2. Field required: JCATEGORY

@brianteeman @wilsonge

avatar wilsonge
wilsonge - comment - 5 Nov 2019

OK So

  1. So that means https://github.com/joomla/joomla-cms/blob/4.0-dev/libraries/src/Dispatcher/ApiDispatcher.php#L65 isn't working as I'd expect :(
  2. Is the en-GB.ini file issue - it needs to have a language folder in the api directory per our discussion @brianteeman (but looks like lib_joomla is fine so just the en-GB.ini file)
avatar brianteeman
brianteeman - comment - 5 Nov 2019

I agree with your conclusion and thats what I was trying to say

avatar infograf768
infograf768 - comment - 5 Nov 2019

Please explain how to test this problem as When you get an error using the api is pre(or post)-homo-sapiens language for me...

avatar wilsonge
wilsonge - comment - 5 Nov 2019

Make an API request creating a contact and then submit a request to create a second one with the same alias for the first issue.
Make an API request missing a required field (e.g. category) in the form to reproduce the second issue

avatar infograf768
infograf768 - comment - 5 Nov 2019

Make an API request does not help at all, sorry.

avatar brianteeman
brianteeman - comment - 5 Nov 2019

I guess that you need to read the instructions for using the API https://docs.joomla.org/J4.x:Joomla_Core_APIs

avatar N6REJ
N6REJ - comment - 6 Nov 2019

@infograf768 unless you know curl there is no "easy" way to test this jm.
First you have to identify yourself as a super admin, THEN you can create the contact, HOWEVER
both of these require curl ( since your using curl to begin with ) and you can't simply cut/paste from command line. I THINK you then have to read the response but thats conjecture.
the link brian gave you is worthless to your specific question other then it provides sample json(?) data that curl would use.
The doc, like most of our docs now, assume your a experienced dev and know what your doing. Seeing it's an api I can SORTA understand that BUT I've seen several api's that are extremely well documented.
I would THINK this is something the unit tests should be able to handle reliably.
After about 30 minutes of testing/checking/trying it looks like phpstorm has a method to make life "easier" but it's as clear as mud to me.
image

avatar brianteeman
brianteeman - comment - 6 Nov 2019

The link is absolutely not worthless. If it was then I wouldnt have been able to do anything ;)

Instead of curl you will probably find it easier to use postman https://www.getpostman.com/

I am creating a quick video for that and will update thiis post when the video is online

avatar brianteeman
brianteeman - comment - 6 Nov 2019
avatar wilsonge
wilsonge - comment - 6 Nov 2019

@N6REJ I'd love to end up producing an Open API file (and push that into something like ReDoc) for something like swagger unfortunately trying to get the list of parameters and response parameters is basically impossible for Joomla. We have plugins adding dynamic extra information in responses and custom fields that add extra required fields potentially to the request. So whilst the docs suck - their better the nothing and probably about as good as we can do for the next few months until the API is solid and we can focus on building the best docs possible

avatar N6REJ
N6REJ - comment - 6 Nov 2019

The link is absolutely not worthless. If it was then I wouldnt have been able to do anything ;)

Notice i said "to your specific purpose" along with caveats!

avatar N6REJ
N6REJ - comment - 6 Nov 2019

Instead of curl you will probably find it easier to use postman https://www.getpostman.com/

I am creating a quick video for that and will update thiis post when the video is online

FANTASTIC! I tried to find something like that but was unable to!... TYVM! THAT SIR IS HELPFUL... please add it to the docs.

avatar wilsonge wilsonge - change - 19 Jan 2020
Labels Added: ?
avatar wilsonge wilsonge - labeled - 19 Jan 2020
avatar SharkyKZ
SharkyKZ - comment - 22 Jan 2020

For fixing component language files see #27593.

avatar SharkyKZ
SharkyKZ - comment - 22 Jan 2020

I'm also getting these notices:

Notice: Trying to access array offset on value of type null in C:\xampp\htdocs\joomla-cms\libraries\src\Language\Language.php on line 1029

Notice: Trying to access array offset on value of type null in C:\xampp\htdocs\joomla-cms\libraries\src\Language\Language.php on line 1029

Notice: Trying to access array offset on value of type null in C:\xampp\htdocs\joomla-cms\libraries\src\Language\Language.php on line 1029

Notice: Trying to access array offset on value of type null in C:\xampp\htdocs\joomla-cms\libraries\src\Language\Language.php on line 1060

Does it make sense to make paths in Language API configurable instead of relying on JPATH_BASE?

avatar wilsonge
wilsonge - comment - 24 Jan 2020

I think we are going to need API paths. Right now we're running something a bit hacky to get to the admin models - but the long term aim is 3rd party extensions will be able to make API's first class the same as Admin/Site

avatar wilsonge wilsonge - change - 28 Jan 2020
Labels Added: ?
avatar wilsonge wilsonge - labeled - 28 Jan 2020
avatar wilsonge
wilsonge - comment - 28 Jan 2020

Anyone here able to do a PR to clone the en-GB.ini file from admin into the JROOT/api/language directory? should fix the last of the issue

avatar brianteeman
brianteeman - comment - 28 Jan 2020

on it

avatar brianteeman brianteeman - change - 28 Jan 2020
Status New Closed
Closed_Date 0000-00-00 00:00:00 2020-01-28 22:18:56
Closed_By brianteeman
avatar brianteeman brianteeman - close - 28 Jan 2020
avatar wilsonge wilsonge - change - 29 Jan 2020
Labels Removed: ?
avatar wilsonge wilsonge - unlabeled - 29 Jan 2020
avatar wilsonge wilsonge - change - 16 Sep 2020
Labels Removed: ?
avatar wilsonge wilsonge - unlabeled - 16 Sep 2020

Add a Comment

Login with GitHub to post a comment