Version 5.0.0 beta 1

This commit is contained in:
Neo committed 2025-12-19 16:27:35 -08:00
1 parent 25ddeb65d6
commit 15c7beabc5
6736 files changed
+627902 -497943

No files matched your search

+51 -28
View File
@@ -11,31 +11,38 @@
namespace IPS\Helpers\Form;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use IPS\Member;
use IPS\Request;
use IPS\Theme;
use function count;
use function defined;
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;
}
/**
* Checkbox Set class for Form Builder
*/
class _CheckboxSet extends Select
class CheckboxSet 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 )
{
$options['multiple'] = TRUE;
$options['showAllNone'] = $options['showAllNone'] ?? TRUE;
@@ -53,7 +60,7 @@ class _CheckboxSet extends Select
*
* @return string
*/
public function html()
public function html(): string
{
/* Get descriptions */
$descriptions = $this->options['descriptions'];
@@ -62,9 +69,9 @@ class _CheckboxSet extends Select
foreach ( $this->options['options'] as $k => $v )
{
$key = "{$v}_desc";
if ( \IPS\Member::loggedIn()->language()->checkKeyExists( $key ) )
if ( Member::loggedIn()->language()->checkKeyExists( $key ) )
{
$descriptions[ $k ] = \IPS\Member::loggedIn()->language()->addToStack( $key );
$descriptions[ $k ] = Member::loggedIn()->language()->addToStack( $key );
}
}
}
@@ -73,7 +80,7 @@ class _CheckboxSet extends Select
if ( $this->options['returnLabels'] )
{
$value = array();
if ( !\is_array( $this->value ) )
if ( !is_array( $this->value ) )
{
$this->value = explode( ',', $this->value );
}
@@ -89,12 +96,12 @@ class _CheckboxSet extends Select
/* If the value is NULL or an empty string, i.e. from a custom field, then we should not convert it into an array because the
value will evaluate to 0 with an == check and the first option in the checkbox set will always be selected erroneously */
if ( $this->options['unlimited'] === NULL and !\is_array( $value ) AND $value !== NULL AND $value !== '' )
if ( $this->options['unlimited'] === NULL and !is_array( $value ) AND $value !== NULL AND $value !== '' )
{
$value = array( $value );
}
return \IPS\Theme::i()->getTemplate( 'forms', 'core', 'global' )->checkboxset( $this->name, $value, $this->required, $this->parseOptions(), $this->options['multiple'], $this->options['class'], $this->options['disabled'], $this->options['toggles'], NULL, $this->options['unlimited'], $this->options['unlimitedLang'], $this->options['unlimitedToggles'], $this->options['unlimitedToggleOn'], $descriptions, $this->options['impliedUnlimited'], $this->options['showAllNone'], $this->options['condense'] );
return Theme::i()->getTemplate( 'forms', 'core', 'global' )->checkboxset( $this->name, $value, $this->required, $this->parseOptions(), $this->options['multiple'], $this->options['class'], $this->options['disabled'], $this->options['toggles'], NULL, $this->options['unlimited'], $this->options['unlimitedLang'], $this->options['unlimitedToggles'], $this->options['unlimitedToggleOn'], $descriptions, $this->options['impliedUnlimited'], $this->options['showAllNone'], $this->options['condense'], $this->options['userSuppliedInput'] );
}
/**
@@ -102,10 +109,10 @@ class _CheckboxSet extends Select
*
* @return array
*/
public function getValue()
public function getValue(): mixed
{
$value = parent::getValue();
if ( $this->options['unlimited'] !== NULL and $value === $this->options['unlimited'] )
{
return $value;
@@ -113,30 +120,46 @@ class _CheckboxSet extends Select
/* We need the array keys. For custom fields we will have 0 => 1, 1 => 1 if checkboxes 0 and 1 are checked, while for Content we will have
customKey => 1, customOtherKey => 1 - we always need the array keys */
$value = \is_array( $value ) ? array_keys( $value ) : array();
$value = is_array( $value ) ? array_keys( $value ) : array();
if ( $this->options['unlimited'] !== NULL and $this->options['impliedUnlimited'] and \count( $value ) == \count( $this->options['options'] ) )
if ( $this->options['unlimited'] !== NULL and $this->options['impliedUnlimited'] and count( $value ) == count( $this->options['options'] ) )
{
return $this->options['unlimited'];
}
$return = array();
if ( $this->options['returnLabels'] )
{
if ( \is_array( $value ) )
if ( is_array( $value ) )
{
$return = array();
foreach ( $value as $k => $v )
{
$return[ $k ] = $this->options['options'][ $v ];
}
return $return;
}
else
{
return $this->options['options'][ $value ];
$return[] = $this->options['options'][ $value ];
}
}
else
{
$return = $value;
}
return $value;
/* User-supplied input */
if( isset( $this->options['userSuppliedInput'] ) AND $this->options['userSuppliedInput'] AND in_array( $this->options['userSuppliedInput'], $value ) )
{
$otherTextField = $this->options['userSuppliedInput'] . '_' . $this->name;
$index = array_search( $this->options['userSuppliedInput'], $return );
if( $index !== false )
{
unset( $return[ $index ] );
}
$return[] = Request::i()->$otherTextField;
}
return $return;
}
}