- Issue created by @jurgenhaas
- ๐ฎ๐ณIndia Ishani Patel
ishani patel โ made their first commit to this issueโs fork.
- Merge request !507Issue #3522693: Avoid config form field type "machine_name" โ (Merged) created by Unnamed author
- ๐ฎ๐ณIndia Ishani Patel
Hello @jurgenhaas,
I've created MR.
Please check and review.Thank you!
- ๐ฉ๐ชGermany jurgenhaas Gottmadingen
@ishani patel this is looking good for the first item in the proposed solution. We also need to look into the other two.
- ๐ฎ๐ณIndia Ishani Patel
Hello @jurgenhaas,
Sure,Can I go with the below changes:For point 2. (#token_type)
For point 3. (#element_validate)Update the field definition like this:
2. Add Token Support to the Field Configuration:$form['name'] = [ '#type' => 'textfield', '#maxlength' => 1024, '#title' => $this->t('Machine name'), '#description' => $this->t('Specify the machine name / key of the render element. Tokens are allowed.'), '#default_value' => $this->configuration['name'], '#element_validate' => [[$this, 'validateName']], '#token_types' => ['node', 'user', 'custom'], // Based on your context ];
3. Add Custom Validation
public function validateName(array &$element, FormStateInterface $form_state, array &$complete_form) { $value = $element['#value']; // Allow token patterns like [entity:property] if (preg_match('/^\[.*:.*\]$/', $value)) { return; } // Otherwise, validate as a machine name. if (!preg_match('/^[a-z0-9_]+$/', $value)) { $form_state->setError($element, $this->t('The name must be a machine-readable name (lowercase letters, numbers, and underscores only) or a valid token like [node:title].')); } }
Let me know your thoughts.
Thank you! - ๐ฉ๐ชGermany jurgenhaas Gottmadingen
As for the token support, there are 2 ECA-specific attributes that we're using for the form fields:
'#eca_token_replacement' => TRUE, '#eca_token_reference' => TRUE,
The first one indicates that tokens are allowed in the input field and the plugin will replace tokens with their value. The second one tells the user that a token name should be provided without the brackets.
As for the machine name replacement, we always need the
eca_token_reference
to be turned on. In some cases, this can also supporteca_token_replacement
, we need to check the code in detail if the access and execute methods do call token replacement on that config value.We don't need to add anything to the description, though, as ECA takes care of it according to those two properties I described.
And then, the
#token_types
property is not required here, either.When it comes to validation, it may be a bit more complex than this. Following the token properties above, we may or may not have brackets around the "machine name", and the content itself can contain strings and a few extra characters like colons, but e.g. no spaces (I guess). But it can certainly be more than one colon, e.g. for something like
node:body:value
.In any case, the validator should go into a service or a trait, so that we don't end up with redundant code everywhere.
- Assigned to jurgenhaas
- Status changed to Needs work
17 days ago 1:57pm 16 July 2025 - ๐ฉ๐ชGermany jurgenhaas Gottmadingen
I've now added a field validation to the former machine name fields and also verified the token attributes for each of them.
- ๐จ๐ญSwitzerland boromino
If I add one of the changed actions in a bpmn model and click the save button, I get the error in the modeler, that something went wrong (the model is not saved) and in the console:
"\nAn AJAX HTTP error occurred.\nHTTP Result Code: 500\nDebugging information follows.\nPath: /admin/modeler_api/eca/bpmn_io/save\nStatusText: error\nResponseText: The website encountered an unexpected error. Try again later.TypeError: call_user_func_array(): Argument #1 ($callback) must be a valid callback, class Drupal\\modeler_api\\Form\\RuntimePluginForm does not have a method "validateElementsMachineName" in call_user_func_array() (line 282 of core/lib/Drupal/Core/Form/FormValidator.php). Drupal\\Core\\Form\\FormValidator->doValidateForm() (Line: 239)\nDrupal\\Core\\Form\\FormValidator->doValidateForm() (Line: 239)\nDrupal\\Core\\Form\\FormValidator->doValidateForm() (Line: 118)\nDrupal\\Core\\Form\\FormValidator->validateForm() (Line: 585)\nDrupal\\Core\\Form\\FormBuilder->processForm() (Line: 321)\nDrupal\\Core\\Form\\FormBuilder->buildForm() (Line: 295)\nDrupal\\modeler_api\\Component->validate() (Line: 395)\nDrupal\\modeler_api\\Api->prepareModelFromData() (Line: 241)\nDrupal\\modeler_api\\Controller\\ModelerApi->save()\ncall_user_func_array() (Line: 123)\nDrupal\\Core\\EventSubscriber\\EarlyRenderingControllerWrapperSubscriber->Drupal\\Core\\EventSubscriber\\{closure}() (Line: 622)\nDrupal\\Core\\Render\\Renderer->executeInRenderContext() (Line: 121)\nDrupal\\Core\\EventSubscriber\\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext() (Line: 97)\nDrupal\\Core\\EventSubscriber\\EarlyRenderingControllerWrapperSubscriber->Drupal\\Core\\EventSubscriber\\{closure}() (Line: 183)\nSymfony\\Component\\HttpKernel\\HttpKernel->handleRaw() (Line: 76)\nSymfony\\Component\\HttpKernel\\HttpKernel->handle() (Line: 53)\nDrupal\\Core\\StackMiddleware\\Session->handle() (Line: 48)\nDrupal\\Core\\StackMiddleware\\KernelPreHandle->handle() (Line: 28)\nDrupal\\Core\\StackMiddleware\\ContentLength->handle() (Line: 32)\nDrupal\\big_pipe\\StackMiddleware\\ContentLength->handle() (Line: 116)\nDrupal\\page_cache\\StackMiddleware\\PageCache->pass() (Line: 90)\nDrupal\\page_cache\\StackMiddleware\\PageCache->handle() (Line: 48)\nDrupal\\Core\\StackMiddleware\\ReverseProxyMiddleware->handle() (Line: 51)\nDrupal\\Core\\StackMiddleware\\NegotiationMiddleware->handle() (Line: 53)\nDrupal\\Core\\StackMiddleware\\AjaxPageState->handle() (Line: 51)\nDrupal\\Core\\StackMiddleware\\StackedHttpKernel->handle() (Line: 715)\nDrupal\\Core\\DrupalKernel->handle() (Line: 19)\n"
- ๐ฉ๐ชGermany jurgenhaas Gottmadingen
Ah, the validation happens in a pseudo form and not directly in the plugin, so that the trait is not available at that point. I've replaced that with a static class method now.
- ๐ฉ๐ชGermany jurgenhaas Gottmadingen
@boromino that's not correct. See the original issue that started all this at ๐ Token name in RenderElementActionBase cannot be specified as nested token Active which uses
mytoken:nested
as a token reference, e.g. inRenderElementActionBase
. So, for token references, colons are allowed. - ๐จ๐ญSwitzerland boromino
I was only referring to token replacements, but I have tested it with a machine name with colon and it works. I thought it had to comply with Drupal's machine_name form element, but that doesn't seem to be the case.
-
jurgenhaas โ
committed 322bc3d8 on 3.0.x authored by
ishani patel โ
Issue #3522693 by jurgenhaas, ishani patel, boromino: Avoid config form...
-
jurgenhaas โ
committed 322bc3d8 on 3.0.x authored by
ishani patel โ
-
jurgenhaas โ
committed 7ca63d06 on 2.1.x authored by
ishani patel โ
Issue #3522693 by jurgenhaas, ishani patel, boromino: Avoid config form...
-
jurgenhaas โ
committed 7ca63d06 on 2.1.x authored by
ishani patel โ
- ๐ฉ๐ชGermany jurgenhaas Gottmadingen
Merged and back ported, thank you so much for all the tests and reviews.