/** * compile button element, inspired by ContentHyperlink */ protected function compile() { if (substr($this->url, 0, 7) == 'mailto:') { $this->url = \String::encodeEmail($this->url); } else { $this->url = ampersand($this->url); } if ($this->linkTitle == '') { $this->linkTitle = $this->url; } if (strncmp($this->rel, 'lightbox', 8) !== 0) { $this->Template->attribute = ' rel="' . $this->rel . '"'; } else { $this->Template->attribute = ' data-lightbox="' . substr($this->rel, 9, -1) . '"'; } // Override the link target if ($this->target) { $this->Template->target = ' target="_blank"'; } if ($this->cssID[1] == '') { $cssID = $this->cssID; $cssID[1] = 'btn-default'; $this->cssID = $cssID; } if ($this->icon) { $this->Template->icon = Icons::generateIcon($this->icon); } // add data attributes $this->dataAttributes = deserialize($this->dataAttributes, true); if (!empty($this->dataAttributes)) { $attributes = array(); foreach ($this->dataAttributes as $attribute) { if (trim($attribute['value']) != '' && $attribute['name'] != '') { $attributes[] = 'data-' . $attribute['name'] . '=' . $attribute['value']; } } $this->Template->attribute = trim($this->attribute . ' ' . implode(' ', $attributes)); } $this->Template->rel = $this->rel; // Backwards compatibility $this->Template->href = $this->url; $this->Template->link = $this->linkTitle; $this->Template->linkTitle = specialchars($this->titleText ?: $this->linkTitle); }
/** * Generate the widget and return it as string * @return string */ public function generate() { if ($this->imageSubmit) { $objModel = \FilesModel::findByPk($this->singleSRC); if ($objModel !== null && is_file(TL_ROOT . '/' . $objModel->path)) { return sprintf('<button type="submit" id="ctrl_%s" class="submit btn %s" title="%s" alt="%s"%s>%s</button>', $this->strId, $this->strClass != '' ? ' ' . $this->strClass : 'btn-default', specialchars($this->slabel), specialchars($this->slabel), $this->getAttributes(), \Image::getHtml($objModel->path, $this->slabel)); } } $label = specialchars($this->slabel); if ($this->bootstrap_addIcon) { $icon = Icons::generateIcon($this->bootstrap_icon); if ($this->bootstrap_iconPosition == 'right') { $label = $label . ' ' . $icon; } else { $label = $icon . ' ' . $label; } } // Return the regular button return sprintf('<button type="submit" id="ctrl_%s" class="submit btn %s"%s>%s</button>', $this->strId, $this->strClass != '' ? $this->strClass : 'btn-default', $this->getAttributes(), $label); }
/** * generate an icon using insert tag * * icon::example * icon::exmaple::extra-css-class * * @param $tag * * @return bool|string */ protected function icon($parts, $cache) { return Icons::generateIcon($parts[0], isset($parts[1]) ? $parts[1] : null); }
/** * @param $container * @param $widget * @param $inputGroup */ private function adjustSubmitButton(Container $container, $widget, InputGroup $inputGroup) { if ($container->hasChild('submit')) { /** @var Node $submit */ $submit = $container->removeChild('submit'); // recreate as button if ($submit->getTag() != 'button') { $submit = Element::create('button'); $submit->setAttribute('type', 'submit'); $submit->addChild($widget->slabel); } $submit->addClass('btn'); if ($widget->bootstrap_addSubmitClass) { $submit->addClass($widget->bootstrap_addSubmitClass); } if ($widget->bootstrap_addSubmitIcon) { $icon = Icons::generateIcon($widget->bootstrap_addSubmitIcon); $position = null; if ($widget->bootstrap_addSubmitIconPosition == 'left') { $position = Node::POSITION_FIRST; $icon .= ' '; } else { $icon = ' ' . $icon; } $submit->addChild(new StaticHtml($icon), $position); } $inputGroup->setRight($submit, $inputGroup::BUTTON); } }