Jump to content
Robin S

HannaCodeDialog

Recommended Posts

@MilenKo, it's not possible to have a required field in the dialog because the dialog form is not submitted anywhere for ProcessWire validation - the field values are just captured via Javascript when the dialog is closed. You should check for empty field values in the code for your Hanna tag.

Incidentally, this is true for any "required" field anywhere in PW because nothing is ever really required - the user can simply abandon the edit process if they want and leave unfilled required fields, so you always need to check that fields are actually populated before doing anything with their value.

  • Like 1

Share this post


Link to post
Share on other sites

@Robin S Thanks for your clarification. I was afraid you would say so, but was just thinking if it would be possible for me to modify the dialogue files and have an extra option added like the other attribute options - something like:

attribute__options=Option1|Option2 but with some extra logic:

attribute__requirements=required or similar.

My idea is that from the dropdown menu, the user is provided a choice of multiple blocks and once one is selected, the dialogue opens up and can intercept an eventual requirement set thorugh the module. Once the user has finished and press OK, if he double clicks on the HC he is still seeing the same code so technically it would be difficult for the user to change the text etc. and is presented a nice "reminder" of an empty attribute or else.

On the other thought, the present functionality might be a better option for me as I am allowing a user to choose a news tab category (1 out of 10) so he can leave 1 empty, 2 empty and then add 3, 4 etc. 

Will see how it would be completted to fit the requirements and avoid any errors as presently I am grouping all the attributes to an array, then have to clean the empty values, then to reorder and then to apply it. But hey, it works and it was super easy for my 8 years old boy I've tested with to add the block, pick categories, limit the number of pages shown etc. GREAT THANK YOU FOR THE EFFORTS AND MODULE!

  • Like 1

Share this post


Link to post
Share on other sites

Btw, is it possible to set the width/height of the dialogue box (width/height) as presently I have about 10 drop-down boxes for categories plus some other limiters to show a specific page count on the block so the scrolling is not very convenient? Maybe I can make the dialogue wider through some options or else? I mean if it is possible to have the options per tag, not by default?

Share this post


Link to post
Share on other sites
16 hours ago, MilenKo said:

I mean if it is possible to have the options per tag, not by default?

No, that isn't possible in this module - the dialog width and height in the module config applies globally to all Hanna tags.

Share this post


Link to post
Share on other sites

@Robin S Thank you for your info. Would it be possible to have an option to set the width and height of the dialogue for all Hanna Tags which would make my options visible better or I would have to set the dimensions by editing the module files?

Share this post


Link to post
Share on other sites
8 minutes ago, MilenKo said:

Would it be possible to have an option to set the width and height of the dialogue for all Hanna Tags which would make my options visible better or I would have to set the dimensions by editing the module files?

As per my previous reply and the module readme there are config options for dialog width and height.

2019-05-03_103012.thumb.png.1fba36d23e2f388488f63b229fffd004.png

Or maybe I don't understand your question.

  • Thanks 1

Share this post


Link to post
Share on other sites

Oh, @Robin S my bad. I don't know how but I've missed to check the module configuration page and was looking at the tag options again. It works perfectly now and I can increase the size from there as most of my tags would require bigger window. Thank you again for the help.

  • Like 1

Share this post


Link to post
Share on other sites
Posted (edited)

v0.2.1 released.

This is a fairly major update in that there has been quite a bit of refactoring. Please be alert for and report any issues. ProcessWire >= v3.0.0 is now required.

This release adds a new hookable HannaCodeDialog::buildForm() method that lets you build the dialog form in the hook rather than setting inputfield options as pseudo-attributes in the Hanna Code tag settings.

From the readme...

Build entire dialog form in a hook

You can hook after HannaCodeDialog::buildForm to add inputfields to the dialog form. You can define options for the inputfields when you add them. Using a hook like this can be useful if you prefer to configure inputfield type/options/descriptions/notes in your IDE rather than as extra attributes in the Hanna tag settings. It's also useful if you want to use inputfield settings such as showIf.

When you add the inputfields you must set both the name and the id of the inputfield to match the attribute name.

You only need to set an inputfield value in the hook if you want to force the value - otherwise the current values from the tag are automatically applied.

To use this hook you only have to define the essential attributes (the "fields" for the tag) in the Hanna Code settings and then all the other inputfield settings can be set in the hook.

Example buildForm() hook

The Hanna Code attributes defined for tag "meal" (a default value is defined for "vegetables"):

vegetables=Carrot
meat
cooking_style
comments

The hook code in /site/ready.php:

$wire->addHookAfter('HannaCodeDialog::buildForm', function(HookEvent $event) {

    // The Hanna tag that is being opened in the dialog
    $tag_name = $event->arguments(0);

    // Other arguments if you need them
    /* @var Page $edited_page */
    $edited_page = $event->arguments(1); // The page open in Page Edit
    $current_attributes = $event->arguments(2); // The current attribute values
    $default_attributes = $event->arguments(3); // The default attribute values

    // The form rendered in the dialog
    /* @var InputfieldForm $form */
    $form = $event->return;

    if($tag_name === 'meal') {

        $modules = $event->wire('modules');

        /* @var InputfieldCheckboxes $f */
        $f = $modules->InputfieldCheckboxes;
        $f->name = 'vegetables'; // Set name to match attribute
        $f->id = 'vegetables'; // Set id to match attribute
        $f->label = 'Vegetables';
        $f->description = 'Please select some vegetables.';
        $f->notes = "If you don't eat your vegetables you can't have any pudding.";
        $f->addOptions(['Carrot', 'Cabbage', 'Celery'], false);
        $form->add($f);

        /* @var InputfieldRadios $f */
        $f = $modules->InputfieldRadios;
        $f->name = 'meat';
        $f->id = 'meat';
        $f->label = 'Meat';
        $f->addOptions(['Pork', 'Beef', 'Chicken', 'Lamb'], false);
        $form->add($f);

        /* @var InputfieldSelect $f */
        $f = $modules->InputfieldSelect;
        $f->name = 'cooking_style';
        $f->id = 'cooking_style';
        $f->label = 'How would you like it cooked?';
        $f->addOptions(['Fried', 'Boiled', 'Baked'], false);
        $form->add($f);

        /* @var InputfieldText $f */
        $f = $modules->InputfieldText;
        $f->name = 'comments';
        $f->id = 'comments';
        $f->label = 'Comments for the chef';
        $f->showIf = 'cooking_style=Fried';
        $form->add($f);

    }

});
Edited by Robin S
Updated version number
  • Like 7

Share this post


Link to post
Share on other sites

 I have HannaCode that generates a message box. The user is allowed to make some words bold in the 'test' field of the message box:

[[MessageBox type="warning" icon="yes" text="Claims filed between <strong>February 16 - December 10</strong> will receive a partial exemption for that year."]]

The HannaCodeDialog won't recognize this as a valid HannaCode tag though. It just leaves it as is and doesn't convert it to a widget. The same happens if there is a link definition (<a href.....).

Is there any remedy to this?

Share this post


Link to post
Share on other sites

@msavard, in this module HTML tags are not supported inside attributes. But you could use Markdown for the same result, for example:

In your attribute: 

Claims filed between **February 16 - December 10** will receive a [partial exemption](https://www.google.com) for that year.

In your Hanna Tag code:

<div class="message-box"><?= $sanitizer->entitiesMarkdown($text) ?></div>

 

Share this post


Link to post
Share on other sites

That is very helpful, thank you! I didn't even know about that function. I will try it out tomorrow.

 

Share this post


Link to post
Share on other sites

Hey @Robin S I've been playing this weekend with HannaCode + Dialogue and was wondering, would you know a way to provide a label for the attribute options? Presently I have the following list of attributes:

Post_sorting_order
Post_sorting_order__options=date|-date|title|-title|phits|-phits|recipe_comments.count|-recipe_comments.count
Post_sorting_order__description=Negative sign means reverse order

and I am trying to presend the options in a more human readable form (eg. "-date" to become "Date - asscending") etc. It is not much to leave it as it is, however presently to sort by comments count I am using the fieldname.count instead of something like: Comments count (ascending/descending). I've tried to modify the module to have a value of the options like:

Post_sorting_order__options=date*Date(Ascending)|-date*Date(Descending) etc. but so far I was not able to modify the code to make it work..

Share this post


Link to post
Share on other sites
1 hour ago, MilenKo said:

would you know a way to provide a label for the attribute options?

This is possible if you use a hook to build the dialog form. See the example in the module readme. You would define the options like this:

$wire->addHookAfter('HannaCodeDialog::buildForm', function(HookEvent $event) {

	// The Hanna tag that is being opened in the dialog
	$tag_name = $event->arguments(0);

	// Other arguments if you need them
	/* @var Page $edited_page */
	$edited_page = $event->arguments(1); // The page open in Page Edit
	$current_attributes = $event->arguments(2); // The current attribute values
	$default_attributes = $event->arguments(3); // The default attribute values

	// The form rendered in the dialog
	/* @var InputfieldForm $form */
	$form = $event->return;

	if($tag_name === 'your_hanna_tag_name') {

		$modules = $event->wire('modules');

		/* @var InputfieldSelect $f */
		$f = $modules->InputfieldSelect;
		$f->name = 'Post_sorting_order';
		$f->id = 'Post_sorting_order';
		$f->addOptions([
			'recipe_comments.count' => 'Recipe comments',
			'-recipe_comments.count' => 'Recipe comments (descending)',
			// etc
		]);
		$form->add($f);

	}

});

Or if you don't want to use a hook you just need to do the work of converting the labels into the values you want to sort by in the Hanna tag code. For example:

switch($Post_sorting_order) {
	case 'Recipe comments':
		$sort = 'recipe_comments.count';
		break;
	case 'Recipe comments (descending)':
		$sort = '-recipe_comments.count';
		break;
	// etc
}

 

  • Thanks 1

Share this post


Link to post
Share on other sites

Hey,@Robin S thank you very much for the quick and useful info. I was playing with some ifs to have a name in the sorting and then convert it to the actual sorting form, however the 'case' switch seems much cleaner and simpler than my code. I will run a test with it and see how it would come out, but I am sure it would be perfect.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Gadgetto
      Status update links (inside this thread) for SnipWire development will be always posted here:
      2019-11-15 2019-10-18 2019-08-08 2019-06-15 2019-06-02 2019-05-25 If you are interested, you can test the current state of development:
      https://github.com/gadgetto/SnipWire
      Please note that the software is not yet intended for use in a production system (alpha version).
      If you like, you can also submit feature requests and suggestions for improvement. I also accept pull requests.
      ---- INITIAL POST FROM 2019-05-25 ----
      I wanted to let you know that I am currently working on a new ProcessWire module that fully integrates the Snipcart Shopping Cart System into ProcessWire. (this is a customer project, so I had to postpone the development of my other module GroupMailer).
      The new module SnipWire offers full integration of the Snipcart Shopping Cart System into ProcessWire.
      Here are some highlights:
      simple setup with (optional) pre-installed templates, product fields, sample products (quasi a complete shop system to get started immediately) store dashboard with all data from the snipcart system (no change to the snipcart dashboard itself required) Integrated REST API for controlling and querying snipcart data webhooks to trigger events from Snipcart (new order, new customer, etc.) multi currency support self-defined/configurable tax rates etc. Development is already well advanced and I plan to release the module in the next 2-3 months.
      I'm not sure yet if this will be a "Pro" module or if it will be made available for free.
      I would be grateful for suggestions and hints!
      (please have a look at the screenshots to get an idea what I'm talking about)
       




    • By horst
      Wire Mail SMTP

      An extension to the (new) WireMail base class that uses SMTP-transport

      This module integrates EmailMessage, SMTP and SASL php-libraries from Manuel Lemos into ProcessWire. I use this continously evolved libraries for about 10 years now and there was never a reason or occasion not to do so. I use it nearly every day in my office for automated composing and sending personalized messages with attachments, requests for Disposition Notifications, etc. Also I have used it for sending personalized Bulkmails many times.

      The WireMailSmtp module extends the new email-related WireMail base class introduced in ProcessWire 2.4.1 (while this writing, the dev-branch only).
       
      Here are Ryans announcement.



      Current Version 0.4.2
      Changelog: https://github.com/horst-n/WireMailSmtp/blob/master/CHANGELOG.md
      get it from the Modules Directory Install and Configure

      Download the module into your site/modules/ directory and install it.

      In the config page you fill in settings for the SMTP server and optionaly the (default) sender, like email address, name and signature.
      You can test the smtp settings directly there. If it says "SUCCESS! SMTP settings appear to work correctly." you are ready to start using it in templates, modules or bootstrap scripts.


      Usage Examples
      The simplest way to use it:
      $numSent = wireMail($to, $from, $subject, $textBody); $numSent = wireMail($to, '', $subject, $textBody); // or with a default sender emailaddress on config page This will send a plain text message to each recipient.
       
      You may also use the object oriented style:
      $mail = wireMail(); // calling an empty wireMail() returns a wireMail object $mail->to($toEmail, $toName); $mail->from = $yourEmailaddress; // if you don't have set a default sender in config // or if you want to override that $mail->subject($subject); $mail->body($textBody); $numSent = $mail->send(); Or chained, like everywhere in ProcessWire:
      $mail = wireMail(); $numSent = $mail->to($toEmail)->subject($subject)->body($textBody)->send(); Additionaly to the basics there are more options available with WireMailSmtp. The main difference compared to the WireMail BaseClass is the sendSingle option. With it you can set only one To-Recipient but additional CC-Recipients.
      $mail = wireMail(); $mail->sendSingle(true)->to($toEmail, $toName)->cc(array('person1@example.com', 'person2@example.com', 'person3@example.com')); $numSent = $mail->subject($subject)->body($textBody)->send(); The same as function call with options array:
      $options = array( 'sendSingle' => true, 'cc' => array('person1@example.com', 'person2@example.com', 'person3@example.com') ); $numSent = wireMail($to, '', $subject, $textBody, $options); There are methods to your disposal to check if you have the right WireMail-Class and if the SMTP-settings are working:
      $mail = wireMail(); if($mail->className != 'WireMailSmtp') { // Uups, wrong WireMail-Class: do something to inform the user and quit echo "<p>Couldn't get the right WireMail-Module (WireMailSmtp). found: {$mail->className}</p>"; return; } if(!$mail->testConnection()) { // Connection not working: echo "<p>Couldn't connect to the SMTP server. Please check the {$mail->className} modules config settings!</p>"; return; }  
      A MORE ADVANCED DEBUG METHOD!
      You can add some debug code into a template file and call a page with it:
      $to = array('me@example.com'); $subject = 'Wiremail-SMTP Test ' . date('H:i:s') . ' äöü ÄÖÜ ß'; $mail = wireMail(); if($mail->className != 'WireMailSmtp') { echo "<p>Couldn't get the right WireMail-Module (WireMailSmtp). found: {$mail->className}</p>"; } else { $mail->from = '--INSERT YOUR SENDER ADDRESS HERE --'; // <--- !!!! $mail->to($to); $mail->subject($subject); $mail->sendSingle(true); $mail->body("Titel\n\ntext text TEXT text text\n"); $mail->bodyHTML("<h1>Titel</h1><p>text text <strong>TEXT</strong> text text</p>"); $dump = $mail->debugSend(1); } So, in short, instead of using $mail->send(), use $mail->debugSend(1) to get output on a frontend testpage.
      The output is PRE formatted and contains the areas: SETTINGS, RESULT, ERRORS and a complete debuglog of the server connection, like this one:
       
      Following are a ...


      List of all options and features


      testConnection () - returns true on success, false on failures


      sendSingle ( true | false ) - default is false

      sendBulk ( true | false ) - default is false, Set this to true if you have lots of recipients (50+)


      to ($recipients) - one emailaddress or array with multiple emailaddresses

      cc ($recipients) - only available with mode sendSingle, one emailaddress or array with multiple emailaddresses

      bcc ($recipients) - one emailaddress or array with multiple emailaddresses

       
      from = 'person@example.com' - emailaddress, can be set in module config (called Sender Emailaddress) but it can be overwritten here

      fromName = 'Name Surname' - optional, can be set in module config (called Sender Name) but it can be overwritten here


      priority (3) - 1 = Highest | 2 = High | 3 = Normal | 4 = Low | 5 = Lowest

      dispositionNotification () or notification () - request a Disposition Notification


      subject ($subject) - subject of the message

      body ($textBody) - use this one alone to create and send plainText emailmessages

      bodyHTML ($htmlBody) - use this to create a Multipart Alternative Emailmessage (containing a HTML-Part and a Plaintext-Part as fallback)

      addSignature ( true | false ) - the default-behave is selectable in config screen, this can be overridden here
      (only available if a signature is defined in the config screen)

      attachment ($filename, $alternativeBasename = "") - add attachment file, optionally alternative basename


      send () - send the message(s) and return number of successful sent messages


      debugSend(1) - returns and / or outputs a (pre formatted) dump that contains the areas: SETTINGS, RESULT, ERRORS and a complete debuglog of the server connection. (See above the example code under ADVANCED DEBUG METHOD for further instructions!)


      getResult () - returns a dump (array) with all recipients (to, cc, bcc) and settings you have selected with the message, the message subject and body, and lists of successfull addresses and failed addresses,


      logActivity ($logmessage) - you may log success if you want

      logError ($logmessage) - you may log warnings, too. - Errors are logged automaticaly
       
       
      useSentLog (true | false) - intended for usage with e.g. third party newsletter modules - tells the send() method to make usage of the sentLog-methods - the following three sentLog methods are hookable, e.g. if you don't want log into files you may provide your own storage, or add additional functionality here

      sentLogReset ()  - starts a new LogSession - Best usage would be interactively once when setting up a new Newsletter

      sentLogGet ()  - is called automaticly within the send() method - returns an array containing all previously used emailaddresses

      sentLogAdd ($emailaddress)  - is called automaticly within the send() method
      Changelog: https://github.com/horst-n/WireMailSmtp/blob/master/CHANGELOG.md
       
       
    • By Robin S
      Sanitizer EasySlugger
      Allows the use of the EasySlugger library as Sanitizer methods.
      Installation
      Install the Sanitizer EasySlugger module.
      Usage
      The module adds four new sanitizer methods.
      slugger($string, $options)
      Similar to $sanitizer->pageName() - I'm not sure if there are any advantages over that method. Included because it is one of the methods offered by EasySlugger.
      $slug = $sanitizer->slugger('Lorem Ipsum'); // Result: lorem-ipsum utf8Slugger($string, $options)
      Creates slugs from non-latin alphabets.
      $slug = $sanitizer->utf8Slugger('这个用汉语怎么说'); // Result: zhe-ge-yong-han-yu-zen-me-shuo seoSlugger($string, $options)
      Augments the string before turning it into a slug. The conversions are related to numbers, currencies, email addresses and other common symbols.
      $slug = $sanitizer->seoSlugger('The price is $5.99'); // Result: the-price-is-5-dollars-99-cents See the EasySlugger readme for some more examples.
      seoUtf8Slugger($string, $options)
      A combination of utf8Slugger() and seoSlugger().
      $slug = $sanitizer->seoUtf8Slugger('价钱是 $5.99'); // Result: jia-qian-shi-5-dollars-99-cents $options argument
      Each of the methods can take an $options array as a second argument.
      separator (string): the character that separates words in the slug. Default: - unique (bool): Determines whether a random suffix is added at the end of the slug. Default: false $slug = $sanitizer->utf8Slugger('这个用汉语怎么说', ['separator' => '_', 'unique' => true]); // Result: zhe_ge_yong_han_yu_zen_me_shuo_3ad66c4  
      https://github.com/Toutouwai/SanitizerEasySlugger
      https://modules.processwire.com/modules/sanitizer-easy-slugger/
    • By Robin S
      If you've ever needed to insert links to a large number of files within CKEditor you may have found that the standard PW link modal is a somewhat slow way to do it.
      This module provides a quicker way to insert links to files on the page being edited. You can insert a link to an individual file, or insert an unordered list of links to all files on the page with a single click.
      CKEditor Link Files
      Adds a menu to CKEditor to allow the quick insertion of links to files on the page being edited.

      Features
      Hover a menu item to see the "Description" of the corresponding file (if present). Click a menu item to insert a link to the corresponding file at the current cursor position. The filename is used as the link text. If you Alt-click a menu item the file description is used as the link text (with fallback to filename if no description entered). If text is currently selected in the editor then the selected text is used as the link text. Click "* Insert links to all files *" to insert an unordered list of links to all files on the page. Also works with the Alt-click option. Menu is built via AJAX so newly uploaded files are included in the menu without the page needing to be saved. However, descriptions are not available for newly uploaded files until the page is saved. There is an option in the module config to include files from Repeater fields in the edited page. Nested Repeater fields (files inside a Repeater inside another Repeater) are not supported. Installation
      Install the CKEditor Link Files module.
      For any CKEditor field where you want the "Insert link to file" dropdown menu to appear in the CKEditor toolbar, visit the field settings and add "LinkFilesMenu" to the "CKEditor Toolbar" settings field.
       
      http://modules.processwire.com/modules/cke-link-files/
      https://github.com/Toutouwai/CkeLinkFiles
    • By David Karich
      ProcessWire InputfieldRepeaterMatrixDuplicate
      Thanks to the great ProModule "RepeaterMatrix" I have the possibility to create complex repeater items. With it I have created a quite powerful page builder. Many different content modules, with many more possible design options. The RepeaterMatrix module supports the cloning of items, but only within the same page. Now I often have the case that very design-intensive pages and items are created. If you want to use a content module on a different page (e.g. in the same design), you have to rebuild each item manually every time.
      This module extends the commercial ProModule "RepeaterMatrix" by the function to duplicate repeater items from one page to another page. The condition is that the target field is the same matrix field from which the item is duplicated. This module is currently understood as proof of concept. There are a few limitations that need to be considered. The intention of the module is that this functionality is integrated into the core of RepeaterMatrix and does not require an extra module.
      Check out the screencast
      What the module can do
      Duplicate a repeater item from one page to another No matter how complex the item is Full support for file and image fields Multilingual support Support of Min and Max settings Live synchronization of clipboard between multiple browser tabs. Copy an item and simply switch the browser tab to the target page and you will immediately see the past button Support of multiple RepeaterMatrix fields on one page Configurable which roles and fields are excluded Duplicated items are automatically pasted to the end of the target field and set to hidden status so that changes are not directly published Automatic clipboard update when other items are picked Automatically removes old clipboard data if it is not pasted within 6 hours Delete clipboard itself by clicking the selected item again Benefit: unbelievably fast workflow and content replication What the module can't do
      Before an item can be duplicated in its current version, the source page must be saved. This means that if you make changes to an item and copy this, the old saved state will be duplicated Dynamic loading is currently not possible. Means no AJAX. When pasting, the target page is saved completely No support for nested repeater items. Currently only first level items can be duplicated. Means a repeater field in a repeater field cannot be duplicated. Workaround: simply duplicate the parent item Dynamic reloading and adding of repeater items cannot be registered. Several interfaces and events from the core are missing. The initialization occurs only once after the page load event Changelog
      1.0.4
      Bug fix: Various bug fixes and improvements in live synchronization Bug fix: Items are no longer inserted when the normal save button is clicked. Only when the past button is explicitly clicked Feature: Support of multiple repeater fields in one page Feature: Support of repeater Min/Max settings Feature: Configurable roles and fields Enhancement: Improved clipboard management Enhancement: Documentation improvement Enhancement: Corrected few typos #1 1.0.3
      Feature: Live synchronization Enhancement: Load the module only in the backend Enhancement: Documentation improvement 1.0.2
      Bug fix: Various bug fixes and improvements in JS functions Enhancement: Documentation improvement Enhancement: Corrected few typos 1.0.1
      Bug fix: Various bug fixes and improvements in the duplication process 1.0.0
      Initial release Support this module
      If this module is useful for you, I am very thankful for your small donation: Donate 5,- Euro (via PayPal – or an amount of your choice. Thank you!)
      Download this module
      > Github: https://github.com/FlipZoomMedia/InputfieldRepeaterMatrixDuplicate
      > PW module directory: https://modules.processwire.com/modules/inputfield-repeater-matrix-duplicate/
×
×
  • Create New...