Uploaded image for project: 'phpBB3'
  1. phpBB3
  2. PHPBB3-10910

function build_cfg_template() allow $size for $tpl_type = select

    Details

    • Type: Improvement
    • Status: Unverified Fix
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 3.0.10
    • Fix Version/s: 3.1.0-a3
    • Component/s: ACP
    • Labels:
      None

      Description

      I think it would be nice to be able to use the variable $size when the switch $tpl_type = 'select'

      Open "/adm/index.php"

      Find

      $tpl = '<select id="' . $key . '" name="' . $name . '">' . $return . '</select>';

      Replace by

      $size = (isset($tpl_type[1])) ? (int) $tpl_type[1] : 1;
       
      $tpl = '<select id="' . $key . '" name="' . $name . '"' . (($size) ? ' size="' . $size . '"' : '') . '>' . $return . '</select>';

      With this modification we can unselect a value without needed to create our own function for adding a choice like "No Value" or "None"

      How to use it ?

      In ACP file used the 'select' type as below :
      For example define the size to '8'

      $display_vars = array(
      	'title'	=> 'FOO_CONFIG',
      	'vars'	=> array(
      		'legend1'						=> 'FOO_SETTINGS',
      		'foo_group_id'	=> array('lang' => 'FOO_GROUP',		'validate' => 'int',	'type' => 'select:8', 'function' => 'group_select_options', 'params' => array('{CONFIG_VALUE}', false, false), 'explain' => true),
       
      		'legend4'				=> 'ACP_SUBMIT_CHANGES',
      	)
      );
      

      After, on submit, we check if no value is selected by using the following code

      // We go compare $display_vars with $cfg_array to determine if the type "select" does not have a choice selected.
      if ($submit)
      {
      	$display_vars_diff = array_diff_key($display_vars['vars'] , $cfg_array);
       
      	foreach ($display_vars_diff as $config_name_diff => $vars_diff)
      	{
      		if (strpos($vars_diff['type'], 'select') === false)
      		{
      			continue;
      		}
       
      		$cfg_array[$config_name_diff] = '';
      	}
      	unset($config_name_diff);
      }

        Activity

        Hide
        Skouat Skouat added a comment -

        add isset() for compatibility with select witch are not defined with size parameters.
        old:

        $size = (int) $tpl_type[1];

        new:

        $size = (isset($tpl_type[1])) ? (int) $tpl_type[1] : 1;

        Show
        Skouat Skouat added a comment - add isset() for compatibility with select witch are not defined with size parameters. old: $size = (int) $tpl_type[1]; new: $size = (isset($tpl_type[1])) ? (int) $tpl_type[1] : 1;
        Hide
        Skouat Skouat added a comment -

        Updating of main message by adding a "How to use"

        Show
        Skouat Skouat added a comment - Updating of main message by adding a "How to use"
        Hide
        nickvergessen Joas Schilling added a comment -

        In 3.1 the code is in includes/functions_acp.php

        Maybe you can set up a pull request against 3.1?

        Show
        nickvergessen Joas Schilling added a comment - In 3.1 the code is in includes/functions_acp.php Maybe you can set up a pull request against 3.1?

          People

          • Assignee:
            nickvergessen Joas Schilling
            Reporter:
            Skouat Skouat
          • Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development