Problem/Motivation

Currently, I can easily set the same alias many times.
One property MUST be unique in a resource.

Step to reproduce

  1. Overwrite the user--user resource and add the same alias picture for fields default_langcode and user_picture
  2. Go to /jsonapi/user/user, default_langcode property has disappeared

Proposed resolution

Add a form validate (maybe an entity preSave verification ?) to ensure aliases are unique.

Comments

vpeltot created an issue. See original summary.

logickal’s picture

StatusFileSize
new1.74 KB

Here's an initial patch to provide this validation, which I agree is probably a very good idea. It also compares the override to the original fields, so you couldn't set 'body' to 'nid' for example.

logickal’s picture

Status: Active » Needs review
e0ipso’s picture

Thanks for the patch @logickal! This is looking good.

We should also investigate how to add an entity validation to make sure that we cannot even create those duplicates when saving the config entity without a form.

Would you like to work on that as part of this issue, or maybe just open a follow up issue and work (you or anyone else) on that there?

e0ipso’s picture

Status: Needs review » Needs work

Marking as needs work since we should either:

  1. Have a follow up issue created.
  2. Some sort of config entity validation included.
logickal’s picture

I meant to come back to this over the weekend, but got distracted - I'll try to take a look at the entity validation over the next day or so!

logickal’s picture

Status: Needs work » Needs review

@e0ipso - I did some investigation and found that config entities don't support proper Drupal entity validation out of the box, so it will likely be a more basic Symfony validation solution. I've got about half of a patch, but I think it probably makes sense to go ahead and break that out into a separate ticket, which I will create.

mkolar’s picture

Hello, #2 works with fields which is great, but you can still set resource type and url wrongly. You can have more resources with same url and rename types same.

mkolar’s picture

StatusFileSize
new2.51 KB

patch.. Validates path and resource type

e0ipso’s picture

@logickal I agree with your conclusion to add a follow up task for that. Did you get the chance to create that ticket? Can you link it to this issue?

Also, I think that the ability to validate configuration entities has been added recently. Did you check that?

  • e0ipso committed 095bc9e on 8.x-1.x authored by logickal
    fix(Form): Enforce unicity of form elements (#2892024 by logickal,...
e0ipso’s picture

Status: Needs review » Fixed

Thanks all! This was committed.

logickal’s picture

@e0ipso - Yes, I opened https://www.drupal.org/node/2894897 to cover the entity validation, and Daniel let me know over there that it's now possible. I haven't had a chance yet to dive in, though - as soon as I can come up for air I will take another look at it!

Status: Fixed » Closed (fixed)

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