0

I need to set a limit on the number of times a field can be edited.

use case: the name of the user (field_name_user) can only be edited once or twice.

I tried node edit limit and field permissions but neither won't fit the task. Is ther any other module out there or a way to achieve this?

1 Answer 1

2

I think you can achieve this using an entity field, in this case the user entity, and some PHP Code.

Add a Field that counts the numebr of editions. Then, alter the entity edit form (in this case again, the user edit form) and:

  1. Hide the field (with #access FALSE, for example).
  2. Add your custom submit handler to the entity edit form.
  3. If the field value is minor than the max edit count allow to edit then increment the field value in a custom submit handler.
  4. If the field value is equal to the max edit count then deny the edition (deny the edit form, hide the field or whatever you want and fit your needs).

Also don't forget to hide the field when the entity is shown (check the entity display settings page).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.