First of all I am very happy to submit the first issue on this project. :-)

I have seen the DrupalCon Nashville 2018 Presentation "Webcomponents, Polymer and HAX: decoupling authoring for Drupal and beyond" and for me it seems that HAX is the ultimate tool to move forward with Drupal as a Backend.

Is there any plan to port it on 8.x.

Thanks.

Update on D8 HAX efforts

There's a functional HAX for Drupal 8 at https://github.com/mlsamuelson/hax. We're currently looking for testers to provide feedback and review.

Comments

TheodorosPloumis created an issue. See original summary.

btopro’s picture

Ha, nice!

There is a port currently in the works and much discussion on twitter currently about it and we're very interested in getting help towards the goal of having this in D8 (hell I'll port it to D5 if I could stand it up anywhere just to showcase the concept).

We are very interested in having this happen but I learn through reverse engineering so it's hard for me to pick up D8 without someone doing a bunch of initial work on it to have me then figure out the guts of the structure and improve upon it.

btopro’s picture

there is a boilerplate start to a port here -- https://github.com/onelittlebecca/drupal_hax8

mlsamuelson’s picture

I've spun off an upgrade effort using drupalmoduleupdater to get started. After conversing with @onelittlebecca I did it as a separate repo: https://github.com/mlsamuelson/hax

Currently, the admin settings UI works.

It's in a bit of a state while I sort out the best method/location for attaching header links in D8, and comment out the parts from the .module file that have moved to the DefaultController.php. I'm likely to commit a HaxModeController.php before long, to handle the HAX mode handling on nodes.

Collaborative effort would be welcomed, for anyone else interested in collaboration, etc.

gloriaswebtech’s picture

Hey @mlsamuelson, I am very interested in helping further this project. I have cloned a copy of your repo but am unsure of how I should go about contributing to it. I assume a merge request or fork but would like your input. I am new to contributing but know the basics of git/github and d8 theming + module development.

btopro’s picture

Let's use https://github.com/mlsamuelson/hax to base PRs off of just so we have a known location to be doing this from. I like PR workflow way more then direct d.o. contribution. Once we get things cleaned up and working off of that repo then we can commit it here. I don't have any experience w/ D8 modules but as project maintainer on HAX / the D7 work I'm always available to answer questions relative to where this should go / how it should operate.

Phase 1 is just make it do what the D7 module does. Phase 2 once we get there will be more of a wholistic "ok, what should the HAX module support" permissions, capabilities, etc and where it should go from there. Some of that back and forth may involve the hax-body series of tags being tweaked to support some CMS specific customizations (for example I could see a need to prevent tags on a per field level where as hax-body currently manages this sanitization internally relative to what tags it registered during boot + html primatives)

mlsamuelson’s picture

@btopro Sounds like a plan.

@Gtucker6 Pull requests work great. I'm happy to have the help!

My current challenge is determining the correct/best means of getting the

  // write content to screen, wrapped in tag to do all the work
  $content = '
  <cms-hax open-default end-point="' . base_path() . 'hax-node-save/' . $node->nid . '/' . drupal_get_token('hax') . '" body-offset-left="' . variable_get('hax_offset_left', 0) . '" app-store-connection=' . "'" . json_encode($appStoreConnection) . "'" . '>'
  . $components .
    check_markup($node->body['und'][0]['value'], $node->body['und'][0]['format'])
  .'</cms-hax>';
  return $content;

markup from _hax_node_form() in D7, around the body field.

So far I've found a number of ways to *not* do it. ;) Including the commented out \Drupal\hax\Controller\DefaultController::_hax_node_form() method. That route failed to return a Response object, so only the field and markup around it returned, with the rest of the page left out. I read somewhere that's by design.

Next I set up the \Drupal\hax\Controller\HaxModeController::hax_node_form() method, tied to the hax.node_form route. And I'm still exploring this option.

As well as the implementation of hook_ENTITY_TYPE_view(), hax_node_view() in the hax.module file, towards the same end. That function has the markup apply to the $build data structure cleanly, but I am yet to see it actually show up in the UI, apart from my dpm()s. Obviously I'm missing something.

mlsamuelson’s picture

Helpful resources for D8 Entity CRUD, and the render pipeline that have proven helpful, so far:
https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Entity%21...
https://www.drupal.org/docs/8/api/render-api/the-drupal-8-render-pipeline

@btopro, My current goal is just work out how to get HAX rendered in the UI, then, I'll want to pick your brain to make sure we maintain feature parity. Having minimal experience with HAX in D7, I'm definitely coming at this from the point of view of a reverse-engineer. :)

mlsamuelson’s picture

@btopro Thanks. That helped, as did https://www.drupal.org/forum/support/module-development-and-code-questio...

See my latest commit:
https://github.com/mlsamuelson/hax/commit/ace5074a433f2df36fabe5c4852c1b...

As in the comments there, need to figure out why this is only working with the code block acting on the $entity object and the other acting on the $build variable. Comment out one or the other, and it doesn't update the field.

Also, the cms-hax markup is being escaped...

mlsamuelson’s picture

So that's not working on an input format with Full HTML, but if I switch the input format on the edit page for the node to "Basic HTML" and I add <cms-hax open-default end-point body-offset-left app-store-connection> to the Basic HTML format's allowed tags, it's working.

Full HTML doesn't allow you to edit the tags unless you have checked "Limit allowed HTML tags and correct faulty HTML" - the ramifications of which, using with Full HTML format I haven't explored yet.

Possibly helpful: https://www.drupal.org/node/1829860
And https://medium.com/@djphenaproxima/how-to-bend-drupal-8-plugins-to-your-...

mlsamuelson’s picture

I should note that one of our the code blocks that adds the tag is now superflous and needs to be pulled out.

btopro’s picture

I believe correct faulty needs to be off. You'll have to have faith that HAX will ensure it's a legit tag (which it should). Security wise though Limit allowed HTML tags should work though we might want to make our own input filter that dynamically adds only known webcomponent tags / HAX provided autoloaded tags.

mlsamuelson’s picture

So, with what’s in the repo right now, that’ll deploys the HAX editor… but for both the hax mode tab AND the node view tab due to the use of the hook_ENTITY_TYPE_view()… and I could call to get the path or route so we only show on the HAX mode page… But there's caching with that hook and I'm hesitant to break the cache in this context.

I also tried again via the controller class HaxModeController, but I’ve not yet identified how to add the cms-hax tag to the body so it’ll render. Current work for that is not in the repo, and I suspect I'm going about it wrong with trying to use that.

Time has caught me for today. But it’s looking like maybe a Drupal 8 field formatter plugin is what's called for to get the component attachments and the cms-hax tag deployed in a targeted way:
https://drupal.stackexchange.com/questions/183393/which-is-the-preferred...

mlsamuelson’s picture

The kickback on a custom field formatter for HAX is going to be that it requires configuration in the UI, or if we attempt to deploy it programmatically, I could see us hitting the same dead ends we've already experienced... unless hook_entity_view_alter() could be used.

Really hoping to keep this zero config.

But maybe we could still do that with some programmatic combination of a HAX field formatter, HAX view mode. Directions to explore.

btopro’s picture

why does one need a hax field formatter again? Are you thinking of having any field able to be "haxed" in the context of a normal drupal form which has other settings applied to it? Also not sure why a HAX view mode would be needed if the element definitions are on the page; would possibly need a hax input filter to ensure that the tags coming across are valid as defined by the W3C spec and not Drupal directly (which might throw out thing-stuff tags for example but this is a guess)

mlsamuelson’s picture

@btopro Yeah, I'm looking askance at the field formatter option, too, but the top response on https://drupal.stackexchange.com/questions/183393/which-is-the-preferred... led me to it.

Essentially, the issue is, it's not real clear what the best way to alter a field before it renders from a module is in D8 in our situation. I have a feeling if I'd started from scratch, rather than trying to "make it work" with the DrupalModuleUpdater code, it would be clearer.

Another option could be to do it from a theme template for the field. Something like - https://drupal.stackexchange.com/questions/170032/overriding-field-html-...

@btopro Philosophically - targeting just the body field is the preference? Correct?

mlsamuelson’s picture

Progress:
HAX mode tab now functional, and caching is correctly applying, based on the route "hax.node_form" due to specifying the "route.name" #cache context and doing the work in hax_preprocess_field(). hax_page_attachments() to add the supporting links to the html_head.

Of note is that the XSS::filterAdmin() function prevents us from adding the wrapper to the body field via #prefix and #suffix, and I've not identified any means to alter the allowed tags in that class. See Xss.php in core/lib/Drupal/Component/Utility (namespace \Drupal\Component\Utility\Xss).

The fallback I have in place is to directly apply the tag to #text. The drawback there is it'll require the user to configure the text format to allow the cms-hax tag and its attributes, like so: <cms-hax open-default end-point body-offset-left app-store-connection>

Editing on the content with HAX now works. Doing a save results in a 405 "method not allowed." And I haven't looked into any of the code related to that yet. So that's the next task on my list.

mlsamuelson’s picture

Reading up on https://www.drupal.org/docs/8/core/modules/rest/javascript-and-drupal-8-... and https://www.drupal.org/docs/8/core/modules/rest/1-getting-started-rest-c... to determine if that's the way to go forward from here since the submission is coming from the front end - possibly using the built in node resource.

mlsamuelson’s picture

So, HAX saves node bodies now. :)

See commit: https://github.com/mlsamuelson/hax/commit/815e67698f3e3d2322f384ac1eb910...

The commit message:

Getting HAX saves to work. Drupal 8 REST for entities doesn't support PUT,
and that's hardcoded into cms-hax. And since we only need something simple
here, we just expose the route as a controller class, with PUT method
support. Note, updates to dependencies and README.md.

I feel like we're over the hump now.

Up next

  • Look into file save support
  • Error with app store in console
  • Get with @btopro to check on feature parity
  • Cleanup. Lots and lots of code cleanup
  • Whatever I've missed
btopro’s picture

This is excellent news! As for the PUT we can variableize the method if it would help. Nice thing about these components is they are really easy to extend as needed. Could you post a screen shot / paste of the JS error in question?

btopro’s picture

https://github.com/LRNWebComponents/cms-hax/blob/master/cms-hax.html#L47

Now if you pass a method="POST" you could do POST for example while the default is still PUT if undefined.

mlsamuelson’s picture

@btopro Cool deal! If we decide to fully integrate with the D8 REST system vs using a Controller endpoint, we'll probably need that. What we're doing now is more in line with the D7 functionality, so I'm going to stick with it for now, unless we hit any walls.

Another task for the TODO list:
- Ensuring we're leveraging proper security practices. Check into https://www.drupal.org/docs/8/api/text-editor-api/overview

On the JS error with the app store... I'm pretty sure that's due to upgrades needed to the code in that call. Will give that a look, and if it's still there after upgrading the code, will share the error.

mlsamuelson’s picture

StatusFileSize
new78.48 KB

Alright. I've sorted out the app store code updates, and have the path hax-app-store/{token} handling token validation and the response object correctly, as well as the hooks and alters.

The error is still popping up in the console. See screenshot.

Looks to be that hax-store.html is not hitting the endpoint successfully. I haven't tracked the issue back to its source yet.

mlsamuelson’s picture

Discovered the json_encode() around the app-store-connection wasn't the issue, after comparing with the D7 version's markup. There's more filtering in D8 getting in the way here.

mlsamuelson’s picture

Alright, whatever quirk of caching caused me to think we needed to enable "Limit Allowed Tags" to get Hax to work, is no longer a thing. I've updated the README.md to remove those steps, and the hax.routing.yml to remove dependencies it turns out we don't need, given the resolution on the PUT (which we can support via the Symfony routing backend). Much cleaner install, on par with the D7 version.

mlsamuelson’s picture

Aw, and having the "Limit allowed tags" unchecked on the text format resolves the issue with the App Store link, which I was seeing in the console (as per the screenshot shared earlier).

btopro’s picture

this makes me wonder just how aggressively applied those things are if they are impacting the tag being applied to the page itself. We'll probably want to make some kind of limit allowed tags variation that automatically adds any tag defined on the backend.

Sounds like your making great strides though :) Pull the latest 0.13.0 release of hax-body and update hax-body-behaviors. It has lots of enhancements to keyboard operations, selection of things in things and performance enhancements

mlsamuelson’s picture

I've done a lot of cleanup (https://github.com/mlsamuelson/hax/commit/23942f1840836862dd7494fe2da00e...), now that things have stabilized. The file save handling hasn't had any attention or testing, really, and I wanted to catch up with you, @btopro, to help me understand when that comes into play, and the philosophy for file handling in HAX.

At this point, short of the files bit, I think we could use some testers - install and try it out. @TheodorosPloumis and @Gtucker6 ? ;)

Clone from master: https://github.com/mlsamuelson/hax

mlsamuelson’s picture

In Core, for file create access checks \Drupal\file\FileAccessControlHandler :

  protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL) {
    // The file entity has no "create" permission because by default Drupal core
    // does not allow creating file entities independently. It allows you to
    // create file entities that are referenced from another entity
    // (e.g. an image for a article). A contributed module is free to alter
    // this to allow file entities to be created directly.
    return AccessResult::neutral();
  }

So, in light of that, since we only have the one route, and it already has _hax_file_access(), I've added the "Upload files via HAX editor" permission, and we check it there and again in _hax_file_save().

btopro’s picture

nice, thanks for detailing why that would be the case too.

We'll want to do a full on HAX permissions audit after it hits feature parity and people are noticing they want / need the ability to set what people have access to on the back end (which will have implications for the parts of the UI to show to different groups but that's fine).

mlsamuelson’s picture

With the commit https://github.com/mlsamuelson/hax/commit/8beb64689ef6b774df7cc59ebe1991..., we're now ready for some testing.

Issues to note:
1. HAX toolbar opens automatically on HAX Mode tab. Issue to be addressed in HAX itself?
2. Clicking "Cancel" button on HAX toolbar results in save occurring. Another one to be addressed in HAX itself?

mlsamuelson’s picture

Assigned: Unassigned » mlsamuelson
Category: Support request » Task
Status: Active » Needs review

Updating status.

btopro’s picture

1. That's due to a flag in the 2. https://github.com/LRNWebComponents/hax-body/issues/111 in place for the cancel issue, need to tweak hax a bit to support this and then clean it up in the integration tags of cms-hax app-editor-hax and wysiwyg-hax tags but totally doable.

mlsamuelson’s picture

Already had some community feedback in the GitHub repo. Have resolved an issue with the README.md having an unnecessary reference to restui, and have merged a code formatting fix that includes renaming the controller and many of its methods away from the D7 names for them, putting them on par with D8 standards for such things.

mmenavas’s picture

I was able to install HAX in a D8 site (standard installation profile and Bartik theme). Below are the issues I encountered:

  • When running bower install, I was prompted to pick a suitable version for a package. This happened at least 5 times. I pretty much made an educated guess by picking a version that was required by hax, hax-body, or hax-cms. This can be very confusing though.
  • I have to have some content on the body field and set the text format to 'Full HTML'. Otherwise, the HAX editor won't load on the 'HAX mode' tab.
  • After inserting a YouTube video on 'HAX mode', the video loads there but not when I go to the 'View' tab. Unchecking 'Limit allowed HTML tags' and 'correct faulty HTML' on the 'Full HTML' text format settings doesn't fix this issue.
  • Clicking on 'Hax Mode' generates a few javascript errors related to CKEditor.

Thanks for porting this module to D8! I'm excited to see everything this module can do once it's finalized.

btopro’s picture

StatusFileSize
new1.13 KB

@mmenavas thanks for the feedback; dependency tree w/ builds is def annoying and confusing right now. I'm attaching an updated bower.json that will automatically resolve these issues. As we get out of active development and into implementation phase we can generate a static single asset (for the majority of it) which then people could point to and it would be a single download instead of mass dependency tree.

Perhaps the build clean up will resolve the other things you mention but we'll see

mlsamuelson’s picture

mlsamuelson’s picture

Issue summary: View changes

From @mmenavas in #36:

I have to have some content on the body field and set the text format to 'Full HTML'. Otherwise, the HAX editor won't load on the 'HAX mode' tab.

This is by design, mimics D7 version, and is touched on in the README.md: "NOTE on Text Formats: HAX is designed to work with nodes with bodies in the default Full HTML format where "Limit allowed HTML tags and correct faulty HTML" is unchecked, or with formats with similarly permissive settings."

Perhaps the workflow, expectations or "signage" could be improved. A candidate for a follow up ticket, I'm thinking.

After inserting a YouTube video on 'HAX mode', the video loads there but not when I go to the 'View' tab. Unchecking 'Limit allowed HTML tags' and 'correct faulty HTML' on the 'Full HTML' text format settings doesn't fix this issue.

I experienced the same thing. Same with the PDF viewer. I was thinking it must be something with filtering, but the markup was there. Turns out it was the hax_is_current_route_supported() call in hax_page_attachments(). I've commented that out and slated it for removal. Looks like that was a bit of code that came over with a copy/paste from hax_preprocess_field() and one that wasn't needed in this instance, as we don't want to constrain the web component imports on the view tab - we need it in order to display the web components.

FIXED and committed: https://github.com/mlsamuelson/hax/commit/6dc57144ac9946060ee857f1088a5a...

Clicking on 'Hax Mode' generates a few javascript errors related to CKEditor.

I'm seeing those too - errors related to JS files in core/assets/vendor/ckeditor. Haven't investigated the cause yet.

GET http://localhost/hax8.6/core/assets/vendor/ckeditor/config.js?t=p93isy 404 (Not Found)

Refused to execute script from 'http://localhost/hax8.6/core/assets/vendor/ckeditor/config.js?t=p93isy' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.

GET http://localhost/hax8.6/core/assets/vendor/ckeditor/styles.js?t=p93isy 404 (Not Found)

Refused to execute script from 'http://localhost/hax8.6/core/assets/vendor/ckeditor/styles.js?t=p93isy' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.

Uncaught Error: [CKEDITOR.resourceManager.load] Resource name "default" was not found at "http://localhost/hax8.6/core/assets/vendor/ckeditor/styles.js?t=p93isy"

Thanks, for the great test findings @mmenavas !

mlsamuelson’s picture

@btopro, thanks for https://github.com/LRNWebComponents/hax-body/issues/111. Re-upping through bower install, the Cancel button no longer triggers a save. But the Save button continues to save. So that's fixed.

Still seeing the HAX toolbar auto-open on the Hax Mode tab, but perhaps that's by design - and now that Cancel doesn't trigger a save, it's not really an issue.

NOTE (maybe something to spin off into a separate issue):
Allowed tags filtering on the frontend:
https://github.com/LRNWebComponents/hax-body/issues/70#issuecomment-3914...

@btopro, Any thoughts on next steps? More testers, any fixes, then a release?

btopro’s picture

auto opening is by design and is also a boolean value that can be changed (could wire it to a Drupal setting if you wanted to I guess). You can see what triggers that here -- https://github.com/mlsamuelson/hax/blob/master/hax.module#L58-L61

"open-default"

On the tag filtering on the front end, you could make an array of tags that Drupal will allow, serialize it and then in the same code block as above inject something like ... allowed-tags="' . json_encode(array('p', 'div', 'li', 'ul')) . '" ... where that array of values would be driven (somehow) based on a Drupal input filter.

Is the D8 version saving to the backend? If it is saving and recalling the app store spec to allow for "finding" assets and generally working I'd say that this sounds like it's worth both publishing to d.o. as well as cutting like a 1.0.0-alpha1 release. Thoughts?

mlsamuelson’s picture

Yeah, we should be fully functional. I'd be happy to see this get an alpha release. Let me know what I can do to help make that happen. :)

btopro’s picture

there is now a branch established for 8.x-2.x. Please commit your code to this branch so we an keep all 3 versions on their respective 2.x branch. I've also made you a maintainer on d.o. so you'll now be able to checkout and push to d.o.

  • mlsamuelson committed 869f52e on 8.x-2.x
    ISSUE #2962055 by mlsamuelson: Initial commit of HAX upgraded for D8,...
mlsamuelson’s picture

Alright. I've cut a 8.x-2.0-alpha1 release, and it's downloadable from the project page.

Are we good to close this ticket?

btopro’s picture

Version: 7.x-2.x-dev » 8.x-2.x-dev
Status: Needs review » Fixed

moving to 8.x and closing this. All new issues with the actual release now that we have one should take place via d.o. still but be in new issues that are opened related to the 8.x-2.x branch. Incredible work mlsamuelson!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.