mirror of
https://github.com/processwire/processwire.git
synced 2025-08-11 17:24:46 +02:00
Add support for a $page->getPageListLabel(); method which enables custom page classes to return custom markup for the page's label in the page-list.
This commit is contained in:
@@ -3852,6 +3852,25 @@ class Page extends WireData implements \Countable, WireMatchable {
|
|||||||
return $this->values()->getIcon($this);
|
return $this->values()->getIcon($this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get label markup to use in page-list or blank to use template/page-list defaults
|
||||||
|
*
|
||||||
|
* This method enables custom page classes to override page labels in page-list.
|
||||||
|
* PLEASE NOTE: Inline markup is allowed so make sure to entity-encode any text field values.
|
||||||
|
*
|
||||||
|
* If you are looking for a hookable version, you should instead hook
|
||||||
|
* `ProcessPageListRender::getPageLabel` which receives the Page as its first argument.
|
||||||
|
*
|
||||||
|
* #pw-internal
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
* @since 3.0.206
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function getPageListLabel() {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the API variable used for managing pages of this type
|
* Return the API variable used for managing pages of this type
|
||||||
*
|
*
|
||||||
|
@@ -60,9 +60,11 @@
|
|||||||
padding-bottom: 3px;
|
padding-bottom: 3px;
|
||||||
line-height: 1em;
|
line-height: 1em;
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
.PageListItem > a span + span:before {
|
.PageListItem > a span + span:before {
|
||||||
content: ', ';
|
content: ', ';
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Style for the children label and notes
|
* Style for the children label and notes
|
||||||
|
@@ -300,8 +300,13 @@ abstract class ProcessPageListRender extends Wire {
|
|||||||
public function ___getPageLabel(Page $page, array $options = array()) {
|
public function ___getPageLabel(Page $page, array $options = array()) {
|
||||||
|
|
||||||
$sanitizer = $this->wire()->sanitizer;
|
$sanitizer = $this->wire()->sanitizer;
|
||||||
|
$formatLabel = true;
|
||||||
|
$label = $page->getPageListLabel();
|
||||||
|
|
||||||
if(strpos($this->pageLabelField, '!') === 0) {
|
if(!empty($label)) {
|
||||||
|
// label from custom page class overrides others
|
||||||
|
$formatLabel = false;
|
||||||
|
} else if(strpos($this->pageLabelField, '!') === 0) {
|
||||||
// exclamation forces this one to be used, rather than template-specific one
|
// exclamation forces this one to be used, rather than template-specific one
|
||||||
$label = trim(ltrim($this->pageLabelField, '!'));
|
$label = trim(ltrim($this->pageLabelField, '!'));
|
||||||
} else {
|
} else {
|
||||||
@@ -318,6 +323,7 @@ abstract class ProcessPageListRender extends Wire {
|
|||||||
|
|
||||||
while(strpos($label, ' ') !== false) $label = str_replace(' ', ' ', $label);
|
while(strpos($label, ' ') !== false) $label = str_replace(' ', ' ', $label);
|
||||||
|
|
||||||
|
if($formatLabel) {
|
||||||
$bracket1 = strpos($label, '{');
|
$bracket1 = strpos($label, '{');
|
||||||
|
|
||||||
if($bracket1 !== false && $bracket1 < strpos($label, '}')) {
|
if($bracket1 !== false && $bracket1 < strpos($label, '}')) {
|
||||||
@@ -332,6 +338,9 @@ abstract class ProcessPageListRender extends Wire {
|
|||||||
if(!strlen($value)) {
|
if(!strlen($value)) {
|
||||||
$value = $sanitizer->entities($page->getUnformatted("title|name"));
|
$value = $sanitizer->entities($page->getUnformatted("title|name"));
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
$value = $label;
|
||||||
|
}
|
||||||
|
|
||||||
if(!empty($options['noTags']) && strpos($value, '<') !== false) {
|
if(!empty($options['noTags']) && strpos($value, '<') !== false) {
|
||||||
// legacy code, appears to be impossible to reach
|
// legacy code, appears to be impossible to reach
|
||||||
|
Reference in New Issue
Block a user