Problem/Motivation

The Requires validation and Anonymous visibility are meant to be displayed only when the visibility of a learning path is Semi-private, on both add and edit forms. This works fine on the add form, but the edit form sometimes has a random suffix in the form ID.

Proposed resolution

Ensure that the #states conditions are always applied.

Remaining tasks

Review.

CommentFileSizeAuthor
#2 3245338-8.x-1.x.patch1.21 KBamateescu
#2 3245338-3.x.patch892 bytesamateescu

Comments

amateescu created an issue. See original summary.

amateescu’s picture

Status: Active » Needs review
StatusFileSize
new892 bytes
new1.21 KB

Here's a patch for both Opigno 2 and 3 branches.

catch’s picture

+++ b/opigno_learning_path.module
@@ -1285,10 +1286,11 @@ function opigno_learning_path_form_alter(&$form, FormStateInterface $form_state,
 
   // Set fields visibility dependencies.
-  if (in_array($form_id, [
-    'group_learning_path_add_form',
-    'group_learning_path_edit_form',
-  ])) {
+  $form_object = $form_state->getFormObject();
+  if ($form_object instanceof ContentEntityFormInterface
+    && $form_object->getBaseFormId() === 'group_form'

A few lines of logic could be saved by using hook_form_BASE_FORM_ID_alter().

https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Form%21fo...

Could be done in a follow-up - really the whole of opigno_learning_path_form_alter() should be split out into individual hook implementations.

catch’s picture

Status: Needs review » Reviewed & tested by the community

This works well so moving to RTBC.

I've also opened a follow-up to simplify the form selection logic as above #3245367: Split up opigno_learning_path_form_alter().

axelm’s picture

Status: Reviewed & tested by the community » Patch (to be ported)

Thanks !
It will be fixed in the next Opigno release

axelm’s picture

Status: Patch (to be ported) » Fixed

Released in Opigno 3.0.2

axelm’s picture

Status: Fixed » Closed (fixed)