Problem/Motivation
If you try to update any configurable actions that are created by the user module, like 'Add ROLE to selected users', you will hit a validation error with the machine name.
Steps to reproduce:
1. go to admin/config/system/actions
2. configure the 'Add the Administrator role to the selected users' action
3. Try to save it
4. You will see a validation error on the machine name field as the config name is 'user_add_role_action.administrator'
Proposed resolution
Either change the ID for the created action entities to not contain a '.' character to namespace them OR expand the machine name element to handle/allow dots, or make this configurable. I don't think it allows for this currently?
Remaining tasks
User interface changes
API changes
Data model changes
Comments
Comment #2
jeremy commentedPerhaps the simplest solution is to simply allow the periods. Patch attached.
Comment #3
damiankloip commentedComment #4
jeremy commentedAdding updated error text to reflect that with this patch periods are allowed too.
Comment #5
jhedstromAllowing periods makes sense to me. Should we add a test here to avoid future regressions?
Comment #6
strykaizerWriting test
Comment #7
strykaizerTest only and patch with code from #4 attached
Comment #9
catchWill this also need an upgrade path if the action was already saved with the .?
Comment #11
damiankloip commentedI don't think so, unless I'm missing something (highly probable). This just changes the validation, so ones saved with a '.' are fine, it just means you can now edit them?
Comment #12
kristiaanvandeneyndeThe user module seems to use a period to "namespace" its actions to keep people from creating an action with the same machine name. This is because it will delete any associated actions when a user role is deleted.
If you happened to be unfortunate enough to:
Your custom action 'user_add_role_action.myrole' would be deleted by the user module even though it was never created by that module! I therefore suggest we do not allow the use of periods in the machine name, but instead disable the machine name field when editing so it doesn't need to run through validation.
Comment #13
heykarthikwithuAs per #12,
machine name doesn't need to run through validation, if at all this not created newly.
Comment #15
heykarthikwithure-rolled #13 patch.
Comment #16
kristiaanvandeneyndeThe element should be disabled, not just its validation. Right now, you allow anything to be entered into the machine name field.
Consider using the #disabled, #value and #element_validate key.
Comment #17
kristiaanvandeneyndeComment #18
heykarthikwithumachine name will be disabled if it is not new.
'#disabled' => !$this->entity->isNew(),and also will not be validated if machine name is not new.
'#element_validate' => !$this->entity->isNew() ?: [],Comment #20
kristiaanvandeneyndeFrom the FAPI 8 reference:
So
'#element_validate' => !$this->entity->isNew() ?: [],won't work. It assigns TRUE to the property when the entity isn't new and an empty array when it is. You should leave the property alone when the entity is new and specify an empty array when it isn't.Comment #21
heykarthikwithuleaving the property alone when the entity is new and specify an empty array when it isn't.
Comment #22
kristiaanvandeneyndeLooks good, but this is the kind of "weird" code that gets tossed out in another issue unless you document why it was added in the first place. Attached is a patch with documentation added.
Comment #23
strykaizerHmm, I think we should always validate the machinename, even if its disabled. So #12 is prolly not an option, as disabled form items are also submitted (and therefore can be altered by javascript etc.)
Feel free to correct me if I'm wrong ;)
Comment #24
kristiaanvandeneyndeFrom FormBuilder::handleInputElement()
Comment #25
kristiaanvandeneyndePlaying the devil's advocate here, but if core created these actions and core will delete them when the user roles are deleted: What good will editing them do? They may end up being deleted automatically because it would make sense to do so if they weren't modified. However, if you did modify them, an automatic deletion may really hurt your site.
Aside from the patch fixing the issue at hand, there's other approaches to this:
That being said, implementing a system to mark action entities as fixed would require a lot more code than what the current patch contains.
Comment #26
strykaizerOh, thanks for that!
In that case, I can live with the change suggested. Its not the most pretty (core generating machinenames with dots, but not allowing them to be created), but neither is allowing dots and having certain actions (in a rare case) automagicly deleted.
Another option might be removing the dots in the generated "add x role to selected user" machinename, and delete those specific generated actions on role_deletion by using a custom event/hook and query. That way we keep machinenaming consistency and do not have a special case for Actions.
Comment #27
kristiaanvandeneynde#2605042: Cannot edit actions created by user_user_role_insert()