- Issue created by @jcandan
- πΊπΈUnited States jcandan
I've pushed a couple of commits to the fork (noting here in case someone overrides):
I am still working through some issues:
- I think I need to prevent error message removal when the condition is not met in
\Drupal\conditional_fields\ConditionalFieldsFormHelper::formValidate()
. - It seems the dependentValidate() thinks the condition is "triggered" when it is not.
- The
dependentValidate()
also seems to be explicitly handlingrequired
and!required
. - Not yet sure if it is best to pass the _wrapper in the error key.
- I think I need to prevent error message removal when the condition is not met in
- πΊπΈUnited States jcandan
Fork description
So that the module doesn't depend on Conditional Fields, the logic is provided in a submodule. When enabled, it provides
require_on_publish
as one of the possible#states
.Steps to reproduce
Using the provided fork, you may begin to understand how this might work.
- Install Require on Publish and Conditional Fields.
- Add a boolean field to Basic Page, and a text field.
- Under Structure > Conditional Fields, make the text field required on publish when the boolean field is checked.
- Create a Basic Page.
With the above and the branch as it stands, the required on publish markings are successfully applied. However, the error handling still needs work.
Problems persist
See comment above and comments in code for an understanding of the ongoing problems.
- πΊπΈUnited States jcandan
By adding full support for #states Form API conditions, integration with Conditional Fields β is possible with:
use Drupal\Core\Form\FormStateInterface; /** * Implements hook_conditionalFieldsStates_alter(). * * @see Drupal\conditional_fields\Conditions::conditionalFieldsState * @phpcs:disable Drupal.NamingConventions.ValidFunctionName.InvalidName */ function require_on_publish_conditional_conditionalFieldsStates_alter(array &$states) { // phpcs:enable // A list of supported states that may be applied to a conditional field. $states['require_on_publish'] = t('Required on Publish'); }
- Merge request !24Issue #3530547: Add require on publish #states Form API handling β (Open) created by jcandan