1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-20 05:21:29 +02:00
This commit is contained in:
Ryan Cramer
2021-08-12 13:10:55 -04:00
parent 48a37bcc5c
commit 5282e5d737

View File

@@ -6,6 +6,7 @@
* @property string $href URL to link to * @property string $href URL to link to
* @property string $aclass Optional class name(s) for <a> element (if href is used). * @property string $aclass Optional class name(s) for <a> element (if href is used).
* @property string $target Link target * @property string $target Link target
* @property bool $linkInner Place <a> link inside <button> rather than outside? Not admin compatible. (default=false) 3.0.184+
* *
*/ */
class InputfieldButton extends InputfieldSubmit { class InputfieldButton extends InputfieldSubmit {
@@ -27,6 +28,7 @@ class InputfieldButton extends InputfieldSubmit {
$this->attr('value', 'Button'); $this->attr('value', 'Button');
$this->attr('href', ''); $this->attr('href', '');
$this->set('aclass', ''); $this->set('aclass', '');
$this->set('linkInner', false);
$this->set('target', ''); $this->set('target', '');
$this->skipLabel = Inputfield::skipLabelBlank; $this->skipLabel = Inputfield::skipLabelBlank;
} }
@@ -35,14 +37,22 @@ class InputfieldButton extends InputfieldSubmit {
$href = $this->attr('href'); $href = $this->attr('href');
if($href) $this->attr('href', ''); if($href) $this->attr('href', '');
$out = parent::___render(); $out = parent::___render();
if($href) { if(!$href) return $out;
$out = trim($out); $out = trim($out);
$attr = " class='" . trim("InputfieldButtonLink $this->aclass") . "'"; $attrs = array(
if($this->target) $attr .= " target='" . $this->wire('sanitizer')->entities($this->target) . "'"; 'class' => trim("InputfieldButtonLink $this->aclass"),
$out = "<a$attr href='$href'>$out</a>"; 'href' => $href,
$this->attr('href', $href); );
if($this->target) $attrs['target'] = $this->target;
$attrs = $this->getAttributesString($attrs);
if($this->linkInner) {
list($button, $text) = explode('>', $out, 2);
list($text,) = explode('</button>', $text, 2);
$out = "$button><a $attrs>$text</a></button>";
} else {
$out = "<a $attrs tabindex='-1'>$out</a>";
} }
$this->attr('href', $href); // restore
return $out; return $out;
} }