From d3cfbbe5e6ea2894860fcc75b88ffeb7fda69dc7 Mon Sep 17 00:00:00 2001 From: ralf Date: Fri, 17 Jun 2022 22:54:54 +0200 Subject: [PATCH] enable taglist-thumbnail --> et2-select-thumbnail conversation also convert select with options to et2-select and move select/taglist conversation to always run, independent of legacy=true --- api/etemplate.php | 84 +++++++++++++++++++++-------------------------- 1 file changed, 37 insertions(+), 47 deletions(-) diff --git a/api/etemplate.php b/api/etemplate.php index 3567912ca5..75c3f05ded 100644 --- a/api/etemplate.php +++ b/api/etemplate.php @@ -177,6 +177,43 @@ function send_template() ) . ">"; }, $str); + + // handling of select and taglist widget, incl. removing of type attribute + $str = preg_replace_callback('#<(select|taglist)(-[^ ]+)? ([^>]+?)(/|>(.*?)#s', static function (array $matches) { + preg_match_all('/(^| )([a-z0-9_-]+)="([^"]*)"/i', $matches[3], $attrs, PREG_PATTERN_ORDER); + $attrs = array_combine($attrs[2], $attrs[3]); + + if (isset($attrs['tags'])) + { + $attrs['multiple'] = 'true'; + unset($attrs['tags']); + } + // no multiple="toggle" or expand_multiple_rows="N" currently, thought Shoelace's select multiple="true" is relative close + // until we find something better, just switch to multiple="true" + if (isset($attrs['multiple']) && $attrs['multiple'] === 'toggle' || !empty($attrs['expand_multiple_rows'])) + { + $attrs['multiple'] = 'true'; + unset($attrs['expand_multiple_rows']); + } + // automatic convert empty_label for multiple=true to a placeholder + if (!empty($attrs['empty_label']) && !empty($attrs['multiple'])) + { + $attrs['placeholder'] = $attrs['empty_label']; + unset($attrs['empty_label']); + } + // type attribute need to go in widget type '; - }, $str); } $processing = microtime(true);