-
Posts
5,034 -
Joined
-
Days Won
340
Everything posted by Robin S
-
How to add drop down menu in the backend with icons
Robin S replied to DrQuincy's topic in General Support
Here's the module: -
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/
- 21 replies
-
- 18
-
-
-
How to add drop down menu in the backend with icons
Robin S replied to DrQuincy's topic in General Support
I've found something similar in a few cases. Doing a Modules > Refresh is supposed to both clear the module info cache and the admin menu cache (AdminThemeUikit hooks Modules::refresh) but sometimes it doesn't work and you have to either logout/login or (easier) use the Tracy Debugger "Clear Session & Cookies" link in the "ProcessWire Info" panel. The whole cached admin menu thing seems a bit pointless to me, so if you want to effectively disable that you can put the following in /site/ready.php // Prevent admin menu from being cached $wire->addHookBefore('ProcessController::execute', function(HookEvent $event) { $event->wire()->session->removeFor('AdminThemeUikit', 'prnav'); }); But you'll still need to do a Modules > Refresh if you make changes to the "nav" item in a Process module's getModuleInfo method. Have a look at ProcessModule and I think you'll be able to work it out. Within getModuleInfo see "useNavJSON" and the "navJSON" items within the "nav" array, and the executeNavJSON method. You probably can't. Probably best to make a corresponding executeSomething() method in your Process module that simply lists the child links. Yeah, unfortunately you can't because AdminThemeFramework forces the Process page URL before the link for items in the "nav" array. It seems this array is really only intended to be used for executeSomething() methods within the Process module and not for general purpose links. Recently I've been playing around with an alternative approach to custom admin menus which involves hooking AdminThemeFramework::getPrimaryNavArray (only possible in PW 3.0.178 or newer). If you use Tracy to dump the event return you can work out how the menus can be manipulated. And I've put together a module that lets you add custom admin menus without writing code - will release soon. -
Yes, the original module which is a completely separate thing to LoginRegisterPro. There is no support thread so people create lots of separate forum threads for questions. And also there are quite a lot of GitHub issues and it's not clear what support or future there is for LoginRegister, and people need to know that before they start using it.
-
Wow, a triple-whammy of modules, thanks @ryan! I noticed that two of these new modules don't have support threads in the forum and the Support button in the modules directory listing isn't functional. That situation also applies to your Login Register module which I believe used to have an entry in the modules directory but no longer does. (Edit: after doing a quick scan through your modules in the directory it looks like the majority don't have support threads in the Modules/Plugins subforum) It's inevitable that users of these modules will have questions/issues that they will want to raise here in the forums, so it would be good if every module that's shared with the community has a dedicated thread in the forums. Otherwise people open multiple new topics so it's harder for users to look through the history of discussion about a module. If the reason some of your modules don't have support threads is that you're not able to spend time responding to support requests (which is totally legitimate IMO) then the opening post could explain the support status of the module, maybe something along the lines of "this module has been shared with the community but the author is generally not available to provide ongoing support". Then people can still post questions or issues with the understanding that they are not guaranteed to get support from the module author but that other members of the PW community may offer advice.
- 8 replies
-
- 13
-
-
-
Thanks. I assume you mean if you accidentally add a description because the point of this module is that it hides the fieldset that surrounds the fields so you wouldn't expect to be able to see any description. In v0.1.7 the module explicitly hides any description and notes for the fieldset so if these are accidentally present they won't disrupt the intended layout.
-
How to add drop down menu in the backend with icons
Robin S replied to DrQuincy's topic in General Support
Pages will only appear in the dropdown menu if those pages have a Process assigned. See here. In effect this usually means "pages that use the admin template". You could possibly create a custom Process module that you use to redirect to other pages in the module's execute() method. Then create new pages using the admin template and select your Process. See here for an easy way to set the menu icon of admin pages. But also consider using the "nav" item in the getModuleInfo() method of a custom Process module. This lets you define some dropdown menu items for the Process when the page is in the top menu. ProcessModule is an example. Unfortunately you cannot set the first level of dropdown items dynamically. https://github.com/processwire/processwire-requests/issues/189 The top menu is cached (unnecessary in my opinion) so if you are making changes and not seeing them reflected in the menu then do a Modules > Refresh (and Tracy has a handy shortcut). Add "#ProcessPageEditChildren" to the URL. /your-admin-page/page/edit/?id=1234#ProcessPageEditChildren -
PageTable inside FieldtypeFieldsetPage not working
Robin S replied to Orkun's topic in General Support
I don't think you'll be able to use that combination because PageTable isn't supported inside a Repeater, and FieldtypeFieldsetPage is very closely related to FieldtypeRepeater (see the intro blog post). This post has a handy summary of fieldtype compatibility (written before FieldsetPage existed): So if changing your PageTable to RepeaterMatrix is an option then that will likely work inside FieldsetPage. AdminActions has an action for migrating PageTable to RepeaterMatrix. -
Try using urlencode() on the image URL to deal with spaces and other potentially problematic characters.
-
Setting page title from other page title with apostrophe (single quote)
Robin S replied to Goca's topic in API & Templates
The HTML Entity Encoder is probably applied to the title field (which is good). So you need to turn off output formatting for $quizPage... $quizPage->of(false); ...or at least get the unformatted value of the title field... $record->title = $quizPage->getUnformatted('title'); -
If the search phrase is coming from user input you'll need to sanitise it through $sanitizer->selectorValue or else there are a range of search phrases that will break your search and cause an error. But "%" is filtered out by $sanitizer->selectorValue by default, because it is a character that is used in a selector operators, e.g. "%=", "%$=", etc. So if it's important that "%" be allowed you'll need to add it in the whitelist option, but bear in mind that this will possibly allow some search phrases that could break the search or return incorrect results. Not sure how likely that is in practice. The basic operators that appear to work with % in the search phrase are *= and %=. The %= operator allows partial word matches so it depends what you want. If you want to match multiple words in any order you'll probably want use an approach where you explode to individual words then build up a selector string.
-
I don't understand the question. ConnectPageFields <= v0.3.1 requires PW >= v3.0.0 ConnectPageFields >= v0.3.2 requires PW >= 3.0.166
-
You're right, I think the vulnerability was only able to be exploited on systems where Adminer had been left in a publicly accessible location.
-
I did a bit of reading about this last night and reports are that in Adminer v4.6.2 and below there was a security hole that hackers exploited to attack WordPress and Magento sites - not sure if other platforms were vulnerable but given that Adminer is a general DB tool I assume so. But this hole was patched and consensus seems to be that recent versions of Adminer are safe. So I wonder if the OP's host has an overly broad rule that is simply flagging Adminer generally rather than detecting specific versions. Having said that, I checked the Tracy Debugger history and the first bundled Adminer version was v4.6.3 so it was kind of a near miss. Maybe it is better that the Adminer panel is separated into its own module so that having it present on a server is more of a conscious choice. I think it's an awesome addition to Tracy so I'll be installing it for sure.
-
Very interesting, although the visualisation doesn't quite demonstrate the fact that the bundled site profiles make up more than half of the total ZIP filesize when you download PW from the repo. I believe this has some negatives so I'm keen to start a discussion about moving most of the profiles to separate repos. For anyone interested, please participate here: https://github.com/processwire/processwire-requests/issues/415
- 1 reply
-
- 2
-
-
ProcessPageLister - Viewing selected bookmark
Robin S replied to cryostar's topic in General Support
When you say "uses", do you mean your module extends ProcessPageLister? If not that would probably be the simplest approach because then bookmarks will work out-of-the-box. Here's a bare-bones example: <?php namespace ProcessWire; class ProcessListerExtend extends ProcessPageLister { /** * Module information */ public static function getModuleinfo() { return array( 'title' => 'Lister Extend', 'summary' => 'An example of a module that extends ProcessPageLister', 'version' => '0.1.0', 'author' => 'Robin S', 'icon' => 'search-plus', 'requires' => 'ProcessWire>=3.0.0, PHP>=5.4.0', 'page' => array( 'name' => 'lister-extend', 'title' => 'Lister Extend', 'parent' => 'setup', ), 'useNavJSON' => true, ); } /** * Init * * Load the CSS and JS assets for ProcessPageLister rather than needing to duplicate them in this module's folder */ public function init() { $this->wire()->modules->loadModuleFileAssets('ProcessPageLister'); parent::init(); } /** * Install * * Call Process::install() to automatically create the admin page for the process on install * This is needed here because ProcessPageLister overrides with an empty install() method */ public function ___install() { Process::___install(); } /** * Uninstall * * Call Process::uninstall to automatically removes the admin page for the process on uninstall * This is needed here because ProcessPageLister overrides with an empty uninstall() method */ public function ___uninstall() { Process::___uninstall(); } } Wherever you need to modify a method of ProcessPageLister you can create a corresponding method in your module to override it, and you can make use of parent::methodName() within your method if you just want to add something to the ProcessPageLister method. -
Generally speaking this is already possible. The syntax is: !your_field_name^=foo Paths are a special case though because these are only searchable when the PagePaths module is installed and that module doesn't support this kind of negation: But I don't think this actually matters because there is a dedicated selector option for when you want to find pages that do or do not have a particular ancestor, and that is "has_parent": https://processwire.com/docs/selectors/#finding2 So rather than needing anything like... ...you can instead do... has_parent!=/foo/|/bar/|/baz/
-
You have to first get the "itinerary" array as a variable distinct from the $session->itinerary overloaded property, modify it as needed, and then set it back to $session->itinerary. if(isset($_GET[$key])){ $itinerary = $session->itinerary; if(is_array($itinerary)) { // destroy a single element of an array unset($itinerary[$key]); $session->itinerary = $itinerary; $session->redirect($page->url); } }
-
The module readme says:
-
@neonwired, as explained a couple of posts above yours, you need to be using PW 3.0.166 or newer (currently on the PW dev branch) to install or upgrade to v0.3.2 of Connect Page Fields. If you don't want to use the PW dev version then you can manually download Connect Page Fields v0.3.1 by browsing back in the commit history: https://github.com/Toutouwai/ConnectPageFields/tree/99f5e06b959d100a57ab130fa6e6f57ffea19dc9 After you download make sure you rename the module folder from "ConnectPageFields-99f5e06b959d100a57ab130fa6e6f57ffea19dc9" to "ConnectPageFields" before you copy it to /site/modules/ and install it (see "Installing manually").