Jump to content

HannaCodeDialog


Robin S

Recommended Posts

1 hour ago, Robin S said:

Or here's a hacky solution that involves adding an extra "path" attribute to your Hanna tag..

Brilliant - thanks. I was thinking along those lines, but obviously not hacky enough 😁

  • Like 1
Link to comment
Share on other sites

12 hours ago, Robin S said:

Or here's a hacky solution that involves adding an extra "path" attribute to your Hanna tag...

Just to report that this works well. I also added some css to hide the path attribute in the dialog box, so as not to confuse the user or risk inadvertant amendment.

Super module , super support!

Link to comment
Share on other sites

Following the above discussion, I decided that it made more sense to display the title rather than the path (since it is only for display purposes). I also wanted a solution for attribute types pagelistselectmultiple, not just pagelistselect. In case it is useful to anyone else, my suggested js is:

$(document).ready(function() {
    /* Author: Mark Evens, based on an original script by Robin Sallis */
    /* This version displays the title text rather than the path name */
    /* It also works for pagelistselectmultiple as well as pagelistselect */

    /* Hide the text field  */
    /* id_title is the name of a text attribute in the hanna code*/
    /* change id_title throughout the code below to match your attribute name */
    $('#wrap_id_title').addClass('hide-field');

    // Must use mousedown instead of click event due to frustrating event propagation issues across PW core
    // https://github.com/processwire/processwire-issues/issues/1028
    // .PageListActionSelect is the button 'Select' with appears when a page is clicked (no normally visible - loaded by js)
    $(document).on('mousedown', '.PageListActionSelect a', function (event) {
        var id_title;
        // Adapt unselect label to suit your language
        if ($(this).text() === 'Unselect') {
            id_title = '';
        } else {
            id_title = ($(this).closest('.PageListItem').children('.PageListPage').text()); // replace .text() by .attr('title') for path name
        }
        $('#id_title').val(id_title);
    });

    // For pagelistselectmultiple, get all the selected pages when the selection is updated
    // This returns the contents of the label displayed in the pagelist item. This can be set in your HannaCodeDialog::buildForm hook
    // The default is the page title. For the path name, set $f->labelFieldName = 'path'; in your hook
    $(document).on('change', '.InputfieldPageListSelectMultiple', function(event) {
        var id_title = [];
        $(this).find('.InputfieldContent ol li:not(.itemTemplate)').each(function(){
            id_title.push($(this).children('span.itemLabel').text())
        })
        $('#id_title').val(id_title);
    });

});

To hide the id_title attribute in the dialog, you need to add the following css:

#hanna-form .hide-field {
  display: none !important;
}

 

  • Like 3
Link to comment
Share on other sites

@Robin S - I have been using this module since it was released and always thought it was a necessary tool for inserting Hanna codes, but I just starting using some of its other features like: linked_page__pagelistselect

which makes it an entirely new beast - amazing.

Thanks!

  • Like 4
Link to comment
Share on other sites

@Robin S - just discovered that if you have this attached to a field that is editable under a user's profile page, it breaks the field with a JS error because it can't load this component.

No rush for a fix for my needs, but someone else might come across it.

  • Like 1
Link to comment
Share on other sites

Thanks for the report @adrian.

The newly released v0.3.6 adds support for ProcessProfile and ProcessUser, and also adds a config field to show the Tracy debug bar in the dialog which can be helpful for debugging if you are building the dialog form with a hook.

  • Like 4
Link to comment
Share on other sites

@Robin S - I am trying to offer selection of an uploaded file and not sure if I am taking the most efficient approach, but either way, it's not quite working. I am using https://processwire.com/modules/fieldtype-select-file/ to give me a InputfieldSelectFile

$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 === 'audio') {

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

        /* @var InputfieldSelect $f */
        $f = $modules->InputfieldSelectFile;
        $f->name = 'selected_file';
        $f->id = 'selected_file';
        $f->label = 'Select File';
        $f->folderPath = 'assets/files/'.$edited_page->id.'/';
        $form->add($f);

    }

});

image.png.11df4fb41967af68a57ac2a557cd2b89.png

image.png.336021b43c2e6f894a7aa14cc420ce7f.png

All looks good so far, but then I end up with:

image.png.e54b3d00af90a7daf82b7ec16bad69ab.png

Any ideas what I might be doing wrong, or if there is a better way?

FYI, I had to change the root path in that File Select module to start at /site/ instead of /site/templates/

Thanks for any thoughts!

 

Link to comment
Share on other sites

4 minutes ago, adrian said:

I am using https://processwire.com/modules/fieldtype-select-file/ to give me a InputfieldSelectFile

If you're using non-core inputfields beyond those described in the module readme it will be a case of "your mileage may vary" and I can't really offer support for those kinds of cases.

I suggest just using a normal InputfieldSelect and setting the options from files in Files field(s) on the page, or via $files->find()/DirectoryIterator/glob.

  • Like 1
Link to comment
Share on other sites

7 minutes ago, Robin S said:

I suggest just using a normal InputfieldSelect and setting the options from files in Files field(s) on the page

Of course - that works perfectly, thank you!

  • Like 1
Link to comment
Share on other sites

  • 4 weeks later...

Good day and once again thanks for the great module!

Is it possible to use ckeditor as an inputfield for text? I am trying to create a readmore hannacode and need to provide a rich text input for the content to be only partly shown.

Link to comment
Share on other sites

9 hours ago, Ivan Gretsky said:

Is it possible to use ckeditor as an inputfield for text?

No, CKEditor isn't a supported inputfield. I expect it would create rendering issues in the tag if it contains HTML, and if you are putting anything more than a short piece of text in your "read more" it would result in a huge, cumbersome tag widget.

Instead I think you should wrap the "read more" text in "open" and "close" Hanna tags.

[[rm-open]]
<p>Your text here.</p>
[[rm-close]]

Then replace the [[rm-open]] with a "Read more..." button and a div open tag, and the [[rm-close]] with a div close tag. Use JS to toggle the visibility of the div when the button is clicked.

You could also look at TextformatterPagination and TextformatterAccordion for inspiration but I think the above method would be the simplest.

  • Like 1
Link to comment
Share on other sites

  • 3 weeks later...

@Robin S - Ryan's update to the HannaCode module yesterday has broken this. Looks like it's probably just because he namespaced it, so should be an easy fix.

image.png.ed85b64ee977df76253cc62bf819aa91.png

PS - @teppo - I wonder if your HannaCodeHelper module might suffer the same fate?

  • Like 2
  • Thanks 1
Link to comment
Share on other sites

On 4/8/2021 at 3:18 AM, adrian said:

Ryan's update to the HannaCode module yesterday has broken this. Looks like it's probably just because he namespaced it, so should be an easy fix.

Thanks. The v0.3.0 update to HannaCode is actually a major refactoring of the module so there were a few things in HannaCodeDialog that needed updating for compatibility. The new v0.4.0 of HannaCodeDialog should be compatible with HannaCode v0.3.0 and it requires HannaCode >= v0.3.0.

  • Like 6
  • Thanks 2
Link to comment
Share on other sites

  • 2 months later...

@Robin S

I'm having some issues with getting this to work – using the latest PW, and Hanna Code, and Hanna Code Dialog; The field with the hanna codes (body) isn't wrapping the codes so they just look like text and don't get identified as widgets. Not sure what i'm doing wrong; Tried uninstalling everything and re-install, but since the upgrades, no widgets; The HCD was working fine before I upgraded it...

thanks for any insights you might have - looking forward to using this on a particular project..

Link to comment
Share on other sites

55 minutes ago, Macrura said:

The field with the hanna codes (body) isn't wrapping the codes so they just look like text and don't get identified as widgets.

That sounds like a JavaScript issue - have a look for errors in the browser console. I just checked with the latest PW/HannaCode/HannaCodeDialog and it all seems to be working here.

  • Like 1
Link to comment
Share on other sites

Thanks!! - i just did another test and figured out the problem – tt only recognizes the shortcodes if you have the Hanna Code textformatter applied to the field.

I'm not actually using Hanna Code, i'm processing the shortcodes with my own textformatter, but using your module to enable editing of my custom shortcodes...

In any case, you're right and it completely works now; I have the Hanna Code Textformatter after my textformatter so it won't do anything (the codes will all be processed by the time it hits that one)..

Link to comment
Share on other sites

@Macrura - thanks to @Robin S in another post: https://processwire.com/talk/topic/15902-hannacodedialog/?do=findComment&comment=208498

// add hanna code dialog to fields even though the Hanna code text formatter isn't applied
// https://processwire.com/talk/topic/15902-hannacodedialog/?do=findComment&comment=208498
$this->wire()->addHookAfter('InputfieldCKEditor::renderReadyHook', function (HookEvent $event) {
    $inputfield = $event->object;
    $field = $inputfield->hasField;
    // For your field name(s)...
    if(!$field || $field->name !== 'XXXX') return;
    $config_name = "InputfieldCKEditor_{$field->name}";
    $config_name_matrix = "InputfieldCKEditor_{$field->name}_matrix";
    $config = $this->wire('config');
    $js_config = $config->js();
    foreach($js_config as $key => $value) {
        if($key === $config_name || strpos($key, $config_name_matrix) === 0) {
            $js_config[$key]['extraPlugins'] .= ',hannadropdown,hannadialog';
            $config->js($key, $js_config[$key]);
        }
    }
});

 

  • Like 2
Link to comment
Share on other sites

Couple of questions and issues...

(1)

On 2/11/2021 at 5:35 PM, Robin S said:
		// Add JS file to Hanna Code Dialog form
		$js_file = $config->paths->templates . 'hannas/select_page.js';
		if(is_file($js_file)) {
			$js_url = $config->urls->templates . 'hannas/select_page.js?v=' . filemtime($js_file);
			$form->appendMarkup = "<script src='$js_url'></script>";
		}

For some reason I can't get this to work at all; not sure why but my hook is in ready.php, and the markup is not appended to the form. I put my js into ACF ProcessPageEdit.js and that works, but it would be interesting to know why the code above didn't work, in case i wanted to keep the js file along with my other hanna code stuff.

(2) I enabled Tracy in the form (module config), but not getting any tracy...not loading. Wondering if there is any way to troubleshoot that.

(3) The CK editor widget things are great, makes it much easier for editors to see where a code is, and of course double click it to edit parameters.
But one thing that is tricky is getting the cursor in front of a widget, if it is the first thing in the editor. For me no problem of course i can just switch to code mode and put in some placeholder in front of it; but for the average user, i do wonder if there is any solution to this...

thanks!

 

 

Link to comment
Share on other sites

5 hours ago, Macrura said:

the markup is not appended to the form

Double-check that the path to your JS file is correct, because that conditional will only append the script markup if is_file() is true. With some debugging (see item 2) hopefully you can get it working. I just tested here again and it works for me.

 

5 hours ago, Macrura said:

(2) I enabled Tracy in the form (module config), but not getting any tracy

The label of that config setting is perhaps not perfect - I'll update it. The setting doesn't actually ensure that Tracy is displayed, rather it only disables the default CSS in the module that would otherwise hide the Tracy debug bar.

<?php if(!$hcd->show_tracy): ?>
	#tracy-debug { display:none !important; }
<?php endif; ?>

So you first need to have Tracy set to display the debug bar in the PW admin generally and then if you have that HCD setting checked it won't be hidden in the dialog.

 

5 hours ago, Macrura said:

But one thing that is tricky is getting the cursor in front of a widget

There's not much I can do about that because it's just how the CKEditor Widget plugin works. In such a situation I tend to use the arrow keys to move the cursor to the start of the field, or type the text underneath and then drag the widget to its new position.

hcd.gif.8cc40b7f3866f2316e30199bd67d3352.gif

  • Like 1
Link to comment
Share on other sites

Many thanks for your post and help! All has been revealed, and some facepalm moments...

(1) had to change $config to wire('config') (🤦‍♂️)
(2) had to set Tracy config to show in dialog  (🤦‍♂️)
(3) Yep, i'll just tell people up front if they need to put something in front of it, they need to move the widget..

  • 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
  • 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...