N°2224 - Portal: Enable tooltips for object's attributes description

This commit is contained in:
Molkobain
2020-10-22 15:23:58 +02:00
parent f72ddd72f3
commit cfd9dba66e
9 changed files with 679 additions and 643 deletions

View File

@@ -37,6 +37,7 @@ abstract class Field
const ENUM_DISPLAY_MODE_DENSE = 'dense'; // Label and value side by side, closely
const DEFAULT_LABEL = '';
const DEFAULT_DESCRIPTION = '';
const DEFAULT_METADATA = array();
const DEFAULT_HIDDEN = false;
const DEFAULT_READ_ONLY = false;
@@ -48,6 +49,13 @@ abstract class Field
protected $sGlobalId;
protected $sFormPath;
protected $sLabel;
/**
* Description text of the field, typically to bring more information to the user on the field purpose
*
* @var string
* @since 3.0.0
*/
protected $sDescription;
protected $aMetadata;
protected $bHidden;
protected $bReadOnly;
@@ -71,6 +79,7 @@ abstract class Field
// No space in such an id, that could be used as a DOM node id
$this->sGlobalId = 'field_' . str_replace(' ', '_', $sId) . '_' . uniqid();
$this->sLabel = static::DEFAULT_LABEL;
$this->sDescription = static::DEFAULT_DESCRIPTION;
$this->aMetadata = static::DEFAULT_METADATA;
$this->bHidden = static::DEFAULT_HIDDEN;
$this->bReadOnly = static::DEFAULT_READ_ONLY;
@@ -121,6 +130,28 @@ abstract class Field
return $this->sLabel;
}
/**
* Return true if the field has a description. Note that an empty string is equivalent to no description.
*
* @see static::$sDescription
* @return bool
* @since 3.0.0
*/
public function HasDescription(): bool
{
return empty($this->sDescription) === false;
}
/**
* @see static::$sDescription
* @return string
* @since 3.0.0
*/
public function GetDescription(): string
{
return $this->sDescription;
}
/**
* Return an array of $sName => $sValue metadata.
*
@@ -248,6 +279,19 @@ abstract class Field
return $this;
}
/**
* @param string $sDescription
* @see static::$sDescription
*
* @return $this
* @since 3.0.0
*/
public function SetDescription(string $sDescription)
{
$this->sDescription = $sDescription;
return $this;
}
/**
* Must be an array of $sName => $sValue metadata.
*