Jump to content

Custom Notes (former List of Allergens)


Recommended Posts

Food Allergens Module
A simple List of Food Allergens

My needs were to provide a simple list of food allergens for our clients with restaurant related activity.
The idea was to simply output the list (to speed up the data entry) without leaving the food menu editing, eg. opening another page in new tab or window.
This isn't a perfect solution, but it works fine for my needs and I decided to share the base idea.
This could also be easily used to show little notes or short "vademecum", not only for the list of food allergens.

---

Main features
The basis

All moves from a short editing of the module in this tutorial: How to create custom admin pages by @bernhard

First of all it creates an empty admin page, with a dedicated permission to let safe-user to see it (this permission has to be created as a new ones, manually or by the module).

Once the page is created, I have hooked its behaviour into the ready.php, to show the content (basically a list).

A step further
With the tips of  @bernhard, @Soma (and many others), see here , the magic happens. 

The new page will be shown as a panel, so editors will not abandon their data entry to have a quick view to the list.

A little further
Why scroll to the top of the page to click a link?

The next step was to create a sticky button only in the food menu pages.

Again with a @bernhard tip I moved into the customization of this simple module and the related hook.

---

How to use this module

  1. After installed, it creates the page /admin/page/allergens/ and the module is to be setted up.
  2. The first field is a CKEditor with multi-language. This is the place where to write the informations that will be shown into the page.
  3. The next field is a simply text-area where to place a bit of JS that will be appended to the markup of the text (omit the 'script' tags).
  4. I also putted a checkbox with a silly statement: this to think at least twice on the safety of the written JS.

Now comes the first way to display the link to the page
Field Note with Link. Enable and save it. The module will display a new row with 4 selects (1 standard and 3 ASM):

  • View mode (to show the page as Panel or as Modal PopUp);
  • Templates to select: select one or more and save before proceed, so the  asm-select of the pages will be populated showing all the pages of the selected templates.
  • Pages to select: also here select at least one and save before proceed to populate the asm-select for fields only with the ones that belong to the selected pages.
  • Select the fields where to place the note and save again.

That's all: now you will find into the notes of the selected fields the link "See the List of Allergens".

At the same way, the option for the sticky button, but with a plus
The field select is obviously unnecessary, but you could play with the last row: the inline styles to fix your sticky button where you like. Here you could set the sticky position of the <div> and the absolute ones of the <a>.


Video Explanation
In these screencasts you could see a custom JS that show a "copy" button near a "hanna-code" call.
This because I've set a specific one for each allergen to show up a tooltip in the front end.

 

---

Last but not the least

Actually it works fine for my needs, even if it's much improvable: I'm working on the permissions creation, the uninstall section, a separate configs and defaults and how to include the hook into the module leaving free the ready.php. According to a simpler uninstall. Also I would make the link text as a dynamic text field, so it will be more flexible.

I always learn a lot here, so I would share my code for whom it could be interested.
I removed the hanna code references, but I provide you the html list of the allergens, English and Italian too, so you can paste them into the "source" of the CKEditor field to have a ready to use module.

Obviously you are free to modify the code as per your needs.

Please, keep in mind that I'm not a pro coder and I beg your pardon for my verbosity (speaking and coding). 😉

I hope be helpful or for inspiration.

Bye

ready.phpList-ITA.htmlList-ENG.htmlAllergens.module

README.md

Edited by Cybermano
Edited title, updateed readme.md (with static link to video and docs pointing to this thread)
  • Like 5
Link to comment
Share on other sites

Thanks for sharing this. 👍

Another possible way to approach this is to use a single Hanna tag for all allergens and then use Hanna Code Dialog to create an interface where a site editor can select allergen types by label. You could use a page per allergen type and use the (multi-language?) title field for the label and an integer field for the allergen number. Then use a hook to set the options for the dialog.

$wire->addHookAfter('HannaCodeDialog::buildForm', function(HookEvent $event) {
	// The Hanna tag that is being opened in the dialog
	$tag_name = $event->arguments(0);
	// The form rendered in the dialog
	/* @var InputfieldForm $form */
	$form = $event->return;
	if($tag_name === 'allergen') {
		/* @var InputfieldCheckboxes $f */
		$f = $event->wire('modules')->InputfieldCheckboxes;
		$f->name = 'type';
		$f->id = 'type';
		$f->label = 'Type';
		foreach($event->wire()->pages->find("parent=/references/allergens/") as $allergen) {
			$f->addOption($allergen->allergen_number, $allergen->title);
		};
		$form->add($f);
	}
});

2021-04-10_140246.png.97c64482c4a32afe8cc610b42ff0a05c.png

Or maybe if you are using a Repeater for your menu items you don't need Hanna Code and could just use a Page Reference field to select allergen pages per menu item.

  • Like 5
Link to comment
Share on other sites

Hi Robin,

thanks for your reply and your suggestions.

I totally missed your HC dialogue: I can't wait to study that module, I will look in depth asap 🙂

And the page reference (yes, I use a repeater) is also a great idea ... I hadn't thought of that.

Tks!

  • Like 1
Link to comment
Share on other sites

43 minutes ago, bernhard said:

Congratulations for your achievements 🙂 

I think https://github.com/BitPoet/ProcessCKInlineComplete could also be a great option? Just type @... and get suggested allergens!

Thanks Bernhard,

your advice spurred me not to settle.

I will surely give a look at the solution of BitPoet, it sounds very interesting...

P.S. Everyday I discover a mine of treasures... 

  • Like 1
Link to comment
Share on other sites

1 minute ago, Cybermano said:

P.S. Everyday I discover a mine of treasures... 

Working with PW now for several years and still have that feeling almost every day 🙂 

Link to comment
Share on other sites

On 4/10/2021 at 4:03 AM, Robin S said:

Another possible way ... use Hanna Code Dialog

Or maybe ... use a Page Reference ...

On 4/10/2021 at 10:30 AM, bernhard said:

I think https://github.com/BitPoet/ProcessCKInlineComplete could also be a great option...

 

Thanks for pointing me out those solutions: really rocks!

For CKEditor field they are the first solution we'll considering in future.

At the point of our production code, also page reference didn't suits well (we would maintain simple textarea and HC). Surely we will change templates and code to use these powerful tools for the next uses.

Currently I think the first idea is really flexible (even if less powerful) to adopt it in a lot of ways, for lot of ready-made sites, and with different solutions without efforts.

E.g. for food related sites we could use it as the List of Allergens, for many others could be used like a docs repo or a shortcut to a help-desk, tuts o more...

  • Like 1
Link to comment
Share on other sites

  • 2 months later...

Hey @Cybermano,

Just letting you know that I opened an issue for the module here: https://github.com/cybermano/CustomNotes/issues/5. Minor things, but they are kind of showstoppers for the module right now. After fixing those, things seemed to work pretty nicely 🙂

On 5/1/2021 at 6:26 PM, Cybermano said:

Do you suggest me to open a new thread?

That would make sense in my opinion. Or if you prefer to, I can split the thread starting from that message (https://processwire.com/talk/topic/25435-custom-notes-former-list-of-allergens/?do=findComment&comment=213864) into a new thread — just let me know.

  • Thanks 1
Link to comment
Share on other sites

50 minutes ago, teppo said:

Hey @Cybermano,

Just letting you know that I opened an issue for the module here: https://github.com/cybermano/CustomNotes/issues/5. Minor things, but they are kind of showstoppers for the module right now. After fixing those, things seemed to work pretty nicely 🙂

That would make sense in my opinion. Or if you prefer to, I can split the thread starting from that message (https://processwire.com/talk/topic/25435-custom-notes-former-list-of-allergens/?do=findComment&comment=213864) into a new thread — just let me know.

Hi Teppo.

First of all, many thanks for you time and for your suggestions. Very appreciated.

At the moment I’m on mobile and far from my pc.
ASAP I will check it and fix as you pointed.

In the meantime, please split the discussion as you see fit and as it’s more convenient for the forum.

Many thanks again for your support.

  • Like 1
Link to comment
Share on other sites

13 hours ago, Cybermano said:

In the meantime, please split the discussion as you see fit and as it’s more convenient for the forum.

Done — https://processwire.com/talk/topic/25815-custom-notes/. Moved the two posts introducing Custom Notes and placed them in the Modules forum section instead of module development (it's a proper module after all), hope that's fine 🙂

  • Thanks 1
Link to comment
Share on other sites

On 6/27/2021 at 9:22 AM, teppo said:

Done — https://processwire.com/talk/topic/25815-custom-notes/. Moved the two posts introducing Custom Notes and placed them in the Modules forum section instead of module development (it's a proper module after all), hope that's fine 🙂

Hi @teppo

PR merged on the trust. 😉

As posted on GitHub , your eyes will surely solve my newbie errors.

ASAP I will check deeply all. 
 

Thanks again.

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Robin S
      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.
      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/
    • By tcnet
      This module for ProcessWire sends a notification email for each failed login attempt. Similar modules exists already in the module directory of ProcessWire. However, this module is designed to notify, even if specified user doesn't exist.
      Settings
      The settings for this module are located in the menu Modules=>Configure=>LoginFailNotifier.
      Notification email
      Specifies the email address to which the notification emails should be sent.
        Email subject
      Specifies the subject line for the notification email.
        Post variables
      Specifies the $_POST variables to be included in the notification email. Each variable must be separated by a comma. For example: login_name,login_pass
        Server variables
      Specifies the $_SERVER variables to be included in the notification email. Each variable must be separated by a comma. For example: REMOTE_ADDR,HTTP_USER_AGENT
      Link to ProcessWire module directory:
      https://processwire.com/modules/login-fail-notifier/
      Link to github.com:
      https://github.com/techcnet/LoginFailNotifier
    • By Fokke
      ProcessWire 3.x markup module for rendering meta tags in HTML document head section. Note that this module is not a full-blown SEO solution, but rather a simple tool for rendering meta tags based on module configuration. Adding custom meta tags is also supported.
      Built-in meta tags
      The following meta tags are supported out-of-the-box:
      Document title consisting of page title and site name Character set Canonical Viewport Description Keywords Hreflang tags Open Graph og:title og:site_name og:type og:url og:description og:image og:image:width og:image:height Twitter meta tags twitter:card twitter:site twitter:creator twitter:title twitter:description twitter:image Facebook meta tags fb:app_id The full documentation with configurable options can be found here: https://github.com/Fokke-/MarkupMetadata
       
      Requirements:
      ProcessWire>=3.0.0 PHP >=7.1 Installation using Composer
      composer require fokke/markup-metadata Manual installation
      Download latest version from https://github.com/Fokke-/MarkupMetadata/archive/master.zip Extract module files to site/modules/MarkupMetadata directory.
    • By m.sieber
      ITRK-Service for ProcessWire
      Module for the automated transfer of imprint, data protection declaration and terms and conditions from IT-Recht Kanzlei to your ProcessWire installation
      What is ITRK Service for ProcessWire?
      ITRK-Service for ProcessWire is a free module for ProcessWire CMS. It provides an interface to the update service of IT-Recht Kanzlei, via which the legal texts of your online presence are automatically updated. In this way, the texts remain legally secure and warning-proof in the long term. Imprint, data protection declaration, revocation and general terms and conditions are currently supported.
      You can find our documentation (in german language) here: https://www.pupit.de/itrk-service-for-processwire/dokumentation/

      Download: https://www.pupit.de/itrk-service-for-processwire/
      Github: https://github.com/pupit-de/pwItrkServiceConnector
    • By LuisM
      Symprowire is a PHP MVC Framework based and built on Symfony using ProcessWire 3.x as DBAL and Service-Provider
      It acts as a Drop-In Replacement Module to handle the Request/Response outside the ProcessWire Admin. Even tough Symfony or any other mature MVC Framework could be intimidating at first, Symprowire tries to abstract Configuration and Symfony Internals away as much as possible to give you a quick start and lift the heavy work for you.
      The main Goal is to give an easy path to follow an MVC Approach during development with ProcessWire and open up the available eco-system.
      You can find the GitHub Repo and more Information here: https://github.com/Luis85/symprowire
      Documentation
      The Symprowire Wiki https://github.com/Luis85/symprowire/wiki How to create a simple Blog with Symprowire https://github.com/Luis85/symprowire/wiki/Symprowire-Blog-Tutorial Last Update
      16.07.2021 // RC 1 v0.6.0 centralized ProcessWire access trough out the Application by wrapping to a Service https://github.com/Luis85/symprowire/releases/tag/v0.6.0-rc-1 Requirements
      PHP ^7.4 Fresh ProcessWire ^3.0.181 with a Blank Profile Composer 2 (v1 should work, not recommended) The usual Symfony Requirements Features
      Twig Dependency Injection Monolog for Symprowire Support for .env YAML Configuration Symfony Console and Console Commands Symfony Webprofiler Full ProcessWire access inside your Controller and Services Webpack Encore support Caveats
      Symfony is no small Framework and will come with a price in terms of Memory Usage and added Overhead. To give you a taste I installed Tracy Debugger alongside to compare ProcessWire profiling with the included Symfony Webprofiler

      So in a fresh install Symprowire would atleast add another 2MB of Memory usage and around 40ms in response time, should be less in production due to the added overhead of the Webprofiler in dev env
       
×
×
  • Create New...