Version 5.0.0 beta 1
This commit is contained in:
1 parent
25ddeb65d6
commit
15c7beabc5
6736 files changed
+627902
-497943
No files matched your search
@@ -11,31 +11,41 @@
|
||||
namespace IPS\Helpers\Form;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use InvalidArgumentException;
|
||||
use IPS\Member;
|
||||
use IPS\Request;
|
||||
use IPS\Theme;
|
||||
use LogicException;
|
||||
use OutOfRangeException;
|
||||
use function defined;
|
||||
use function in_array;
|
||||
use function is_array;
|
||||
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Radio Switch class for Form Builder
|
||||
*/
|
||||
class _Radio extends Select
|
||||
class Radio extends Select
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param string $name Name
|
||||
* @param mixed $defaultValue Default value
|
||||
* @param bool|NULL $required Required? (NULL for not required, but appears to be so)
|
||||
* @param array $options Type-specific options
|
||||
* @param callback $customValidationCode Custom validation code
|
||||
* @param string $prefix HTML to show before input field
|
||||
* @param string $suffix HTML to show after input field
|
||||
* @param string $id The ID to add to the row
|
||||
* @return void
|
||||
* @param string $name Name
|
||||
* @param mixed $defaultValue Default value
|
||||
* @param bool|NULL $required Required? (NULL for not required, but appears to be so)
|
||||
* @param array $options Type-specific options
|
||||
* @param callable|null $customValidationCode Custom validation code
|
||||
* @param string|null $prefix HTML to show before input field
|
||||
* @param string|null $suffix HTML to show after input field
|
||||
* @param string|null $id The ID to add to the row
|
||||
*/
|
||||
public function __construct( $name, $defaultValue=NULL, $required=FALSE, $options=array(), $customValidationCode=NULL, $prefix=NULL, $suffix=NULL, $id=NULL )
|
||||
public function __construct( string $name, mixed $defaultValue=NULL, ?bool $required=FALSE, array $options=array(), callable $customValidationCode=NULL, string $prefix=NULL, string $suffix=NULL, string $id=NULL )
|
||||
{
|
||||
parent::__construct( $name, $defaultValue, $required, $options, $customValidationCode, $prefix, $suffix, $id );
|
||||
|
||||
@@ -51,7 +61,7 @@ class _Radio extends Select
|
||||
/* If you haven't selected any radio options, then there is no input and the required flag is never checked (validate() is never called) */
|
||||
$_key = "radio_" . $this->name . "__empty";
|
||||
|
||||
if( isset( \IPS\Request::i()->$_key ) )
|
||||
if( isset( Request::i()->$_key ) )
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -60,7 +70,7 @@ class _Radio extends Select
|
||||
$this->value = $this->formatValue();
|
||||
$this->validate();
|
||||
}
|
||||
catch ( \LogicException $e )
|
||||
catch ( LogicException $e )
|
||||
{
|
||||
$this->error = $e->getMessage();
|
||||
}
|
||||
@@ -72,7 +82,7 @@ class _Radio extends Select
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function html()
|
||||
public function html(): string
|
||||
{
|
||||
$descriptions = $this->options['descriptions'];
|
||||
$warnings = $this->options['warnings'];
|
||||
@@ -80,9 +90,9 @@ class _Radio extends Select
|
||||
{
|
||||
foreach ( $this->options['options'] as $k => $v )
|
||||
{
|
||||
$descriptions[ $k ] = \IPS\Member::loggedIn()->language()->addToStack( "{$v}_desc", FALSE, array( 'returnBlank' => TRUE, 'returnInto' => \IPS\Theme::i()->getTemplate( 'forms', 'core', 'global' )->rowDesc( NULL, NULL ), $this, NULL ) );
|
||||
$descriptions[ $k ] = Member::loggedIn()->language()->addToStack( "{$v}_desc", FALSE, array( 'returnBlank' => TRUE, 'returnInto' => Theme::i()->getTemplate( 'forms', 'core', 'global' )->rowDesc( NULL, NULL ), $this, NULL ) );
|
||||
|
||||
$warnings[ $k ] = \IPS\Member::loggedIn()->language()->addToStack( "{$v}_warning", FALSE, array( 'returnBlank' => TRUE, 'returnInto' => \IPS\Theme::i()->getTemplate( 'forms', 'core', 'global' )->rowWarning( NULL, NULL, FALSE, NULL, NULL, NULL, $this->name . '_' . $k ), $this, NULL ) );
|
||||
$warnings[ $k ] = Member::loggedIn()->language()->addToStack( "{$v}_warning", FALSE, array( 'returnBlank' => TRUE, 'returnInto' => Theme::i()->getTemplate( 'forms', 'core', 'global' )->rowWarning( NULL, NULL, FALSE, NULL, NULL, NULL, $this->name . '_' . $k ), $this, NULL ) );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,25 +112,25 @@ class _Radio extends Select
|
||||
|
||||
if ( $this->options['parse'] === 'image' )
|
||||
{
|
||||
return \IPS\Theme::i()->getTemplate( 'forms', 'core', 'global' )->radioImages( $this->name, $value, $this->required, $this->options['options'], $this->options['disabled'], $this->options['toggles'], $descriptions, $warnings, $this->options['userSuppliedInput'], $this->options['unlimited'], $this->options['unlimitedLang'], $this->htmlId, $this->options['gridspan'] );
|
||||
return Theme::i()->getTemplate( 'forms', 'core', 'global' )->radioImages( $this->name, $value, $this->required, $this->options['options'], $this->options['disabled'], $this->options['toggles'], $descriptions, $warnings, $this->options['userSuppliedInput'], $this->options['unlimited'], $this->options['unlimitedLang'], $this->htmlId, $this->options['gridspan'] );
|
||||
}
|
||||
else
|
||||
{
|
||||
return \IPS\Theme::i()->getTemplate( 'forms', 'core', 'global' )->radio( $this->name, $value, $this->required, $this->parseOptions(), $this->options['disabled'], $this->options['toggles'], $descriptions, $warnings, $this->options['userSuppliedInput'], $this->options['unlimited'], $this->options['unlimitedLang'], $this->htmlId );
|
||||
return Theme::i()->getTemplate( 'forms', 'core', 'global' )->radio( $this->name, $value, $this->required, $this->parseOptions(), $this->options['disabled'], $this->options['toggles'], $descriptions, $warnings, $this->options['userSuppliedInput'], $this->options['unlimited'], $this->options['unlimitedLang'], $this->htmlId );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate
|
||||
*
|
||||
* @throws \OutOfRangeException
|
||||
* @throws OutOfRangeException
|
||||
* @return TRUE
|
||||
*/
|
||||
public function validate()
|
||||
public function validate(): bool
|
||||
{
|
||||
if( $this->value === null and $this->required )
|
||||
{
|
||||
throw new \InvalidArgumentException('form_required');
|
||||
throw new InvalidArgumentException('form_required');
|
||||
}
|
||||
/* Field is not required and value was not supplied */
|
||||
else if( $this->value === null )
|
||||
@@ -136,12 +146,12 @@ class _Radio extends Select
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getValue()
|
||||
public function getValue(): mixed
|
||||
{
|
||||
$value = parent::getValue();
|
||||
|
||||
/* Disabled radio fields do not submit a value to the server */
|
||||
if( $this->options['disabled'] === TRUE or ( \is_array( $this->options['disabled'] ) and \in_array( $value, $this->options['disabled'] ) ) )
|
||||
if( $this->options['disabled'] === TRUE or ( is_array( $this->options['disabled'] ) and in_array( $value, $this->options['disabled'] ) ) )
|
||||
{
|
||||
return $this->defaultValue;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user