1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-16 11:44:42 +02:00

Add PR #77 from @BernhardBaumrock which makes AdminThemeUikit::getUikitCSS() method hookable and adds an option for using uk-svg attribute on custom logo.

Co-authored-by: BernhardBaumrock <office@baumrock.com>
This commit is contained in:
Ryan Cramer
2021-05-11 08:29:15 -04:00
parent d29ed3eb96
commit 32150bd4b7
2 changed files with 26 additions and 10 deletions

View File

@@ -20,6 +20,8 @@
* @property string $inputSize Size for input/select elements. One of "s" for small, "m" for medium (default), or "l" for large. * @property string $inputSize Size for input/select elements. One of "s" for small, "m" for medium (default), or "l" for large.
* @property bool|int $ukGrid When true, use uk-width classes for Inputfields (rather than CSS percentages). * @property bool|int $ukGrid When true, use uk-width classes for Inputfields (rather than CSS percentages).
* *
* @method string getUikitCSS()
*
* *
*/ */
class AdminThemeUikit extends AdminThemeFramework implements Module, ConfigurableModule { class AdminThemeUikit extends AdminThemeFramework implements Module, ConfigurableModule {
@@ -990,30 +992,42 @@ class AdminThemeUikit extends AdminThemeFramework implements Module, Configurabl
$options = array_merge($defaults, $options); $options = array_merge($defaults, $options);
$logoURL = $this->get('logoURL'); $logoURL = $this->get('logoURL');
$logoQS = '';
$svg = false; $svg = false;
if(empty($logoURL) || $options['getNative'] || strpos($logoURL, '//') !== false) { if(empty($logoURL) || $options['getNative'] || strpos($logoURL, '//') !== false) {
$native = true; $native = true;
$logoURL = $this->url() . self::logo; $logoURL = $this->url() . self::logo;
} else { } else {
if(strpos($logoURL, '?')) list($logoURL, $logoQS) = explode('?', $logoURL, 2);
$logoURL = $config->urls->root . ltrim($logoURL, '/'); $logoURL = $config->urls->root . ltrim($logoURL, '/');
$logoURL = $sanitizer->entities($logoURL); $logoURL = $sanitizer->entities($logoURL);
$native = false; $native = false;
$svg = strtolower(pathinfo($logoURL, PATHINFO_EXTENSION)) === 'svg'; $svg = strtolower(pathinfo($logoURL, PATHINFO_EXTENSION)) === 'svg';
} }
if($options['getURL']) return $logoURL;
$alt = $options['alt']; $alt = $options['alt'];
if(empty($alt) && $this->wire('user')->isLoggedin()) { if(empty($alt) && $this->wire()->user->isLoggedin()) {
$alt = "ProcessWire $config->version"; $alt = "ProcessWire $config->version";
} }
$class = 'pw-logo ' . ($native ? 'pw-logo-native' : 'pw-logo-custom');
$attr = "class='$class' src='$logoURL' alt='$alt' ";
if($svg && $options['height']) $attr .= "style='height:$options[height]' ";
$img = "<img $attr/>";
return $img; $class = 'pw-logo ' . ($native ? 'pw-logo-native' : 'pw-logo-custom');
$attr = "class='$class' alt='$alt' ";
if($svg) {
if($options['height']) $attr .= "style='height:$options[height]' ";
if(strpos($logoQS, 'uk-svg') === 0) {
// if logo has "?uk-svg" query string, add uk-svg attribute which makes it styleable via CSS/LESS (PR#77)
$attr .= 'uk-svg ';
$logoQS = str_replace(array('uk-svg&', 'uk-svg'), '', $logoQS);
}
}
if($logoQS) $logoURL .= '?' . $sanitizer->entities($logoQS);
$img = "<img src='$logoURL' $attr/>";
return $options['getURL'] ? $logoURL : $img;
} }
/** /**
@@ -1052,9 +1066,10 @@ class AdminThemeUikit extends AdminThemeFramework implements Module, Configurabl
* Get the primary Uikit CSS file to use * Get the primary Uikit CSS file to use
* *
* @return string * @return string
* @since 3.0.178 Was not hookable in prior versions
* *
*/ */
public function getUikitCSS() { public function ___getUikitCSS() {
$config = $this->wire('config'); $config = $this->wire('config');
$cssURL = $this->get('cssURL'); $cssURL = $this->get('cssURL');
$moduleInfo = self::getModuleInfo(); $moduleInfo = self::getModuleInfo();

View File

@@ -111,7 +111,8 @@ class AdminThemeUikitConfigHelper extends Wire {
$f->label = $this->_('Logo image file'); $f->label = $this->_('Logo image file');
$f->description = $defaultFileDesc; $f->description = $defaultFileDesc;
$f->notes = $defaultFileNote . $f->notes = $defaultFileNote .
$this->_('File should be PNG, GIF, JPG or SVG, on transparent background, and at least 100px in both dimensions.'); $this->_('File should be PNG, GIF, JPG or SVG, on transparent background, and at least 100px in both dimensions.') . ' ' .
sprintf($this->_('If using SVG, you may optionally append “?uk-svg” to URL to make it add the [uk-svg](%s) attribute.'), 'https://getuikit.com/docs/svg');
$f->collapsed = Inputfield::collapsedBlank; $f->collapsed = Inputfield::collapsedBlank;
$f->icon = 'file-image-o'; $f->icon = 'file-image-o';
$fieldset->add($f); $fieldset->add($f);