I just tried to create my first context when, after hitting Save, I realised my Context ID was invalid. As a result, I noticed the following related issues:
1 - The error message I got said "The export id can only consist of lowercase letters, underscores, dashes, and numbers." This doesn't make sense as the field that is highlighted is 'Name'. The message should be re-worded to something like "The context name can only consist of lowercase letters, underscores, dashes, and numbers."
2 - I was not aware that the context name was restricted in any way. I recommend adding something like the following to the Name field's help text: "The unique ID for this context. Must only consist of lowercase letters, underscores, dashes, and numbers."
3 - When the page reloaded to display the error, I lost all the changes I had made to the Conditions and Reactions (and subsequently had to redo them). I recommend these changes be saved on reloading the form as per all other Drupal forms.
| Comment | File | Size | Author |
|---|---|---|---|
| #10 | 927244-fixing-context-name.patch | 2.96 KB | bnash2501 |
| #9 | 927244-fixing-context-name.patch | 3.88 KB | bnash2501 |
Comments
Comment #1
agileware commentedI have come across this too.
When you create a context the name field doesn't say that you can't use certain characters.
It also doesn't complain when you create a context that has hyphens in the name.
But then when you export that context and import it and try to save it you get this error:
If you remove the hyphen from the export text before importing it works fine.
Comment #2
benjf commentedI can confirm that this is not an issue when creating a new context in the UI, but does occur when importing a context. In my case, I tried several contexts which were just exported from the same site. I also tried creating a test context with the identical name of a "bad" imported context, and it was accepted.
update: once I get the initial error, I cannot enter any string of text and successfully submit.
workaround: edit the exported context code and replace any hyphens with underscores in $context->name before pasting it into the context import textarea. On the resulting page, before saving the imported context, you can change the underscores back to hyphens, and the form submit is accepted.
Comment #3
el_reverend commentedI can confirm this error when importing a context. It imports and displays the the error message that the Context ID can only display lowercase letters, underscores, and numbers! However when this error message is called when you create a context item from scratch the error message includes dashes as allowed characters.
My context ID is: logged-in_and_edit-user-details and it fails on imports and save. However if I remove the dashes and underscores, update the context, add the dashes and underscores back in; and then save the import completes successfully.
Comment #4
soulfroysFor now, the #3 workaround worked for me too...
Comment #5
Ankabout commentedI can confirm the importing error as well on D7.8 and Context 3.0-beta-1.
My context had a capital in the name, which works fine, but when you export and import, it does not accept the capital.
Comment #6
rerooting commentedI am have this issue as well retroactively - all my context names had spaces in them before updating to the latest. Now when I go back to edit the older contexts, the 'Name' field is disabled, however I cannot save the context until the namespace is changed. This means that I am totally locked out of editing older contexts unless I go into the database.
Comment #7
rerooting commentedI should also mention that I am using the D7 version as well. Brute forcing the database and changing the context machine names over manually worked from what I can tell. I hope less experienced users dont run into this bug because it could ruin a project! Make sure to back up before updating to the latest version of context module, and that all the names of your context are machine name appropriate. We should also make sure that there is a way to fix this issue during migration - whether it transliterates context names when you run database updates, or forces a change on saving an old context (it almost does this, except for the fact that the form field is disabled when you go to change it!). I may upload a patch that takes care of the latter here shortly.
Comment #8
laura s commentedSubscribe. Having to clone any context needing editing at this point.
Comment #9
bnash2501 commentedI've created a patch to add a proper field description for the name and fix the error message to now say name instead of id.
The patch includes an update that will remove invalid characters from the context name. In cases that the new name is already in use, it will append a numeric value.
This will likely require features to be re-exported.
Comment #10
bnash2501 commentedUpdated patch to fix some formatting issues.
Comment #11
Ankabout commentedIt seems in Context 3.0-beta2, #1 and #3 of the original post is fixed. Only #2 still needs to be added.
Is this correct? Or is there a reason why the description is not changed in the published module, but the rest has?
Comment #12
hass commentedThe issues seems to be fixed. I get an error message "The name can only consist of lowercase letters, underscores, dashes, and numbers."