Jump to content

add theme setting [node list]


Recommended Posts

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

Link to comment
Share on other sites


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

1659915793_Screenshot2023-07-06114336.png.012cd6880895869ed0e1df39c1271fc9.png

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 by Axen1
Link to comment
Share on other sites


  • Management

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! >

Link to comment
Share on other sites


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

1309771300_Screenshot2023-07-07130409.png.cc4cd775414b28ad33facd52a52933d4.png

Spoiler

1519195994_Screenshot2023-07-07131201.png.175866bc61ee8a3a3b9b48d07b16f41a.png

 

 

Link to comment
Share on other sites


  • Management

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.

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! >

Link to comment
Share on other sites


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.

Link to comment
Share on other sites


  • Management

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! >

Link to comment
Share on other sites


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 by Axen1
Link to comment
Share on other sites


  • Management

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! >

Link to comment
Share on other sites


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.

Link to comment
Share on other sites


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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and Privacy Policy.