id = $ID;
$this->type = $this->getType();
$this->params['do'] = $this->type;
if(!actionOK($this->type)) throw new \RuntimeException("action disabled: {$this->type}");
}
/**
* Return this item's label
*
* When the label property was set, it is simply returned. Otherwise, the action's type
* is used to look up the translation in the main language file and, if used, the replacement
* is applied.
*
* @return string
*/
public function getLabel() {
if($this->label !== '') return $this->label;
/** @var array $lang */
global $lang;
$label = $lang['btn_' . $this->type];
if(strpos($label, '%s')) {
$label = sprintf($label, $this->replacement);
}
if($label === '') $label = '[' . $this->type . ']';
return $label;
}
/**
* Return this item's title
*
* This title should be used to display a tooltip (using the HTML title attribute). If
* a title property was not explicitly set, the label will be returned.
*
* @return string
*/
public function getTitle() {
if($this->title === '') return $this->getLabel();
return $this->title;
}
/**
* Return the link this item links to
*
* Basically runs wl() on $id and $params. However if the ID is a hash it is used directly
* as the link
*
* Please note that the generated URL is *not* XML escaped.
*
* @see wl()
* @return string
*/
public function getLink() {
if($this->id && $this->id[0] == '#') {
return $this->id;
} else {
return wl($this->id, $this->params, false, '&');
}
}
/**
* Convenience method to get the attributes for constructing an element
*
* @see buildAttributes()
* @param string|false $classprefix create a class from type with this prefix, false for no class
* @return array
*/
public function getLinkAttributes($classprefix = 'menuitem ') {
$attr = array(
'href' => $this->getLink(),
'title' => $this->getTitle(),
);
if($this->isNofollow()) $attr['rel'] = 'nofollow';
if($this->getAccesskey()) {
$attr['accesskey'] = $this->getAccesskey();
$attr['title'] .= ' [' . $this->getAccesskey() . ']';
}
if($classprefix !== false) $attr['class'] = $classprefix . $this->getType();
return $attr;
}
/**
* Convenience method to create a full element
*
* Wraps around the label and SVG image
*
* @param string|false $classprefix create a class from type with this prefix, false for no class
* @param bool $svg add SVG icon to the link
* @return string
*/
public function asHtmlLink($classprefix = 'menuitem ', $svg = true) {
$attr = buildAttributes($this->getLinkAttributes($classprefix));
$html = "";
if($svg) {
$html .= '' . hsc($this->getLabel()) . '';
$html .= inlineSVG($this->getSvg());
} else {
$html .= hsc($this->getLabel());
}
$html .= "";
return $html;
}
/**
* Convenience method to create a