Leaderboard
Popular Content
Showing content with the highest reputation on 09/08/2021 in all areas
-
That's great! Thanks for the feedback. It is even easier now in v1.0.9 as I reduced the hook priority, so every "usual" hook written inside a template should work, too.2 points
-
Hi @joshua, that works - sort of. When setting the user language inside a template we still only get the default language, as your hook gets called earlier. However, what does work is hooking into the same Page::render method with a lower priority number, so our code gets an earlier execution. Great! In ready.php we now have: <?php namespace ProcessWire; // Hook into Page::render, just before PrivacyWire's hook // Which uses the default priority of 100 wire()->addHookBefore('Page::render', function (HookEvent $evt) { // Only apply to front-end pages $page = $evt->object; if ( $page->template == 'admin' || // exclude admin pages $page->template == 'form-builder' // exclude from form-builder iframe ) { return; } $user = wire()->user; $languages = wire()->languages; // Get and sanitize the ?lang= get param $lang = strtolower(wire()->input->get("lang", "text")); // Set appropriate language if ($lang === "en") { $user->language = $languages->get("default"); } else { $user->language = $languages->get("de"); } }, ['priority' => 99]);2 points
-
This module lets you add some custom menu items to the main admin menu, and you can set the dropdown links dynamically in a hook if needed. Sidenote: the module config uses some repeatable/sortable rows for the child link settings, similar to the ProFields Table interface. The data gets saved as JSON in a hidden textarea field. Might be interesting to other module developers? Custom Admin Menus Adds up to three custom menu items with optional dropdowns to the main admin menu. The menu items can link to admin pages, front-end pages, or pages on external websites. The links can be set to open in a new browser tab, and child links in the dropdown can be given an icon. Requires ProcessWire v3.0.178 or newer and AdminThemeUikit. Screenshots Example of menu items Module config for the menus Link list shown when parent menu item is not given a URL Advanced Setting child menu items dynamically If needed you can set the child menu items dynamically using a hook. Example: $wire->addHookAfter('CustomAdminMenus::getMenuChildren', function(HookEvent $event) { // The menu number is the first argument $menu_number = $event->arguments(0); if($menu_number === 1) { $colours = $event->wire()->pages->findRaw('template=colour', ['title', 'url', 'page_icon']); $children = []; foreach($colours as $colour) { // Each child item should be an array with the following keys $children[] = [ 'icon' => $colour['page_icon'], 'label' => $colour['title'], 'url' => $colour['url'], 'newtab' => false, ]; } $event->return = $children; } }); Create multiple levels of flyout menus It's also possible to create multiple levels of flyout submenus using a hook. For each level a submenu can be defined in a "children" item. Example: $wire->addHookAfter('CustomAdminMenus::getMenuChildren', function(HookEvent $event) { // The menu number is the first argument $menu_number = $event->arguments(0); if($menu_number === 1) { $children = [ [ 'icon' => 'adjust', 'label' => 'One', 'url' => '/one/', 'newtab' => false, ], [ 'icon' => 'anchor', 'label' => 'Two', 'url' => '/two/', 'newtab' => false, 'children' => [ [ 'icon' => 'child', 'label' => 'Red', 'url' => '/red/', 'newtab' => false, ], [ 'icon' => 'bullhorn', 'label' => 'Green', 'url' => '/green/', 'newtab' => false, 'children' => [ [ 'icon' => 'wifi', 'label' => 'Small', 'url' => '/small/', 'newtab' => true, ], [ 'icon' => 'codepen', 'label' => 'Medium', 'url' => '/medium/', 'newtab' => false, ], [ 'icon' => 'cogs', 'label' => 'Large', 'url' => '/large/', 'newtab' => false, ], ] ], [ 'icon' => 'futbol-o', 'label' => 'Blue', 'url' => '/blue/', 'newtab' => true, ], ] ], [ 'icon' => 'hand-o-left', 'label' => 'Three', 'url' => '/three/', 'newtab' => false, ], ]; $event->return = $children; } }); Showing/hiding menus according to user role You can determine which menu items can be seen by a role by checking the user's role in the hook. For example, if a user has or lacks a role you could include different child menu items in the hook return value. Or if you want to conditionally hide a custom menu altogether you can set the return value to false. Example: $wire->addHookAfter('CustomAdminMenus::getMenuChildren', function(HookEvent $event) { // The menu number is the first argument $menu_number = $event->arguments(0); $user = $event->wire()->user; // For custom menu number 1... if($menu_number === 1) { // ...if user does not have some particular role... if(!$user->hasRole('foo')) { // ...do not show the menu $event->return = false; } } }); https://github.com/Toutouwai/CustomAdminMenus https://processwire.com/modules/custom-admin-menus/1 point
-
The topic comes up regularly, so there's already a ton of information in the forum. If url segments for the building template aren't needed, this solution should cover the requirements:1 point
-
I did wonder if that might be the case. I need to use the setting in both sites, having just set it in site-web, and I thought setting() achieves that whereas adminSite() is not available to the other site. However, it seems I am wrong and that the adminSite() function is available in site-admin when that instance is called from site-web. So I removed the extra line and everything seems to work, thanks! bodyFoot was "<p>myText, some more text, ... </p>" and $host was "myText" so your explanantion is spot on and in line with the docs. However, *= worked in 3.0.165 with exactly the same values so it looks like something changed... No worries, it all works now, but I wonder if there might be a problem lurking for others if indeed there was a change.1 point
-
Thanks for responding @ryan. No, the error was triggering later, on line 41, at the JSON.parse(). I just found it strange that removing the class .InputfieldPage made the error go away. No, I didn't try this. Next time. That's what I was thinking at first. However, if I added multiple fields, it would reload the first one OK then trip on the next one. Yeah, me too! ?.1 point
-
That's correct, currently PrivacyWire loads itself in the module ready() method. I played around with some settings to load PrivacyWire later. You can find the feature in this branch: https://github.com/webworkerJoshua/privacywire/tree/feature-initiate-privacywire-laster In this version PrivacyWire initiates itself before Page::render: $this->addHookBefore('Page::render', $this, 'initiatePrivacyWire'); Could you try this version and confirm, that it's working the way you wanted / expected? After that I will do some more testing before merging into the main branch just to be sure that there are no side effects ? Thanks!1 point
-
Hi @Ivan Gretsky The code I gonna paste here is a copy/paste from other work so there might be glitches. And you should use your own fieldnames etc. What you can do is: Create a template and template file for RSS name it rss. Template not ending with slash. (Name a the page that uses this template should end with .rss In the template file something like: <?php namespace ProcessWire; use DomDocument; use DOMElement; use DateTime; header('Content-Type: application/xml; charset=utf-8', true); date_default_timezone_set("Europe/Amsterdam"); setlocale(LC_MONETARY, 'nl_NL'); /** @var \DateTime */ $date = new DateTime('today midnight'); $items = $pages->find("YOUR SEARCH SELECTOR DON'T FORGET TO SET LIMIT"); /** * Start XML Object * * @var DOMDocument */ $dom = new DOMDocument("1.0", "UTF-8"); $root = $dom->appendChild($dom->createElement("rss")); $root->setAttribute("version","2.0"); $root->setAttribute("xmlns:dc","http://purl.org/dc/elements/1.1/"); $root->setAttribute("xmlns:content","http://purl.org/rss/1.0/modules/content/"); $root->setAttribute("xmlns:atom","http://www.w3.org/2005/Atom"); $link = $dom->createElement("atom:link"); $link->setAttribute("href", $page->httpUrl()); $link->setAttribute("rel","self"); $link->setAttribute("type","application/rss+xml"); $channel = $root->appendChild($dom->createElement("channel")); $channel->appendChild($link); $channel->appendChild($dom->createElement("title", $page->title)); $channel->appendChild($dom->createElement("description", $page->description)); $channel->appendChild($dom->createElement("link", $page->httpUrl)); $channel->appendChild($dom->createElement("language", "nl")); $channel->appendChild($dom->createElement("lastBuildDate", $date->format(DateTime::RFC2822))); $channel->appendChild($dom->createElement("generator", "DomDocument, ProcessWire")); foreach ($items as $item) { $dateInt = (int) $item->getUnformatted("date_start"); if (!$dateInt) $dateInt = (int) $item->modified; /** @var DateTime $date */ $date = new DateTime(date("Y-m-d", $dateInt)); /** @var DOMElement $parent */ $itemParent = $dom->createElement("item"); // Plain tags $elements = array( $dom->createElement("title", $item->title), $dom->createElement("description", htmlspecialchars($item->description)), $dom->createElement("link", $item->httpUrl()), ); // For closure $image = $images->first(); $image = $image->size(600, round(600 * 9 / 16)); $mime = $image->ext === 'jpg' ? "image/jpeg" : "image/png"; $enclosure = $dom->createElement("enclosure"); $enclosure->setAttribute('url', $image->httpUrl()); $enclosure->setAttribute('type', $mime); $enclosure->setAttribute('length', $image->filesize); $elements[] = $enclosure; foreach ($elements as $element) $itemParent->appendChild($element); $channel->appendChild($itemParent); } echo $dom->saveXML(); When you want to place the RSS in the root you could hide it for non superusers: /** * Hide RSS page * * Hide RSS page int pagelist for NON superusers * */ $wire->addHookBefore("ProcessPageList::find", function (HookEvent $event) { /** @var User $user */ $user = $this->wire("user"); if ($user->isSuperuser()) return; /** @var Page $page */ $page = $event->arguments(1); /** @var string $baseSelector */ $baseSelector = $event->arguments(0); $selector = $baseSelector . ", template!=rss"; $event->arguments(0, $selector); }); Hope this could be a good starting point for you.1 point