Collapse navlink config under heading in backend

Skinning and designing Serendipity (CSS, HTML, Smarty)
Timbalu
Regular
Posts: 4598
Joined: Sun May 02, 2004 3:04 pm

Re: Collapse navlink config under heading in backend

Post by Timbalu »

Please help me on the way.... which example do you mean?
That said, I still need a dump of your option table, or the full template_loaded_config array, to see what I can do about it, if... is an existing heading such as 'My Heading' => array('colorset', 'userstylesheet', etc.....) part of it?
Regards,
Ian

Serendipity Styx Edition and additional_plugins @ https://ophian.github.io/ @ https://github.com/ophian
Don Chambers
Regular
Posts: 3652
Joined: Mon Feb 13, 2006 2:40 am
Location: Chicago, IL, USA
Contact:

Re: Collapse navlink config under heading in backend

Post by Don Chambers »

This was a hypothetical question. Currently, we can group multiple options under a collapsible heading by either specifically listing them, like bulletproof does:

Code: Select all

    THEME_COLORSET  => array('colorset', 'userstylesheet', 'layouttype', 'jscolumns'),
or we can use your suggested method:

Code: Select all

    $new_tlc = array();
    $new_tlc = array_diff($template_loaded_config, $template_config);
    $navonly = array();
    foreach($new_tlc as $key=>$value)
    {
        if (preg_match('#^(amount)#', $key, $matches)===1 || preg_match('#^(navlink+)#', $key, $matches)===1) {
            $navonly[] = $key; 
        }
    }
    $template_config_groups = array(
        THEME_COLORSET  => array('colorset', 'userstylesheet', 'layouttype', 'jscolumns'),
        THEME_HEADER    => array('custheader', 'headerimage', 'headertype'),
        THEME_NAV       => $navonly
    );
This is not a good example, but what if I wanted to have a single heading that included specifically listed template options, ie 'colorset', 'userstylesheet', 'layouttype' AND the result of what is contained in $navonly. It would be the equivalent of:

Code: Select all

        if (preg_match('#^(amount)#', $key, $matches)===1 || preg_match('#^(navlink+)#', $key, $matches)===1 || preg_match('#^(colorset)#', $key, $matches)===1 || preg_match('#^(userstylesheet)#', $key, $matches)===1 || preg_match('#^(layouttype)#', $key, $matches)===1) {
Just wondered if there was a way to append the result of $navonly to the list other template options so they all collapse under a single header, but only the array items need to be processed through the logical condition. Hope that made sense.
=Don=
Timbalu
Regular
Posts: 4598
Joined: Sun May 02, 2004 3:04 pm

Re: Collapse navlink config under heading in backend

Post by Timbalu »

Sure you could do that, even if it meanwhile is getting somehow overcrowed and should get rewritten...

Would still be good to see a full var_export($template_loaded_config); array, to have a look what is currently available and what makes sense to pick up in a collapsable header group.

Btw, this extra old $new_tlc part is nonsense and not needed. (see my more straight second example)

... do you think of a single collapsing header like
'my nav header 1' ([0] => nav2link0sitenav2_amount
[1] => nav2link0target
[2] => nav2link0text
[3] => nav2link0url
[4] => nav2link0zsublink0target
[5] => nav2link0zsublink0text
[6] => nav2link0zsublink0url
[7] => nav2link0zsublink1target
[8] => nav2link0zsublink1text
[9] => nav2link0zsublink1url
[10] => nav2link0zsublink2target
[11] => nav2link0zsublink2text
[12] => nav2link0zsublink2url
[13] => nav2link0zsublink3target
[14] => nav2link0zsublink3text
[15] => nav2link0zsublink3url),

then a second header for the nav2link1 stuff, dito for nav2link2 stuff etc?
Regards,
Ian

Serendipity Styx Edition and additional_plugins @ https://ophian.github.io/ @ https://github.com/ophian
Don Chambers
Regular
Posts: 3652
Joined: Mon Feb 13, 2006 2:40 am
Location: Chicago, IL, USA
Contact:

Re: Collapse navlink config under heading in backend

Post by Don Chambers »

The idea to combine several template options is that some options are singular (ie, Show navbar? Location of navbar? Color of navbar? etc...) plus all the navigation links with their parameters, which is contained in $navonly. Imagine this:

+ Navigation options (collapsible header)
Show Navigation Bar? true/false
Location of navbar? select: Header/Footer
Some other option:_____________
Some other option:_____________
Some other option:_____________
Number of navigation links: 2

Navlink 0 configuration (this is where we need type: content)
Navlink text: ____________________________
Navlink url:______________________________
Navlink target: true/false
Number of sublinks: 3

Navlink 0, Sublink 0 configuration (this is where we need type: content)
Sublink text: ____________________________
Sublink url:______________________________
Sublink target: true/false

Navlink 0, Sublink 1 configuration (this is where we need type: content)
Sublink text: ____________________________
Sublink url:______________________________
Sublink target: true/false

Navlink 0, Sublink 2 configuration (this is where we need type: content)
Sublink text: ____________________________
Sublink url:______________________________
Sublink target: true/false

Navlink 2 configuration (this is where we need type: content)
Navlink text: ____________________________
Navlink url:______________________________
Navlink target: true/false
Number of sublinks: 0

So all of the above are contained in a single collapsible heading. The first few options are singular, not contained in an array, and ideally just listed explicitly, ie 'navbar_show', 'navbar_location', etc.... the other options are contained in your $navonly array. So is this possible? Can we combine template options that are explicitly specified, with those in an array, without going through a whole conditional test for each explicit template option ie

if (preg_match('#^(navbar_show)#', $key, $matches)===1 ||

What I am imaging is a scenario where there are several single template options that I want to combine with a fewer number of array items, and avoid a super long if THIS or THIS or THIS or THIS or THIS or THIS..... make sense?
=Don=
Timbalu
Regular
Posts: 4598
Joined: Sun May 02, 2004 3:04 pm

Re: Collapse navlink config under heading in backend

Post by Timbalu »

What you mean is to combine static $template_config items with the navonly header array? Yes!
Just add

Code: Select all

$navonly[] = $template_loaded_config['navbar_show'];
and so on.

I still see the requirement for a full

Code: Select all

var_export($template_loaded_config);
array.
Regards,
Ian

Serendipity Styx Edition and additional_plugins @ https://ophian.github.io/ @ https://github.com/ophian
Don Chambers
Regular
Posts: 3652
Joined: Mon Feb 13, 2006 2:40 am
Location: Chicago, IL, USA
Contact:

Re: Collapse navlink config under heading in backend

Post by Don Chambers »

Recap of issues so far:

1) To create these example navlinks, we iterate through one or more loops. When displaying content that is not collapsed, our template_config does this in the desired order, because our loop was defined in the desired order! However, when fetching it via a comparison to $template_loaded_config, we are returning values in the order they were saved. The only way to get any specific order is to play games with the selected variable names ie "zsublink" to make sure it is last.

2) I have also discovered that variables of type "content" do not get displayed at all, if they are part of the array, because they never exist in $template_loaded_config, and also because our usual $template_config loop is no longer displaying these items.

3) I wanted to add in "static" template options with those otherwise in an array, so they are displayed under a single collapsible heading.

So, how about this:

Code: Select all

$navonly3=array();
// add our static items to the array first, in the exact order we want them to appear
array_push($navonly3, 'sitenav3_toggle', 'sitenav3_amount');
// now add the dynamic items in exactly the order we want them to appear
for ($i = 0; $i < $template_loaded_config['sitenav3_amount']; $i++) {
	$navonly3[] =('navlink3' . $i . 'navlink_intro');
	$navonly3[] =('navlink3' . $i . 'text');
	$navonly3[] =('navlink3' . $i . 'url');
	$navonly3[] =('navlink3' . $i . 'target');
}
// we could add more static items here if we wanted
//array_push($navonly3, 'blah1', 'blah2');
//now contain our template options under a collapsible header
$template_config_groups = array(
    'Navigation Bar #3'       => $navonly3
)	
Opinions? Input? This does everything I need it to do. No game playing. No alphabetic issues. Mix & match static with array variables, and content types work as expected.

Ian's method is probably cleaner when there is no content types, no alphabetic issues, and no issue about the order options were saved in the database:

Code: Select all

$navonly3 = array();
foreach($template_loaded_config as $key=>$value) {
    if (preg_match('#^(sitenav3_toggle)#', $key, $matches)===1 || preg_match('#^(sitenav3_amount)#', $key, $matches)===1 || preg_match('#^(navlink3+)#', $key, $matches)===1) {
        $navonly3[] = $key; 
    }
}
$template_config_groups = array(
    'Navigation Bar #3'       => $navonly3
)
=Don=
Timbalu
Regular
Posts: 4598
Joined: Sun May 02, 2004 3:04 pm

Re: Collapse navlink config under heading in backend

Post by Timbalu »

Don Chambers wrote:Opinions? Input?
Sounds pretty good. That way avoids changing core functions somewhere, which is good!
What about the sort issue? Does the array itself has a natural order (print_r) or does it even display in natural order like you wish it to be? (As $array[] or array_push() usually append the vars to the end of that array.)

Possibly

Code: Select all

for ($i = 0; $i < $template_loaded_config['sitenav3_amount']; $i++) {
   $navonly3[] =('navlink3' . $i . 'navlink_intro');
   $navonly3[] =('navlink3' . $i . 'text');
   $navonly3[] =('navlink3' . $i . 'url');
   $navonly3[] =('navlink3' . $i . 'target');
}
could be rewritten to

Code: Select all

for ($i = 0; $i < $template_loaded_config['sitenav3_amount']; $i++) {
   array_push($navonly3, 'navlink3' . $i . 'navlink_intro', 'navlink3' . $i . 'text', 'navlink3' . $i . 'url', 'navlink3' . $i . 'target');
}
as well.
But as the docu says:
If you use array_push() to add one element to the array it's better to use $array[] = because in that way there is no overhead of calling a function.
You have to choose. :wink:
Regards,
Ian

Serendipity Styx Edition and additional_plugins @ https://ophian.github.io/ @ https://github.com/ophian
Don Chambers
Regular
Posts: 3652
Joined: Mon Feb 13, 2006 2:40 am
Location: Chicago, IL, USA
Contact:

Re: Collapse navlink config under heading in backend

Post by Don Chambers »

The reason for the method I have is I was only using a single item when I was testing this. But I think I will change to your suggested method. I may also relocate this code so that it occurs in the original loop defining the $template_options, so we don't need do the exact same loop twice, ie for ($i = 0; $i < $template_loaded_config['sitenav3_amount']; $i++)

This also works very well with the nested loop example we discussed via PM. Order is not a problem, because using this method, the new $navonly array is populated in exactly the order specified. If I want "text" to come before "sublink", I merely have to list them that way in the loop... I do not need do use any naming tricks, like "zsublink".
=Don=
Post Reply