N°6179 - Tooltip attribute in field component (in Twig) (#478)

N°6179 - Tooltip attribute in field component (in Twig) (#478)
This commit is contained in:
jf-cbd
2023-04-19 11:02:47 +02:00
committed by GitHub
parent 866a09e0c8
commit e436f9bf8d
3 changed files with 48 additions and 3 deletions

View File

@@ -9,6 +9,7 @@ namespace Combodo\iTop\Application\UI\Base\Component\Field;
use Combodo\iTop\Application\UI\Base\Layout\UIContentBlock; use Combodo\iTop\Application\UI\Base\Layout\UIContentBlock;
use Combodo\iTop\Application\UI\Base\UIBlock; use Combodo\iTop\Application\UI\Base\UIBlock;
use utils;
/** /**
* @since 3.0.0 * @since 3.0.0
@@ -45,6 +46,11 @@ class Field extends UIContentBlock
protected $sValueRaw; protected $sValueRaw;
/** @var string */ /** @var string */
protected $sLabel; protected $sLabel;
/**
* @var string
* @since 3.1.0
*/
protected $sDescription = '';
/** @var string */ /** @var string */
protected $sValueId; protected $sValueId;
@@ -354,4 +360,34 @@ class Field extends UIContentBlock
return $this; return $this;
} }
/**
* @return string
* @since 3.1.0
*/
public function GetDescription(): string
{
return $this->sDescription;
}
/**
* @param string $sDescription
*
* @return $this
* @since 3.1.0
*/
public function SetDescription(string $sDescription)
{
$this->sDescription = $sDescription;
return $this;
}
/*
* @return bool
* @since 3.1.0
*/
public function HasDescription(): bool
{
return utils::IsNotNullOrEmptyString($this->GetDescription());
}
} }

View File

@@ -105,12 +105,14 @@ class FieldUIBlockFactory extends AbstractUIBlockFactory
* @api * @api
* @param string $sLabel * @param string $sLabel
* @param string $sValueHtml * @param string $sValueHtml
* @param string $sDescription
* *
* @return \Combodo\iTop\Application\UI\Base\Component\Field\Field * @return \Combodo\iTop\Application\UI\Base\Component\Field\Field
*/ */
public static function MakeLarge(string $sLabel, string $sValueHtml = '') public static function MakeLarge(string $sLabel, string $sValueHtml = '', string $sDescription = '')
{ {
$oField = new Field($sLabel, new Html($sValueHtml)); $oField = new Field($sLabel, new Html($sValueHtml));
$oField->SetDescription($sDescription);
$oField->SetLayout(Field::ENUM_FIELD_LAYOUT_LARGE); $oField->SetLayout(Field::ENUM_FIELD_LAYOUT_LARGE);
return $oField; return $oField;
} }
@@ -119,12 +121,14 @@ class FieldUIBlockFactory extends AbstractUIBlockFactory
* @api * @api
* @param string $sLabel * @param string $sLabel
* @param string $sValueHtml * @param string $sValueHtml
* @param string $sDescription
* *
* @return \Combodo\iTop\Application\UI\Base\Component\Field\Field * @return \Combodo\iTop\Application\UI\Base\Component\Field\Field
*/ */
public static function MakeSmall(string $sLabel, string $sValueHtml = '') public static function MakeSmall(string $sLabel, string $sValueHtml = '', string $sDescription = '')
{ {
$oField = new Field($sLabel, new Html($sValueHtml)); $oField = new Field($sLabel, new Html($sValueHtml));
$oField->SetDescription($sDescription);
$oField->SetLayout(Field::ENUM_FIELD_LAYOUT_SMALL); $oField->SetLayout(Field::ENUM_FIELD_LAYOUT_SMALL);
return $oField; return $oField;
} }
@@ -134,12 +138,14 @@ class FieldUIBlockFactory extends AbstractUIBlockFactory
* @param string $sLabel * @param string $sLabel
* @param string $sLayout * @param string $sLayout
* @param string|null $sId * @param string|null $sId
* @param string $sDescription
* *
* @return \Combodo\iTop\Application\UI\Base\Component\Field\Field * @return \Combodo\iTop\Application\UI\Base\Component\Field\Field
*/ */
public static function MakeStandard(string $sLabel = '', string $sLayout = Field::ENUM_FIELD_LAYOUT_SMALL, ?string $sId = null) public static function MakeStandard(string $sLabel = '', string $sLayout = Field::ENUM_FIELD_LAYOUT_SMALL, ?string $sId = null, string $sDescription = '')
{ {
$oField = new Field($sLabel, null, $sId); $oField = new Field($sLabel, null, $sId);
$oField->SetDescription($sDescription);
$oField->SetLayout($sLayout); $oField->SetLayout($sLayout);
return $oField; return $oField;

View File

@@ -23,6 +23,9 @@
{% endif %} {% endif %}
> >
<div class="ibo-field--label">{{ oUIBlock.GetLabel()|raw }} <div class="ibo-field--label">{{ oUIBlock.GetLabel()|raw }}
{% if oUIBlock.HasDescription() %}
<span class="ibo-has-description" data-tooltip-content="{{ oUIBlock.GetDescription() }}" data-tooltip-max-width="600px" ></span>
{% endif %}
{% if oUIBlock.GetLayout() == constant("Combodo\\iTop\\Application\\UI\\Base\\Component\\Field\\Field::ENUM_FIELD_LAYOUT_LARGE") %} {% if oUIBlock.GetLayout() == constant("Combodo\\iTop\\Application\\UI\\Base\\Component\\Field\\Field::ENUM_FIELD_LAYOUT_LARGE") %}
{% if oUIBlock.GetComments() %} {% if oUIBlock.GetComments() %}
<div class="ibo-field--comments">{{ oUIBlock.GetComments()|raw }}</div> <div class="ibo-field--comments">{{ oUIBlock.GetComments()|raw }}</div>