Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[4.0] Support to set the location when saving a category through the API #36318

Merged
merged 4 commits into from Dec 30, 2021

Conversation

laoneo
Copy link
Member

@laoneo laoneo commented Dec 15, 2021

Summary of Changes

This PR adds the possibility to define the location of the category while saving it through the API. A location can be one of the following values:

  • before
  • after
  • first-child
  • last-child

If before or after is used it is advisable to also set the location_reference parameter which defines the sibling the category should be located.

Testing Instructions

Run the following curl command:

curl --location --request POST 'https://[your J4 website]/api/index.php/v1/content/categories' \
--header 'Content-Type: application/json' \
--header 'X-Joomla-Token: [your user token]' \
--data-raw '{
    "title": "test",
    "location": "first-child",
    "published": "1",
    "language": "*"
}'

Actual result BEFORE applying this Pull Request

The new category appears as last item in the list in the back end UI.

Expected result AFTER applying this Pull Request

The new category appears as first item in the list in the back end UI.

Documentation Changes Required

The new location and location_reference arguments need to be documented.

@laoneo
Copy link
Member Author

laoneo commented Dec 16, 2021

@alikon , @khu5h1 can you guys give this one here a test too? Similar procedure as the other ones. Thanks!!

@alikon
Copy link
Contributor

alikon commented Dec 17, 2021

i guess we should do the same for endpoint POST {{base_path}}/api/index.php/v1/menus/{app}

@alikon
Copy link
Contributor

alikon commented Dec 17, 2021

I have tested this item ✅ successfully on b51641d

CS issue apart


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

@laoneo
Copy link
Member Author

laoneo commented Dec 20, 2021

@alikon if accepted, then I can do also for menus.

@HLeithner
Copy link
Member

While testing this it seems that api can by-pass the alias naming restrictions is this intended?

curl --location --request POST 'https://[domain]/api/index.php/v1/content/categories' \
--header 'Content-Type: application/json' \
--header 'X-Joomla-Token: [key]' \
--data-raw '{"location_reference":2,
    "title": "test before Uncategorised",
    "location": "before",
    "published": "1",
    "language": "*"
}

executing this command 2 times ends, in one item before and one (the second call) as last item... I know unrelated to this PR...

What the rest is working find but could we get some variable validation in this function because passing location and location_reference without input validation is wrong.

@laoneo
Copy link
Member Author

laoneo commented Dec 20, 2021

Validation is done on the model level, so there is no reason to do it on the controller level as well. So if there is something missing on the validation side, it must be fixed in the model. But I casted to int in the controller to be double save.

@laoneo
Copy link
Member Author

laoneo commented Dec 22, 2021

@HLeithner can you mark your test as successful please.

@HLeithner
Copy link
Member

I have tested this item ✅ successfully on 323a846


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

1 similar comment
@alikon
Copy link
Contributor

alikon commented Dec 23, 2021

I have tested this item ✅ successfully on 323a846


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

@alikon
Copy link
Contributor

alikon commented Dec 23, 2021

RTC


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

@joomla-cms-bot joomla-cms-bot added the RTC This Pull Request is Ready To Commit label Dec 23, 2021
@wilsonge wilsonge merged commit d9cc2bc into joomla:4.0-dev Dec 30, 2021
@wilsonge
Copy link
Contributor

Thanks!

@joomla-cms-bot joomla-cms-bot removed the RTC This Pull Request is Ready To Commit label Dec 30, 2021
@wilsonge wilsonge deleted the j4/api/category/location branch December 30, 2021 21:13
@wilsonge wilsonge added this to the Joomla 4.0.6 milestone Dec 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants