Jump to content
Robin S

HannaCodeDialog

Recommended Posts

33 minutes ago, tpr said:

how about adding items that wouldn't require Hanna code module? What I have in mind is having eg a

$config->hannaCodeDialogItems = array( item1 => function () { ... }, ... )

code somewhere in template files so one could easily insert custom items to ckeditor?

Not sure I understand fully, but wouldn't that be reinventing the wheel? Hanna Code already does a great job of allowing the result of any custom code/function to be inserted into a textarea.

35 minutes ago, tpr said:

Perhaps $config could be replaced with $page.

Do you mean so you could have certain tags that are available only on certain pages? Because that is what the getDropdownTags() hook allows for:

 

Share this post


Link to post
Share on other sites

The main motivation is to make the module work without the Hanna code module.

config/page: its just a different approach to have a value available for the module. Perhaps $config is more appropriate here.

Share this post


Link to post
Share on other sites
9 hours ago, Robin S said:

Thanks for the report. Are you running PHP 7.1? I think that's the version that started enforcing stricter numeric values and throwing errors like this.

I tested in PHP7.1 and I can't reproduce this issue. Also, I can't see how this error could be connected to HannaCodeDialog. From what I've read the "non well formed numeric value" error occurs when some arithmetic or other operation that expects an integer receives a string instead. And line 118 of Database.php is:


$timerTotalSinceStart = Debug::timer() - $timerFirstStartTime;

So probably Debug::timer() or $timerFirstStartTime is not an integer, but this is core code that relates to the debug mode tools and HannaCodeDialog has nothing to do with that.

Do you see the error as soon as you install HannaCodeDialog? Do you see it if you have no Hanna codes defined when the module is installed (I'm wondering if the problem is with one of your Hanna codes rather than the module itself)? If you uninstall HannaCodeDialog does the error go away?

 

I will support this in the next version. The intention was to avoid needlessly attaching the plugins to every instance of CKEditor if the textformatter wasn't applied to that field, but I guess to support $hanna->render() there's no way to know if a CKEditor field needs the plugins or not.

 

I'm having trouble understanding exactly what's going wrong for you here. Make sure you meet the prerequisites and have completed the installation process:

  • TextformatterHannaCode must be installed.
  • TextformatterHannaCode must be applied as a textformatter to your CKEditor field.
  • You must have at least one Hanna code created.
  • Install HannaCodeDialog module.
  • Edit the settings for your CKEditor field and in "Input > CKEditor Settings > CKEditor Toolbar" add "HannaDropdown" (to be precise, with a comma space separating it from the other items there)

 

Yes I'm running on PHP 7.1.1 and all of the steps are done.

I switched to PHP 7.0.15 and the error is now gone. PHP 7.0.15 is okay for me - so I can ingore the error for now

 

 

Share this post


Link to post
Share on other sites
15 hours ago, Robin S said:

 

  • TextformatterHannaCode must be installed.
  • TextformatterHannaCode must be applied as a textformatter to your CKEditor field.
  • You must have at least one Hanna code created.
  • Install HannaCodeDialog module.
  • Edit the settings for your CKEditor field and in "Input > CKEditor Settings > CKEditor Toolbar" add "HannaDropdown" (to be precise, with a comma space separating it from the other items there)

Followed this, -> Works

Thanks a lot

Share this post


Link to post
Share on other sites

Is HannaDropdown supposed to work on ProFields Textareas too?

Because I can't get it to show on multiple textareas with CKE, but perfectly on a single CKE textarea. 

PW 3.0.42 and ProFields Textareas 0.0.6

Share this post


Link to post
Share on other sites
10 hours ago, Klenkes said:

Is HannaDropdown supposed to work on ProFields Textareas too?

Well it wasn't something I tested for specifically, but it was pretty easy to add support for ProFields Textareas so I have done that in v0.0.6.

  • Like 2

Share this post


Link to post
Share on other sites

Hi Robin,

Great module. Is the module dialog supposed to allow you to edit existing Hanna Codes? When I double click an existing code, it opens in the dialog but none of the inputs are filled out. If I save, then all of the content disappears.

Another issue I ran into after upgrading to the latest build: The cancel button on the dialog no longer works. The JS error I'm getting is: "hannadialog.js?t=2015030801.157:32 Uncaught TypeError: Cannot read property 'setAttribute' of null"

  • Like 1

Share this post


Link to post
Share on other sites
8 hours ago, thetuningspoon said:

Another issue I ran into after upgrading to the latest build: The cancel button on the dialog no longer works. The JS error I'm getting is: "hannadialog.js?t=2015030801.157:32 Uncaught TypeError: Cannot read property 'setAttribute' of null"

That's a bug, sorry. I missed something in the JS in a recent update. Should be fixed now in v0.0.7.

 

8 hours ago, thetuningspoon said:

Is the module dialog supposed to allow you to edit existing Hanna Codes? When I double click an existing code, it opens in the dialog but none of the inputs are filled out. If I save, then all of the content disappears.

Yes, the module should work for existing Hanna codes. I can't reproduce that issue here. If the v0.0.7 update doesn't fix things for you could you give me some more info: any JS console errors, the PW version, TextformatterHannaCode version, and an export of a Hanna code that you see the issue with? Edit: also please let me know how the Hanna tag looks in your CKEditor field - i.e. are the attribute values inside quotes, single or double?

Share this post


Link to post
Share on other sites

The close button is working now, but opening an existing code now shows a completely blank iframe in the popup.

58efb8190a422_ScreenShot2017-04-13at1_38_15PM.thumb.png.7151845c04b5384bb93fe134a26754c9.png58efb812a1315_ScreenShot2017-04-13at1_38_06PM.thumb.png.2f16545ffb4a792d2bf7a448b5c78e6a.png

PW version is 3.0.40. Hanna code is 0.2.0

Edit: No console errors, either.

Share this post


Link to post
Share on other sites

@thetuningspoon, thanks, I couldn't reproduce the issue exactly as you're seeing it but I think I have found the source of the problem. For some reason I didn't anticipate using long strings of text for attribute values. So I've added support for that in v0.0.8 and now if the length of a value is greater than 50 characters a textarea is used in the dialog instead of a text input. The breakpoint at which a textarea is used is configurable in the module settings.

Please let me know if this doesn't fix the issue for you.

Share this post


Link to post
Share on other sites
2 minutes ago, thetuningspoon said:

Does this also mean that textareas are a configurable input type now?

I had thought it would be nicer if the module decided automatically based on the length of the attribute value you give it, but now that you mention this I can see that my idea won't work very well when inserting a new tag, where the length will be zero until it is populated. So in v0.0.9 I have removed that breakpoint idea and now you can manually specify the textarea inputfield type for an attribute, e.g.

myattribute__type=textarea

 

Share this post


Link to post
Share on other sites

@Robin S Yeah, that makes sense. Just tested the previous build and found that it is still stripping out the long text inputs after re-saving them. Did you resolve this in your latest update?

Share this post


Link to post
Share on other sites
13 minutes ago, thetuningspoon said:

Just tested the previous build and found that it is still stripping out the long text inputs after re-saving them.

v0.1.0: this time hopefully... :)

  • Like 1

Share this post


Link to post
Share on other sites

@thetuningspoon, I just pushed another small change in v0.1.1 to remove any manual line breaks that a user might insert inside a textarea. Manual line breaks cannot be supported because they break the CKEditor tag widget.

Share this post


Link to post
Share on other sites

After using this module for a while, I have a couple of suggestions for future modifications.

First, would it be possible to skip the dialogue window (or auto-close it) if the Hanna code being added does not have any attributes set?  It could still have the on-click behaviour after being added (with the "This tag has no editable attributes" message), to future-proof the tag should the user add attributes in the future. Obviously, one could just type the Hanna code, but it is more convenient for clients to pick it from a list.

Secondly, this isn't really a suggestion, but a custom modification I made to the code for my own purposes, which might be useful to others.

When using selectable option fields (selects, radios, etc), the current method to set the different options is simply:

attribute__options=Option A|Option B|Option C

// The option string format is the same for dyanamically generated options.

With this method, the option field input 'value' and 'text/label' are the same.

However, I found that this was not very user-friendly when the options are somewhat cryptic. Eg, from a returned file list:

  • file123-xyz.pdf
  • abc-1978.pdf
  • xyz-blah123.pdf
  • really-long-title-2017-05-apple-blueberry-banana.pdf

So, what I did was modify the foreach loop code in the file 'iframe_form.php' at line #63, to make it possible to have a separate input value and text.
 

/* Original code at line #63 in iframe_form.php */
foreach ($select_options as $select_option) {
    $f->addOption($select_option);
}

/* My own modification
 * - Searches the option value for '@@'
 * - Uses it to split the string into two variables: $optionValue and $optionText
 * - Then adds the option to the select field.
 */
foreach ($select_options as $select_option) {
    if (strpos($select_option, "@@") !== false) {
        list($optionValue, $optionText) = explode("@@", $select_option);
        $f->addOption($optionValue, $optionText);
    } else {
        $f->addOption($select_option);
    }
}


Now, when setting the options, you specify them (either directly or dynamically) by separating each option's value and text/label with '@@' (chosen because it's unlikely to be part of an option value or text):

attribute__options=file123-xyz.pdf@@Annual Accounts 2016|abc-1978.pdf@@Some Meaningiful Title|xyz-blah123.pdf@@Another Meaningful Title|
really-long-title-2017-05-apple-blueberry-banana.pdf@@The Price of Fruit May 2017

// Note: in reality the above options would be generated dynamically.

 

I would make a pull request (?) via GitHub for this, but I've never used it for such a thing and don't really know how.

 

Edited by LMD
Terrible typos caused by being in a hurry originally.
  • Like 2

Share this post


Link to post
Share on other sites
12 hours ago, LMD said:

First, would it be possible to skip the dialogue window (or auto-close it) if the Hanna code being added does not have any attributes set?

I agree this would be an improvement and will add it in the next release.

 

12 hours ago, LMD said:

Now, when setting the options, you specify them (either directly or dynamically) by separating each option's value and text/label with '@@'

I'm not opposed to adding this as such but I want to be sure that it's the best way forward. Besides making the module usage that bit more complicated, the issue to me is that the tag as it appears in the CKEditor window is readable text - a site editor can look at the tag and it makes some sense. If you display a different string of text in the dialog inputfield than what is inserted into the tag then I think this could be confusing for site editors.

You are saying you have some options where there is a human-friendly label and a not-so-friendly value that you actually need for use inside the tag's code. Wouldn't it be better to only ever show the human-friendly label in the tag and dialog, and then match the label to the needed value inside your Hanna code? So if you, the developer, know that "file123-xyz.pdf" is aka "Annual Accounts 2016" then in your Hanna tag code you have something like:

if($file == 'Annual Accounts 2016') $file = 'file123-xyz.pdf';

Of course you could use switch() for multiple cases, or look up filenames from the descriptions, or match the label to value in whatever way you would have done when assigning "value@@label" under your proposal. Does that make sense? Any other users have an opinion on this?

Share this post


Link to post
Share on other sites
18 hours ago, Robin S said:

I'm not opposed to adding this as such but I want to be sure that it's the best way forward. Besides making the module usage that bit more complicated, the issue to me is that the tag as it appears in the CKEditor window is readable text - a site editor can look at the tag and it makes some sense. If you display a different string of text in the dialog inputfield than what is inserted into the tag then I think this could be confusing for site editors.

Yea there's a trade-off here.  Personally, I think inserting the IDs is the best route since IDs do not change (while text does).  Unless there's a really fancy way to satisfy both needs through some sort of richer CKEditor widget?

Share this post


Link to post
Share on other sites
6 hours ago, Jonathan Lahijani said:

Personally, I think inserting the IDs is the best route since IDs do not change (while text does).

To my way of thinking, numeric IDs are the worst case in terms of being editor friendly. I see HannaCodeDialog as being a kind of progressive enhancement of Hanna Code, such that in the future you could uninstall HannaCodeDialog and still have tags that an editor can understand and use. But with numeric IDs you'll have tags along the lines of...

[[my_tag file="34784" options="4745|9748|8985"]]

And that seems contrary to the whole idea of Hanna Code, which is about giving editors easy to understand options while you the developer do the heavy lifting (be it matching editor-friendly names to IDs or whatever) behind the scenes in the tag code.

Having said that, I'd like the module to be flexible and let devs decide for themselves how they want to use it. So happy to announce...

 

HannaCodeDialog v0.1.2

  • Inserting a tag from the dropdown no longer opens the dialog if the tag has no editable options.
  • A new method prepareOptions() can be hooked in order to define or manipulate the options that can be selected for a tag attribute. See the module readme for more.

 

@LMD, you can hook this new method to set separate value and label as per your proposal:

$wire->addHookAfter('HannaCodeDialog::prepareOptions', function($event) {
    $options = $event->return;
    $new_options = array();
    foreach($options as $option) {
        if(strpos($option, '@@') !== false) {
            list($value, $label) = explode('@@', $option);
            $new_options[$value] = $label;
        } else {
            $new_options[$option] = $option;
        }
    }
    $event->return = $new_options;
});

 

  • Like 5

Share this post


Link to post
Share on other sites
5 hours ago, Robin S said:

HannaCodeDialog v0.1.2

  • Inserting a tag from the dropdown no longer opens the dialog if the tag has no editable options.
  • A new method prepareOptions() can be hooked in order to define or manipulate the options that can be selected for a tag attribute. See the module readme for more.

@Robin S Jonathan's concern regarding the stability of 'IDs' vs. 'text' was one of my concerns. After thinking about it, I was going to suggest if a hookable method was possible, so this makes me happy.  I'll try it out today and report back!

 

  • Like 1

Share this post


Link to post
Share on other sites
On 5/23/2017 at 2:50 AM, LMD said:

@Robin S Jonathan's concern regarding the stability of 'IDs' vs. 'text' was one of my concerns. After thinking about it, I was going to suggest if a hookable method was possible, so this makes me happy.  I'll try it out today and report back!

 

I tested out the new version and it works really well.  Thanks @Robin S.

  • Like 1

Share this post


Link to post
Share on other sites

i was having trouble getting this – i had these as attributes

underline__type=radios
underline__options=None|Top|Bottom|Both
underline__description=Please select your border options.

but not working, so i tried this:

underline
underline__type=radios
underline__options=None|Top|Bottom|Both
underline__description=Please select your border options.

and it works;

i don't think this is clear from the instructions – would be great if there were more working examples to copy/paste, in the cheatsheet

  • Like 1

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 Robin S
      After forgetting the class name of the wonderful AdminPageFieldEditLinks module for what feels like the 100th time I decided I needed to give my failing memory a helping hand...
      Autocomplete Module Class Name
      Provides class name autocomplete suggestions for the "Add Module From Directory" field at Modules > New.
      Requires ProcessWire >= v3.0.16.
      Screencast

      Installation
      Install the Autocomplete Module Class Name module.
      Configuration
      Choose the type of autocomplete options list: "Module class names from directory" or "Custom list of module class names". The latter could be useful if you regularly install some modules and would prefer a shorter list of autocomplete suggestions. The list of class names in the modules directory is generated when the Autocomplete Module Class Name module is installed. It doesn't update automatically (because the retrieval of the class names is quite slow), but you can use the button underneath when you want to retrieve an updated list of class names from the directory. The "fuzzy search" option uses custom filter and item functions for Awesomplete so that the characters you type just have to exist in the module class name and occur after preceding matches but do not need to be contiguous. Uncheck this option if you prefer the standard Awesomplete matching. Custom settings for Awesomplete can be entered in the "Awesomplete options" field if needed. See the Awesomplete documentation for more information.  
      https://github.com/Toutouwai/AutocompleteModuleClassName
      https://modules.processwire.com/modules/autocomplete-module-class-name/
    • By teppo
      MarkupMenu is a markup module for generating menu trees. When provided a root page as a starting point, it generates a navigation tree (by default as a HTML "<ul>" element wrapped by a "<nav>" element) from that point onwards. If you've also provided it with current (active) page, the menu will be rendered accordingly, with current item highlighted and items rendered up to that item and its children (unless you disable the "collapsed" option, in which case the full page tree will be rendered instead).
      Modules directory: https://modules.processwire.com/modules/markup-menu/ GitHub repository: https://github.com/teppokoivula/MarkupMenu Usage
      As a markup module, MarkupMenu is intended for front-end use, but you can of course use it in a module as well. Typically you'll only need the render() method, which takes an array of options as its only argument:
      echo $modules->get('MarkupMenu')->render([ 'root_page' => $pages->get(1), 'current_page' => $page, ]); Note: if you omit root_page, site root page is used by default. If you omit current_page, the menu will be rendered, but current (active) page won't be highlighted etc.
      A slightly more complex example, based on what I'm using on one of my own sites to render a (single-level) top menu:
      echo $modules->get('MarkupMenu')->render([ 'current_page' => $page, 'templates' => [ 'nav' => '<nav class="{classes} menu--{menu_class_modifier}" aria-label="{aria_label}">%s</nav>', 'item_current' => '<a class="menu__item menu__item--current" href="{item.url}" tabindex="0" aria-label="Current page: {item.title}">{item.title}</a>', ], 'placeholders' => [ 'menu_class_modifier' => 'top', 'aria_label' => 'Main navigation', ], 'include' => [ 'root_page' => true, ], 'exclude' => [ 'level_greater_than' => 1, ], ]); Note: some things you see above may not be entirely sensible, such as the use of {menu_class_modifier} and {aria_label} placeholders. On the actual site the "nav" template is defined in site config, so I can define just these parts on a case-by-case basis while actual nav markup is maintained in one place.
      Please check out the README file for available render options. I'd very much prefer not to keep this list up to date in multiple places. Basically there are settings for defining "templates" for different parts of the menu (list, item, etc.), include array for defining rules for including in the menu and exclude array for the opposite effect, classes and placeholders arrays for overriding default classes and injecting custom placeholders, etc. 🙂
      MarkupMenu vs. MarkupSimpleNavigation
      TL;DR: this is another take on the same concept. There are many similarities, but also some differences – especially when it comes to the supported options and syntax. If you're currently using MarkupSimpleNavigation then there's probably no reason to switch over.
      I'd be surprised if anyone didn't draw lines between this module and Soma's awesome MarkupSimpleNavigation. Simply put, I've been using MSN (...) for a number of years, and it's been great – but there have been some smallish issues with it, particularly with the markup generation part, and it's also doing some things in a way that just doesn't work for me – the xtemplates thing being one of these. In many ways it's less about features, and more about style.
      In MarkupMenu I've tried to correct these little hiccups, modernise the default markup, and allow for more flexibility with placeholder variables and additional / different options. MarkupMenu was built for ProcessWire 3.0.112+ and PHP 7.1+, it's installable with Composer, and I have a few additional ideas (such as conditional placeholders) on my todo list.
      One smallish and rather specific difference is that MarkupMenu supports overriding default options via $config->MarkupMenu. I find myself redefining the default markup for every site, which until now meant that each site has a wrapper function for MarkupSimpleNavigation (to avoid code / config repetition), and this way I've been able to omit that 🙂
      Requirements
      ProcessWire >= 3.0.112 PHP >= 7.1.0 If you're working on an earlier version of ProcessWire or PHP, use MarkupSimpleNavigation instead.
    • By Robin S
      Repeater Images
      Adds options to modify Repeater fields to make them convenient for "page-per-image" usage. Using a page-per-image approach allows for additional fields to be associated with each image, to record things such as photographer, date, license, links, etc.
      When Repeater Images is enabled for a Repeater field the module changes the appearance of the Repeater inputfield to be similar (but not identical) to an Images field. The collapsed view shows a thumbnail for each Repeater item, and items can be expanded for field editing.
      Screencast

      Installation
      Install the Repeater Images module.
      Setup
      Create an image field to use in the Repeater field. Recommended settings for the image field are "Maximum files allowed" set to 1 and "Formatted value" set to "Single item (null if empty)". Create a Repeater field. Add the image field to the Repeater. If you want additional fields in the Repeater create and add these also. Repeater Images configuration
      Tick the "Activate Repeater Images for this Repeater field" checkbox. In the "Image field within Repeater" dropdown select the single image field. You must save the Repeater field settings to see any newly added Image fields in the dropdown. Adjust the image thumbnail height if you want (unlike the core Images field there is no slider to change thumbnail height within Page Edit). Note: the depth option for Repeater fields is not compatible with the Repeater Images module.
      Image uploads feature
      There is a checkbox to activate image uploads. This feature allows users to quickly and easily add images to the Repeater Images field by uploading them to an adjacent "upload" field.
      To use this feature you must add the image field selected in the Repeater Images config to the template of the page containing the Repeater Images field - immediately above or below the Repeater Images field would be a good position.
      It's recommended to set the label for this field in template context to "Upload images" or similar, and set the visibility of the field to "Closed" so that it takes up less room when it's not being used. Note that when you drag images to a closed Images field it will automatically open. You don't need to worry about the "Maximum files allowed" setting because the Repeater Images module overrides this for the upload field.
      New Repeater items will be created from the images uploaded to the upload field when the page is saved. The user can add descriptions and tags to the images while they are still in the upload field and these will be retained in the Repeater items. Images are automatically deleted from the upload field when the page is saved.
      Tips
      The "Use accordion mode?" option in the Repeater field settings is useful for keeping the inputfield compact, with only one image item open for editing at a time. The "Repeater item labels" setting determines what is shown in the thumbnail overlay on hover. Example for an image field named "image": {image.basename} ({image.width}x{image.height})  
      https://github.com/Toutouwai/RepeaterImages
      https://modules.processwire.com/modules/repeater-images/
    • By EyeDentify
      Hello There Guys.

      I am in the process of getting into making my first modules for PW and i had a question for you PHP and PW gurus in here.

      I was wondering how i could use an external library, lets say TwitterOAuth in my PW module.
      Link to library
      https://twitteroauth.com/

      Would the code below be correct or how would i go about this:
      <?PHP namespace ProcessWire; /* load the TwitterOAuth library from my Module folder */ require "twitteroauth/autoload.php"; use Abraham\TwitterOAuth\TwitterOAuth; class EyeTwitter extends WireData,TwitterOAuth implements Module { /* vars */ protected $twConnection; /* extend parent TwitterOAuth contructor $connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $access_token, $access_token_secret); */ public function myTwitterConnection ($consumer_key, $consumer_secret, $access_token, $access_token_secret) { /* save the connection for use later */ $this->twConnection = TwitterOAuth::__construct($consumer_key, $consumer_secret, $access_token, $access_token_secret); } } ?> Am i on the right trail here or i am barking up the wrong tree?
      I don´t need a complete solution, i just wonder if i am including the external library the right way.
      If not, then give me a few hint´s and i will figure it out.

      Thanks a bunch.

      /EyeDentify
    • By dimitrios
      Hello,
      this module can publish content of a Processwire page on a Facebook page, triggered by saving the Processwire page.
      To set it up, configure the module with a Facebook app ID, secret and a Page ID. Following is additional configuration on Facebook for developers:
      Minimum Required Facebook App configuration:
      on Settings -> Basics, provide the App Domains, provide the Site URL, on Settings -> Advanced, set the API version (has been tested up to v3.3), add Product: Facebook Login, on Facebook Login -> Settings, set Client OAuth Login: Yes, set Web OAuth Login: Yes, set Enforce HTTPS: Yes, add "http://www.example.com/processwire/page/" to field Valid OAuth Redirect URIs. This module is configurable as follows:
      Templates: posts can take place only for pages with the defined templates. On/Off switch: specify a checkbox field that will not allow the post if checked. Specify a message and/or an image for the post.
      Usage
      edit the desired PW page and save; it will post right after the initial Facebook log in and permission granting. After that, an access token is kept.
       
      Download
      PW module directory: http://modules.processwire.com/modules/auto-fb-post/ Github: https://github.com/kastrind/AutoFbPost   Note: Facebook SDK for PHP is utilized.


×
×
  • Create New...