diff --git a/api/etemplate.php b/api/etemplate.php index d2099b436b..5fb4632f59 100644 --- a/api/etemplate.php +++ b/api/etemplate.php @@ -13,12 +13,12 @@ use EGroupware\Api; // add et2- prefix to following widgets/tags, if NO '; }, $str); - $str = preg_replace('#]+)/>#', '', $str); + $str = preg_replace('#]+)(/|>#', '', $str); + + // fix --> + $str = preg_replace_callback('##s', function ($matches) use ($name) + { + $tag = 'et2-button'; + $attrs = parseAttrs($matches[2]); + // replace buttononly tag with noSubmit="true" attribute + if (!empty($matches[1])) + { + $attrs['noSubmit'] = 'true'; + } + // novalidation --> noValidation + if (!empty($attrs['novalidation']) && in_array($attrs['novalidation'], ['true', '1'], true)) + { + unset($attrs['novalidation']); + $attrs['noValidation'] = 'true'; + } + // replace not set background_image attribute with et2-image tag, if not in NM / lists + if (!empty($attrs['image']) && (empty($attrs['background_image']) || $attrs['background_image'] === 'false') && + !preg_match('/^(index|list)/', $name)) + { + $tag = 'et2-image'; + $attrs['src'] = $attrs['image']; + unset($attrs['image']); + // Was expected to submit. Images don't have noValidation, so add directly + if (!array_key_exists('onclick', $attrs) && empty($attrs['noSubmit'])) + { + $attrs['onclick'] = 'this.getInstanceManager().submit(this, undefined, ' . $attrs['noValidation'] . ')'; + } + } + unset($attrs['background_image']); + return "<$tag " . stringAttrs($attrs) . '>'; + }, $str); + + $str = preg_replace_callback('#]+)/>#', static function($matches) + { + if ($matches[1] === 'date-time_today') $matches[1] = 'date-time-today'; + return ""; + }, $str); // ^^^^^^^^^^^^^^^^ above widgets get transformed independent of legacy="true" set in overlay ^^^^^^^^^^^^^^^^^^ // eTemplate marked as legacy --> replace only some widgets (eg. requiring jQueryUI) with web-components - if (preg_match('/]* legacy="true"/', $str)) + if (!preg_match('/]* legacy="true"/', $str)) { - $str = preg_replace_callback('#]+)/>#', static function($matches) - { - if ($matches[1] === 'date-time_today') $matches[1] = 'date-time-today'; - return ""; - }, $str); - } - else - { - // fix --> - $str = preg_replace_callback('##s', function ($matches) use ($name) { - $tag = 'et2-button'; - $attrs = parseAttrs($matches[2]); - // replace buttononly tag with noSubmit="true" attribute - if (!empty($matches[1])) - { - $attrs['noSubmit'] = 'true'; - } - // novalidation --> noValidation - if (!empty($attrs['novalidation']) && in_array($attrs['novalidation'], ['true', '1'], true)) - { - unset($attrs['novalidation']); - $attrs['noValidation'] = 'true'; - } - // replace not set background_image attribute with et2-image tag, if not in NM / lists - if (!empty($attrs['image']) && (empty($attrs['background_image']) || $attrs['background_image'] === 'false') && - !preg_match('/^(index|list)/', $name)) - { - $tag = 'et2-image'; - $attrs['src'] = $attrs['image']; - unset($attrs['image']); - // Was expected to submit. Images don't have noValidation, so add directly - if (!array_key_exists('onclick', $attrs) && empty($attrs['noSubmit'])) - { - $attrs['onclick'] = 'this.getInstanceManager().submit(this, undefined, ' . $attrs['noValidation'] . ')'; - } - } - unset($attrs['background_image']); - return "<$tag " . stringAttrs($attrs) . '>'; - }, $str); - $str = preg_replace_callback(ADD_ET2_PREFIX_REGEXP, static function (array $matches) { - if ($matches[3] === 'date-time_today') $matches[3] = 'date-time-today'; return '<' . $matches[2] . 'et2-' . $matches[3] . // web-components must not be self-closing (no "", but "") (substr($matches[ADD_ET2_PREFIX_LAST_GROUP], -1) === '/' ? substr($matches[ADD_ET2_PREFIX_LAST_GROUP], 0, -1) . '>'; }, $str); } + // change all attribute-names of new et2-* widgets to camelCase, and other attribute modifications for all web-components $str = preg_replace_callback('/<(et2|records)-([a-z-]+)\s([^>]+)>/', static function(array $matches) {