Version 5.0.6
This commit is contained in:
1 parent
a3a4a9ccbd
commit
b89858b2ff
1214 files changed
+92828
-14859
No files matched your search
+25
-12
@@ -13,8 +13,8 @@ namespace IPS\Content;
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
|
||||
use Exception;
|
||||
use IPS\Node\CustomBadge;
|
||||
use IPS\Platform\Bridge;
|
||||
use IPS\core\CustomBadge;
|
||||
use IPS\Data\Store;
|
||||
use IPS\Db;
|
||||
use IPS\File;
|
||||
@@ -43,6 +43,8 @@ if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
*/
|
||||
class Reaction extends Model
|
||||
{
|
||||
use CustomBadge;
|
||||
|
||||
/**
|
||||
* @brief Database Table
|
||||
*/
|
||||
@@ -103,6 +105,18 @@ class Reaction extends Model
|
||||
*/
|
||||
public static array $icons = array();
|
||||
|
||||
/**
|
||||
* @brief Disable the number overlay for custom badges
|
||||
*/
|
||||
public static bool $customBadgeNumberOverlay = false;
|
||||
|
||||
/**
|
||||
* @brief Toggle off these fields when generating a custom badge
|
||||
*
|
||||
* @var array|string[]
|
||||
*/
|
||||
public static array $customBadgeToggles = [ 'reaction_icon' ];
|
||||
|
||||
/**
|
||||
* Form
|
||||
*
|
||||
@@ -111,10 +125,14 @@ class Reaction extends Model
|
||||
*/
|
||||
public function form( Form &$form ): void
|
||||
{
|
||||
/* Allow SVGs without the obscure hash removing the file extension */
|
||||
File::$safeFileExtensions[] = 'svg';
|
||||
|
||||
$form->add( new Translatable( 'reaction_title', NULL, TRUE, array( 'app' => 'core', 'key' => ( $this->id ? 'reaction_title_' . $this->id : NULL ) ) ) );
|
||||
$form->add( new Radio( 'reaction_value', $this->id ? $this->value : 1, TRUE, array( 'options' => array( 1 => 'positive', 0 => 'neutral', -1 => 'negative' ) ) ) );
|
||||
CustomBadge::getRecordBadge( $this )
|
||||
->addBadgeFieldsToForm( $form, (bool) $this->use_custom, ['reaction_icon'], includeNumberOverlay: false );
|
||||
|
||||
parent::form( $form );
|
||||
|
||||
$form->add( new Upload( 'reaction_icon', $this->id ? File::get( 'core_Reaction', (string) $this->icon ) : NULL, false, array( 'image' => TRUE, 'storageExtension' => 'core_Reaction', 'storageContainer' => 'reactions', 'obscure' => FALSE ), null, null, null, 'reaction_icon' ) );
|
||||
}
|
||||
|
||||
@@ -131,12 +149,7 @@ class Reaction extends Model
|
||||
$this->save();
|
||||
}
|
||||
|
||||
if ( array_key_exists( 'badge_use_custom', $values ) )
|
||||
{
|
||||
$values['use_custom'] = $values['badge_use_custom'];
|
||||
}
|
||||
|
||||
CustomBadge::saveRecordBadge( $this, CustomBadge::generateBadgeFromFormValues( $values ) );
|
||||
$values['use_custom'] = ( isset( $values['custombadge_use_custom'] ) and $values['custombadge_use_custom'] );
|
||||
|
||||
Lang::saveCustom( 'core', 'reaction_title_' . $this->id, $values['reaction_title'] );
|
||||
unset( $values['reaction_title'] );
|
||||
@@ -240,12 +253,12 @@ class Reaction extends Model
|
||||
*/
|
||||
public function get__icon(): mixed
|
||||
{
|
||||
if ( !isset( static::$icons[ $this->id ] ) )
|
||||
if( $this->use_custom and $badge = $this->getRecordBadge() )
|
||||
{
|
||||
static::$icons[ $this->id ] = $this->use_custom ? CustomBadge::getRecordBadge( $this )->url() : File::get( 'core_Reaction', $this->_data['icon'] );
|
||||
return $badge->file()?->url;
|
||||
}
|
||||
|
||||
return static::$icons[ $this->id ];
|
||||
return File::get( 'core_Reaction', $this->_data['icon'] );
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user