1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-22 06:13:57 +02:00

Fix issue processwire/processwire-issues#726 where Pages > Tree > dropdown was displaying liternal icon names (in addition to actual icon) in some cases when it shouldn't

This commit is contained in:
Ryan Cramer
2018-11-29 13:59:36 -05:00
parent 009dec332c
commit c7447bf838
2 changed files with 9 additions and 4 deletions

View File

@@ -546,7 +546,7 @@ class ProcessPageList extends Process implements ConfigurableModule {
} }
$numChildren = $id > 1 ? $page->numChildren : 0; $numChildren = $id > 1 ? $page->numChildren : 0;
$label = $renderer->getPageLabel($page, array('noTags' => true)); $label = $renderer->getPageLabel($page, array('noTags' => true, 'noIcon' => true));
if(strlen($label) > $maxLabelLength) { if(strlen($label) > $maxLabelLength) {
$label = substr($label, 0, $maxLabelLength); $label = substr($label, 0, $maxLabelLength);
$pos = strrpos($label, ' '); $pos = strrpos($label, ' ');

View File

@@ -44,7 +44,7 @@ abstract class ProcessPageListRender extends Wire {
'restore' => $this->_('Restore'), // Restore from trash action 'restore' => $this->_('Restore'), // Restore from trash action
); );
require_once(dirname(__FILE__) . '/ProcessPageListActions.php'); require_once(dirname(__FILE__) . '/ProcessPageListActions.php');
$this->actions = $this->wire(new ProcessPageListActions($this)); $this->actions = $this->wire(new ProcessPageListActions());
$this->actions->setActionLabels($this->actionLabels); $this->actions->setActionLabels($this->actionLabels);
} }
@@ -102,13 +102,14 @@ abstract class ProcessPageListRender extends Wire {
* *
* @param Page $page * @param Page $page
* @param array $options * @param array $options
* - `noTags` (bool): If true, HTML will be excluded [other than for icon] in returned text value (default=false)
* - `noIcon` (bool): If true, icon markup will be excluded from returned value (default=false)
* @return string * @return string
* *
*/ */
public function ___getPageLabel(Page $page, array $options = array()) { public function ___getPageLabel(Page $page, array $options = array()) {
$value = ''; $value = '';
$icon = empty($options['noTags']) ? $page->getIcon() : '';
if(strpos($this->pageLabelField, '!') === 0) { 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
@@ -124,9 +125,10 @@ abstract class ProcessPageListRender extends Wire {
$bracket1 = strpos($pageLabelField, '{'); $bracket1 = strpos($pageLabelField, '{');
if($bracket1 !== false && $bracket1 < strpos($pageLabelField, '}')) { if($bracket1 !== false && $bracket1 < strpos($pageLabelField, '}')) {
// predefined format string // predefined format string
$icon = $page->getIcon();
if($icon) $pageLabelField = str_replace(array("fa-$icon", "icon-$icon", " "), array('', '', ' '), $pageLabelField); if($icon) $pageLabelField = str_replace(array("fa-$icon", "icon-$icon", " "), array('', '', ' '), $pageLabelField);
if(!empty($options['noIcon'])) $icon = '';
// adjust string so that it'll work on a single line, without the markup in it // adjust string so that it'll work on a single line, without the markup in it
$value = $page->getText($pageLabelField, true, true); $value = $page->getText($pageLabelField, true, true);
// if(strpos($value, '</li>')) $value = preg_replace('!</li>\s*<li[^>]*>!', ', ', $value); // if(strpos($value, '</li>')) $value = preg_replace('!</li>\s*<li[^>]*>!', ', ', $value);
@@ -135,6 +137,7 @@ abstract class ProcessPageListRender extends Wire {
} else { } else {
// CSV or space-separated field or fields // CSV or space-separated field or fields
$icon = empty($options['noTags']) ? $page->getIcon() : '';
// convert to array // convert to array
if(strpos($pageLabelField, ' ')) $fields = explode(' ', $pageLabelField); if(strpos($pageLabelField, ' ')) $fields = explode(' ', $pageLabelField);
@@ -183,6 +186,8 @@ abstract class ProcessPageListRender extends Wire {
if($icon) { if($icon) {
$icon = $this->wire('sanitizer')->name($icon); $icon = $this->wire('sanitizer')->name($icon);
$icon = "<i class='icon fa fa-fw fa-$icon'></i>"; $icon = "<i class='icon fa fa-fw fa-$icon'></i>";
} else {
$icon = '';
} }
if(!strlen($value)) $value = $this->wire('sanitizer')->entities($page->getUnformatted("title|name")); if(!strlen($value)) $value = $this->wire('sanitizer')->entities($page->getUnformatted("title|name"));