Commit aa2eafba authored by Mathias Schreiber's avatar Mathias Schreiber Committed by Frank Nägler
Browse files

[TASK] Allow to show label text next to a button

Releases: master
Resolves: #70383
Change-Id: Ie7d144866ac0550df0e88b893a44a01633c74c01
Reviewed-on: http://review.typo3.org/43817


Reviewed-by: default avatarMichael Oehlhof <typo3@oehlhof.de>
Tested-by: default avatarMichael Oehlhof <typo3@oehlhof.de>
Reviewed-by: Frank Nägler's avatarFrank Nägler <frank.naegler@typo3.org>
Tested-by: Frank Nägler's avatarFrank Nägler <frank.naegler@typo3.org>
parent c860d417
...@@ -36,6 +36,34 @@ class AbstractButton extends AbstractControl implements ButtonInterface { ...@@ -36,6 +36,34 @@ class AbstractButton extends AbstractControl implements ButtonInterface {
*/ */
protected $type; protected $type;
/**
* Defines whether to show the title as a label within the button
*
* @var bool
*/
protected $showLabelText = FALSE;
/**
* Show Label text
*
* @return bool
*/
public function getShowLabelText() {
return $this->showLabelText;
}
/**
* Show Label text
*
* @param bool $showLabelText
*
* @return $this
*/
public function setShowLabelText($showLabelText) {
$this->showLabelText = $showLabelText;
return $this;
}
/** /**
* Get icon * Get icon
* *
......
...@@ -121,6 +121,10 @@ class InputButton extends AbstractButton implements ButtonInterface { ...@@ -121,6 +121,10 @@ class InputButton extends AbstractButton implements ButtonInterface {
'value' => $this->getValue(), 'value' => $this->getValue(),
'title' => $this->getTitle() 'title' => $this->getTitle()
); );
$labelText = '';
if ($this->showLabelText) {
$labelText = ' ' . $this->title;
}
foreach ($this->dataAttributes as $attributeName => $attributeValue) { foreach ($this->dataAttributes as $attributeName => $attributeValue) {
$attributes['data-' . htmlspecialchars($attributeName)] = $attributeValue; $attributes['data-' . htmlspecialchars($attributeName)] = $attributeValue;
} }
...@@ -129,7 +133,7 @@ class InputButton extends AbstractButton implements ButtonInterface { ...@@ -129,7 +133,7 @@ class InputButton extends AbstractButton implements ButtonInterface {
$attributesString .= ' ' . htmlspecialchars($key) . '="' . htmlspecialchars($value) . '"'; $attributesString .= ' ' . htmlspecialchars($key) . '="' . htmlspecialchars($value) . '"';
} }
return '<button' . $attributesString . '">' return '<button' . $attributesString . '">'
. $this->getIcon()->render() . $this->getIcon()->render() . htmlspecialchars($labelText)
. '</button>'; . '</button>';
} }
......
...@@ -90,6 +90,10 @@ class LinkButton extends AbstractButton implements ButtonInterface { ...@@ -90,6 +90,10 @@ class LinkButton extends AbstractButton implements ButtonInterface {
'class' => 'btn btn-default btn-sm ' . $this->getClasses(), 'class' => 'btn btn-default btn-sm ' . $this->getClasses(),
'title' => $this->getTitle() 'title' => $this->getTitle()
); );
$labelText = '';
if ($this->showLabelText) {
$labelText = ' ' . $this->title;
}
foreach ($this->dataAttributes as $attributeName => $attributeValue) { foreach ($this->dataAttributes as $attributeName => $attributeValue) {
$attributes['data-' . htmlspecialchars($attributeName)] = $attributeValue; $attributes['data-' . htmlspecialchars($attributeName)] = $attributeValue;
} }
...@@ -102,7 +106,7 @@ class LinkButton extends AbstractButton implements ButtonInterface { ...@@ -102,7 +106,7 @@ class LinkButton extends AbstractButton implements ButtonInterface {
} }
return '<a ' . $attributesString . '>' return '<a ' . $attributesString . '>'
. $this->getIcon()->render() . $this->getIcon()->render() . htmlspecialchars($labelText)
. '</a>'; . '</a>';
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment