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

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


  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By daniels
      General
      This is a lightweight alternative to other newsletter & newsletter-subscription modules.
      It can subscribe, update, unsubscribe & delete a user in a list in Mailchimp with MailChimp API 3.0. It does not provide any forms or validation, so you can feel free to use your own. To protect your users, it does not save any user data in logs or sends them to an admin.
      This module fits your needs if you...
      ...use Mailchimp as your newsletter / email-automation tool ...want to let users subscribe to your newsletter on your website ...want to use your own form, validation and messages (with or without the wire forms) ...don't want any personal user data saved in any way in your ProcessWire environment (cf. EU data regulation terms) ...like to subscribe, update, unsubscribe or delete users to/from different lists ...like the Mailchimp UI for creating / sending / reviewing email campaigns You can find it here: https://github.com/danielstieber/SubscribeToMailchimp
      Let me know what you think and if I should add it to the Modules Directory.
      Setup
      Log into your Mailchimp account and go to  Profile > Extras > API Keys. If you don't have an API Key, create a new one. Copy your API Key and paste it in the module settings (Processwire > Modules > Site > SubscribeToMailchimp). Back in Mailchimp, go to the list, where you want your new subscribers. Go to Settings > List name and defaults. Copy the List ID an paste it in to the module settings.
      Usage
      To use the module, you need to load it into your template:
      $mc = $modules->get("SubscribeToMailchimp"); Now you can pass an email address to the module and it will try to edit (if the user exists) or create a new subscriber in your list.
      $mc->subscribe('john.doe@example.com'); You can also pass a data array, to add additional info.
      $mc->subscribe('john.doe@example.com', ['FNAME' => 'John', 'LNAME' => 'Doe']); You can even choose an alternative list, if you don't want this subscriber in your default list.
      $mc->subscribe('john.doe@example.com', ['FNAME' => 'John', 'LNAME' => 'Doe'], 'abcdef1356'); // Subscribe to List ID abcdef1356 If you want to unsubscribe a user from a list, you can use the unsubscribe method.
      $mc->unsubscribe('john.doe@example.com'); // Unsubscribe john.doe@example.com from the default list $mc->unsubscribe('john.doe@example.com', 'abcdef1356'); // Unsubscribe john.doe@example.com from the list abcdef1356 If you want to permantly delete a user, you can call the delete method. Carefully, this step cannot be undone
      $mc->delete('john.doe@example.com'); // Permanently deletes john.doe@example.com from the default list $mc->delete('john.doe@example.com', 'abcdef1356'); // Permanently deletes john.doe@example.com from the list abcdef1356  
      Important Notes
      This module does not do any data validation. Use a sever-sided validation like Valitron Make sure that you have set up your fields in your Mailchimp list. You can do it at Settings > List fields and *|MERGE|* tags Example
      Example usage after a form is submitted on your page:
      // ... validation of form data $mc = $modules->get("SubscribeToMailchimp"); $email = $input->post->email; $subscriber = [ 'FNAME' => $input->post->firstname, 'LNAME' => $input->post->lastname, ]; $mc->subscribe($email, $subscriber);  
      Troubleshooting
      In case of trouble check your ProcessWire warning logs.
      I can't see the subscriber in the list
      If you have enabled double opt-in (it is enabled by default) you will not see the subscriber, until he confirmed the subscription in the email sent by Mailchimp
      I get an error in my ProccessWire warning logs
      Check if you have the right List ID and API Key. Check if you pass fields, that exist in your list. Check if you pass a valid email address. Go to Mailchimps Error Glossary for more Information
      How To Install
      Download the zip file at Github or clone directly the repo into your site/modules If you downloaded the zip file, extract it in your sites/modules directory. You might have to change the folders name to 'SubscribeToMailchimp'. Goto the modules admin page, click on refresh and install it  
      Changelog
      0.0.2
      Note: You can update safely from 0.0.1 without any changes in your code
      New Features
      Added 'Unsubscribe' method $mc->unsubscribe($email, $list = "") Added 'Delete' method $mc->delete($email, $list = "") Bug Fixes and compatibility changes
      Removed type declarations to be compatible with PHP 5.1+* (thanks to wbmnfktr) Other
      Changed the way, the base url for the api gets called *I have only tested it with PHP 7.x so far, so use on owners risk
    • By BitPoet
      As threatened in the Pub sub forum in the "What are you currently building?" thread, I've toyed around with Collabora CODE and built file editing capabilities for office documents (Libre-/OpenOffice formats and MS Office as well as a few really old file types) into a PW module.
      If you are running OwnCloud or NextCloud, you'll perhaps be familiar with the Collabora app for this purpose.
      LoolEditor
      Edit office files directly in ProcessWire
      Edit your docx, odt, pptx, xlsx or whatever office files you have stored in your file fields directly from ProcessWire's page editor. Upload, click the edit icon, make your changes and save. Can be enabled per field, even in template context.
      Currently supports opening and saving of office documents. Locking functionality is in development.
      See the README on GitHub for installation instructions. You should be reasonably experienced with configuring HTTPS and running docker images to get things set up quickly.
      Pull requests are welcome!
      Here is a short demonstration:

    • By Robin S
      An Images field allows you to:
      Rename images by clicking the filename in the edit panel or in list view. Replace images, keeping metadata and filename (when possible) by dropping a new image on the thumbnail in the edit panel. Introduced here. But neither of these things is possible in File fields, which prompted this module. The way that files are renamed or replaced in this module is not as slick as in the Images field but it gets the job done. The most time-consuming part was dealing with the UI differences of the core admin themes. @tpr, gives me even more respect for the work that must go into AdminOnSteroids.
      Most of the code to support the rename/replace features is already present in InputfieldFile - there is just no UI for it currently. So hopefully that means these features will be offered in the core soon and this module can become obsolete.
       
      Files Rename Replace
      Allows files to be renamed or replaced in Page Edit.

      Usage
      Install the Files Rename Replace module.
      If you want to limit the module to certain roles only, select the roles in the module config. If no roles are selected then any role may rename/replace files.
      In Page Edit, click "Rename/Replace" for a file...
      Rename
      Use the text input to edit the existing name (excluding file extension).
      Replace
      Use the "Replace with" select to choose a replacement file from the same field. On page save the file will be replaced with the file you selected. Metadata (description, tags) will be retained, and the filename also if the file extensions are the same.
      Tip: newly uploaded files will appear in the "Replace with" select after the page has been saved.
       
      https://github.com/Toutouwai/FilesRenameReplace
      http://modules.processwire.com/modules/files-rename-replace/
    • By d'Hinnisdaël
      So I decided to wade into module development and created a wrapper module around ImageOptim, a service that compresses and optimizes images in the cloud. ImageOptim currently handles JPG, PNG and GIF files and, depending on the settings you use, shaves off between 15% and 60% in filesize. Great for bandwidth and great for users, especially on mobile.
      This module handles the part of uploading images to ImageOptim via their official API, downloading the optimized version and storing it alongside the original image.
       

       
      Download & Info
      GitHub / Module directory / Readme / Usage
       
      Why ImageOptim?
      There are other image optimization services out there, some of them free, that have outstanding ProcessWire modules. A few things make ImageOptim the best tool for most of my customers: It's not free, i.e. it will probably be around for a while and offers support. However, it's cheaper than some of the bigger competitors like Cloudinary. And it does PNG compression better than any of the free services out there, especially those with alpha channels.
       
      Installation
      Install the module like any other ProcessWire module, by either copying the folder into your modules folder or installing it via the admin. See above for downloads links on GitHub and in the module directory.
       
      Requirements
      To be able to upload images to the service, allow_url_fopen must be set on the server. The module will abort installation if that's not the case.
      I have only tested the module on ProcessWire 3.x installations. I don't see why it shouldn't work in 2.x, if anyone wants to try it out and report back.
       
      ImageOptim account
      To compress images, you first need to sign up for an ImageOptim account. They offer free trials to try the service.
       
      Usage (manual optimization)
      Images can be optimized by calling the optimize() method on any image. You can pass an options array to set ImageOptim API parameters.
      $image->size(800,600)->optimize()->url $image->optimize(['quality' => 'low', 'dpr' => 2]) // Set quality to low and enable hi-dpi mode
      Automatic optimization
      The module also has an automatic mode that optimizes all image variations after resizing. This is the recommended way to use this module since it leaves the original image uncompressed, but optimizes all derivative images.
      $image->size(800,600)->url // nothing to do here; image is optimized automatically
      To change compression setting for single images, you can pass an options array along with the standard ImageResizer options. Passing false disables optimization.
      $image->size(800, 600, ['optimize' => 'medium']) $image->size(800, 600, ['optimize' => ['quality' => 'low', 'dpr' => 2]]) $image->size(800, 600, ['optimize' => false])
      For detailed usage instructions and all API parameters, see the usage instructions on GitHub.
       
      Filenames
      Optimized images will be suffixed, e.g. image.jpg becomes image.optim.jpg. You can configure the suffix in the module settings.
       
      Roadmap
      Asynchronous processing. Not really high on the list. Image variations need to be created anyway, so waiting a few seconds longer on first load is preferable to adding complexity to achieve async optimization. Optimize image variations created by other modules. CroppableImage comes to mind. I don't use any of these, so if somebody wants to help out and submit a pull request — all for it! Add a dedicated page in the setup menu with a dashboard and detailed statistics. ImageOptim's API is very barebones for now, so not sure if that's feasible or even necessary.
      Stability
      I've been using this module on production sites for some time now, without hiccups. If you do notice oddities, feel free to comment here or investigate and submit PRs.
    • By PWaddict
      Module for hiding pages for non-superusers.
      Download
      HidePages
      Requirements
      ProcessWire 3.x Changelog
      1.0.1 (31 March 2018)
      Module renamed to prevent confusion 1.0.0 (30 March 2018)
      Initial release