ArashDev Posted July 5, 2023 Posted July 5, 2023 hi I use the following code in theme setting for selecting forums: <?php $custom1_id = new \IPS\Helpers\Form\Node("core_theme_setting_title_{$row['sc_id']}", $value, FALSE, array( 'class' => 'IPS\forums\Forum', 'multiple' => TRUE, 'permissionCheck' => function($forum) { if ($forum->parent_id == -1) { return true; } return null; } ), NULL, NULL, NULL, 'theme_setting_' . $row['sc_key']); return $custom1_id; I want to use the same method, where the user can only select sub-forums. so I used the following code for this purpose, but it displays not only the sub-forums but also the sub-forums categories. <?php $custom1_id = new \IPS\Helpers\Form\Node("core_theme_setting_title_{$row['sc_id']}", $value, FALSE, array( 'class' => 'IPS\forums\Forum', 'multiple' => TRUE, 'permissionCheck' => function($node) { return $node; } ), NULL, NULL, NULL, 'theme_setting_' . $row['sc_key']); return $custom1_id; please help me
Management terabyte Posted July 5, 2023 Management Posted July 5, 2023 It will still display all categories. The most you can do is disable them from being selectable. Would that work? ArashDev 1 Board Rules - Available Products - Need a Custom Work? < Don't PM me for support, post in the forum or submit a ticket from the client area instead! >
ArashDev Posted July 6, 2023 Author Posted July 6, 2023 (edited) 13 hours ago, terabyte said: The most you can do is disable them from being selectable. Would that work? actually I didn't try this and I don't know how to do. can you help me? Spoiler if you look at the picture I disabled parents with below code but I want sub categories for support not be selectable <?php $custom1_id = new \IPS\Helpers\Form\Node("core_theme_setting_title_{$row['sc_id']}", $value, FALSE, array( 'class' => 'IPS\forums\Forum', 'multiple' => TRUE, 'permissionCheck' => function($node) { if ($node->parent_id == -1) { return false; } return $node; } ), NULL, NULL, NULL, 'theme_setting_' . $row['sc_key']); return $custom1_id; Edited July 6, 2023 by Axen1
Management terabyte Posted July 6, 2023 Management Posted July 6, 2023 Just to double-check, do you want all subforums to be disabled? You mentioned support in your reply. As an example let's say ticket has also subforums, in that case you'd like to block that, too? If that's indeed what you're trying to do, than replace the code in your permissionCheck callback function with this: if ( $node->parent_id == -1 OR $node->hasChildren() ) { return false; } return true; Instead, if you want to block all forums where you cannot post, regardless of their subforum status, you can use this check instead: if ( !$node->sub_can_post ) { return false; } return true; In any case, replace the return call at the end to return TRUE rather than the $node variable. Board Rules - Available Products - Need a Custom Work? < Don't PM me for support, post in the forum or submit a ticket from the client area instead! >
ArashDev Posted July 7, 2023 Author Posted July 7, 2023 17 hours ago, terabyte said: do you want all subforums to be disabled? You mentioned support in your reply. As an example let's say ticket has also subforums, in that case you'd like to block that, too? I apologize for my weak English skills. No. What I want is for the user to be able to select only the main subforums, and if a subforum has its own subforums, those subforums should not be selectable. For example, in the image below, I want the "Support" to be selected when clicked, but its subforums should not be displayed, as I don't want to confuse the user. Spoiler Spoiler
Management terabyte Posted July 7, 2023 Management Posted July 7, 2023 Ah, okay, so you want to make all forums with a root parent selectable instead. Using a Node helper the other forums will still show though, the only thing you can do is make them unselectable (similar to the code in your first post): if ( $node->parent_id == -1 ) { return false; } return true; If you don't want the other subforums (test 1, test 2, test 3, etc) to show in the list you need to switch to a Select helper instead, and then manually build the list of forums. That way you can completely skip any subforums from showing. ArashDev 1 Board Rules - Available Products - Need a Custom Work? < Don't PM me for support, post in the forum or submit a ticket from the client area instead! >
ArashDev Posted July 7, 2023 Author Posted July 7, 2023 3 hours ago, terabyte said: If you don't want the other subforums (test 1, test 2, test 3, etc) to show in the list you need to switch to a Select helper instead, and then manually build the list of forums. That way you can completely skip any subforums from showing. can you give me a code for this? 3 hours ago, terabyte said: if ( $node->parent_id == -1 ) { return false; } return true; I have previously tested this code, but it did not give me the desired output.
Management terabyte Posted July 7, 2023 Management Posted July 7, 2023 It's the same code in the first codebox of your first reply (with only the second return statement changed): $custom1_id = new \IPS\Helpers\Form\Node("core_theme_setting_title_{$row['sc_id']}", $value, FALSE, array( 'class' => 'IPS\forums\Forum', 'multiple' => TRUE, 'permissionCheck' => function($node) { if ( $node->parent_id == -1 ) { return false; } return true; } ), NULL, NULL, NULL, 'theme_setting_' . $row['sc_key']); With it, the other (sub)forums will still display in the list but you shouldn't be able to select them. Board Rules - Available Products - Need a Custom Work? < Don't PM me for support, post in the forum or submit a ticket from the client area instead! >
ArashDev Posted July 7, 2023 Author Posted July 7, 2023 (edited) thanks for your effort but your code doesn't return a field object. setting page give an error and say: " Your code is invalid or does not return a field object." Edited July 7, 2023 by Axen1
Management terabyte Posted July 7, 2023 Management Posted July 7, 2023 The code above only generates the field, you still need to add it to the form: $form->add( $custom1_id ); I see you actually have a return at the end in your first post, and it seems the code is inside a custom PHP file? return $custom1_id; I've never really worked with theme settings, so I'm unsure how they're usually setup. Board Rules - Available Products - Need a Custom Work? < Don't PM me for support, post in the forum or submit a ticket from the client area instead! >
ArashDev Posted July 7, 2023 Author Posted July 7, 2023 13 minutes ago, terabyte said: I see you actually have a return at the end in your first post, and it seems the code is inside a custom PHP file? yes my lord! 13 minutes ago, terabyte said: I've never really worked with theme settings, so I'm unsure how they're usually setup. hmmm! However, I thank you nonetheless. If I cannot find a solution, I will have to resort to providing a description below the field, instructing users to only select the main forum.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now