Closed (fixed)
Project:
Contact Storage
Version:
8.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Reporter:
Created:
13 May 2016 at 06:11 UTC
Updated:
29 Aug 2016 at 21:04 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
larowlanComment #3
larowlanComment #4
Bambell commentedComment #5
Bambell commentedHere we go, however I'm not too sure about :
Illegal string offset '#disabled'For :
$form_action['#disabled'] = 'disabled';Also, should a second verification be done after the form has been submitted, in case the form is submitted by other means than pressing the submit button?
Comment #6
Bambell commentedComment #8
Bambell commentedFixed the failing test.
Comment #9
berdirYou should first check if the max submission value is 0. There's no point in doing a query when there is no limit.
Also, this is now the total amount.
I think what's more likely desired here is to have a limit that's per user. So you need to check limit on the user id. The description in the form should also mention that.
Where it gets interesting is anonymous submissions. We don't want to limit it for all uid 0 together I think. So we maybe need to store the IP of the submission?
Can you post a screenshot of how this looks?
Comment #10
Bambell commentedHere's the requested screenshot. Will await community input, as discussed, regarding whether we want the form submission limit to be per user or for the total number of submissions or both.
Comment #11
larowlanI think @Berdir meant a screenshot of how the 'this form is disabled' looked :)
Looking good, couple of observations.
We should use 'Maximum submissions' here
Agree with @Berdir, we should check if its > 0 before we query.
This doesn't actually prevent submission, as anyone can inspect the element and remove the disabled attribute. We need to also include a validation constraint that prevents the submission at the Entity layer. This would be an entity-level constraint, see Comment's annotation for an example.
After we add the constraint, we should validate we can't actually submit too.
Comment #12
larowlanAlso - I think we should make this message configurable.
Comment #13
berdirYes, that's not the screenshot that I meant :)
We could also hide the buttons completely in that case? Validation constraint doesn't hurt as well.
@larowlan: What do you think about per user or not? I think usually you want to limit the submissions per user. Total limit also has use cases, but I also don't want to build a full-blown event registration system here ;)
Comment #14
larowlanYeah hiding the buttons is a good idea, validation constraint is for REST sake too.
Per user is a good idea.
Comment #15
berdirComment #16
dawehnerSo yeah for my usecase it would be a global limit, but I agree the more common usecase is per user.
Comment #17
Bambell commentedHere's my attempt at this. I added a constraint on the
messagefield of thecontact_messageentity type. The validate method of the constraint validation class is duplicated from thehook_form_FORM_ID_alterfunction. Validating access to the form by validating an entity field's input sounds wrong and this code duplication looks absolutely wrong, but I'm not exactly sure how to do this differently. Also, I was unable to write a test to verify that anonymous user has a submission limit, I guess it might have to do with (inContactStorageTest) :user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, array('access site-wide contact form'));The patch passes manual testing, though.
Comment #18
andypostPlease use
Comment #19
berdirLets rename this to maxium_submissions_user.
Did you try setting #access to FALSE?
unset() can result in notices, if other code tries to access those arrays and they're completely gone then.
This requires a re-save and the data is also not available for mails.
There are two alternatives:
a) An entity builder callback, that is called when the entity is built from the form values. It's still tied to the form, however.
b) A default value callback on the field definitions, then the value is already there when we create the entity.
Use type entity_reference with a target_type => user setting.
Can we somehow avoid to duplicate this code? Move it somewhere both places can call it and get the current submissions back?
There have been discussions about a repository service with such methods.
Comment #20
Bambell commentedAll those changes should have done.
Comment #21
berdirwe need an update function to add those two fields.
lets document on those two functions that they are used as default value callbacks. they seem weird if you don't know that.
no empty line after return.
Comment #22
Bambell commentedHere we go. I moved the test in its own function and therefor had to do a tiny bit of refactoring on the test class to extract common behavior in a
setUp()function. This will be green after the modification suggested in #2780763: Add missing parameter in ContactFormCloneForm::__construct() is in.Comment #23
berdirLooks good to me.
I think we have at least 3 issues that refactor that test in a similar way. going to be a bit painful to re-roll the others, we might want to focus on getting one in and then finish the others.
Comment #24
larowlanFixed, thanks