1
0
mirror of https://github.com/e107inc/e107.git synced 2025-01-17 04:38:27 +01:00

Keep button class in a logical order e107::getForm()->button(); and admin_button() modified. Test added.

'button' has been removed when the action == 'button' in order to avoid BC css conflict. Use button[type="button"] if needed.
This commit is contained in:
Cameron 2021-01-28 09:36:27 -08:00
parent cdcd2d33d2
commit 296bc650a7
3 changed files with 89 additions and 18 deletions

View File

@ -189,7 +189,9 @@ class e_chart
if(!empty($type))
{
$this->provider = $type;
}
}
return $this;
}
public function getProvider()

View File

@ -69,7 +69,7 @@ class e_form
protected $_field_warnings = array();
private $_inline_token;
public $_snippets = false; // use snippets or not. - experimental, and may be removed - use at own risk.
private $_fontawesome = false;
/**
* @var user_class
*/
@ -89,6 +89,11 @@ class e_form
{
$this->_snippets = true;
}
if(deftrue('FONTAWESOME'))
{
$this->_fontawesome = true;
}
}
/**
@ -3618,7 +3623,7 @@ var_dump($select_options);*/
$opt = array();
$homeicon = (deftrue('FONTAWESOME')) ? 'fa-home' : 'icon-home.glyph';
$homeicon = ($this->_fontawesome) ? 'fa-home' : 'icon-home.glyph';
$homeIcon = e107::getParser()->toGlyph($homeicon,false);
@ -3690,7 +3695,7 @@ var_dump($select_options);*/
public function admin_button($name, $value, $action = 'submit', $label = '', $options = array())
{
$btype = 'submit';
if(strpos($action, 'action') === 0)
if(strpos($action, 'action') === 0 || $action === 'button')
{
$btype = 'button';
}
@ -3702,8 +3707,7 @@ var_dump($select_options);*/
}
else
{
// $include = (deftrue("FONTAWESOME")) ? "data-loading-icon='fa-spinner' data-disable='true'" : "";
$include = (deftrue('FONTAWESOME')) ? "data-loading-icon='fa-spinner' " : ''; // data-disable breaks db.php charset Fix.
$include = ($this->_fontawesome) ? "data-loading-icon='fa-spinner'" : ''; // data-disable breaks db.php charset Fix.
}
$confirmation = LAN_JSCONFIRM;
@ -3715,19 +3719,27 @@ var_dump($select_options);*/
$options = $this->format_options('admin_button', $name, $options);
$options['class'] = vartrue($options['class']);
$options['class'] .= ' btn ' . $action;
$class = 'btn';
$class .= (!empty($action) && $action !== 'button') ? ' '. $action : '';
if(!empty($options['class']))
{
$class .= ' '.$options['class'];
}
// Ability to use any kind of button class for the selected action.
if(!$this->defaultButtonClassExists($class))
{
$class .= ' ' . $this->getDefaultButtonClassByAction($action);
}
$options['class'] = $class;
if(empty($label))
{
$label = $value;
}
// Ability to use any kind of button class for the selected action.
if (!$this->defaultButtonClassExists($options['class']))
{
$options['class'] .= ' ' . $this->getDefaultButtonClassByAction($action);
}
switch ($action)
{
@ -3766,7 +3778,7 @@ var_dump($select_options);*/
* @return bool
* True if $class already contains a button class. Otherwise false.
*/
public function defaultButtonClassExists($class = '')
private function defaultButtonClassExists($class = '')
{
// Bootstrap button classes.
// @see http://getbootstrap.com/css/#buttons-options
@ -3780,7 +3792,8 @@ var_dump($select_options);*/
'btn-link',
);
foreach($btnClasses as $btnClass) {
foreach($btnClasses as $btnClass)
{
if(strpos($class, $btnClass) !== false)
{
return true;
@ -3804,7 +3817,7 @@ var_dump($select_options);*/
* @return string $class
* Default button class.
*/
public function getDefaultButtonClassByAction($action)
private function getDefaultButtonClassByAction($action)
{
switch($action)
{

View File

@ -702,12 +702,68 @@ class e_formTest extends \Codeception\Test\Unit
{
}
*/
public function testButton()
{
$tests = array(
0 => array(
'name' => 'form_button',
'value' => 'go',
'action' => 'button',
'label' => '',
'options' => array('class' => 'btn-primary custom-class', 'data-my-value' => '1323')
),
1 => array(
'name' => 'form_update',
'value' => '1',
'action' => 'update',
'label' => '',
'options' => array('class' => 'btn-custom', 'data-my-value' => '365')
),
2 => array(
'name' => 'form_noaction',
'value' => 'go',
'action' => null,
'label' => '',
'options' => array( 'data-my-value' => '365')
),
3 => array(
'name' => 'form_checkall',
'value' => 1,
'action' => 'checkall',
'label' => 'Check All',
'options' => array( 'data-my-value' => '365')
),
4 => array(
'name' => 'form_submit',
'value' => 'My Label',
'action' => '',
'label' => '',
'options' => array('loading'=>false)
),
);
$expected = array (
0 => "<button data-loading-icon='fa-spinner' type='button' name='form_button' value='go' id='form-button' class='btn btn-primary custom-class' data-my-value='1323'><span>go</span></button>",
1 => "<button data-loading-icon='fa-spinner' type='submit' name='form_update' value='1' id='form-update' class='btn update btn-custom btn-success' data-my-value='365'><span>1</span></button>",
2 => "<button data-loading-icon='fa-spinner' type='submit' name='form_noaction' value='go' id='form-noaction' class='btn btn-default' data-my-value='365'><span>go</span></button>",
3 => "<button data-loading-icon='fa-spinner' type='submit' name='form_checkall' value='1' id='form-checkall' class='btn checkall btn-default btn-mini btn-xs' data-my-value='365'><span>Check All</span></button>",
4 => "<button type='submit' name='form_submit' value='My Label' id='form-submit' class='btn btn-default'><span>My Label</span></button>",
);
// $ret = [];
foreach($tests as $index => $var)
{
$result = $this->_frm->button($var['name'], $var['value'], $var['action'], $var['label'], $var['options']);
$this->assertSame($expected[$index],$result, "Mismatch on #".$index);
// $ret[] = $result;
}
// var_export($ret);
}
/*
public function testBreadcrumb()
{