Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Support Magewire in the backend #139

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

michielgerritsen
Copy link

Last week during the pre-Meet Magento NL Hackathon, I hacked together a proof of concept on getting Magewire to work in the backend of Magento. This PR is the result of that. Next to that, this PR and repository are also required:

The RequireJS adjustments are made as the backend also needs RequireJS support, but the module has a dependency on customer data. It is not required to make it work in the backend, though. Next to that, the form key in the backend is being retrieved differently than in the frontend.

The solution lies mainly in moving configuration from etc/frontend/di.xml to etc/di.xml, and from etc/frontend/events.xml to etc/events.xml. Also, a controller is created in the adminhtml folder, but that extends upon the frontend controller without any changes.

A big question that popped up during the hackathon was what about security? Magewire relies on the form key, which by accident makes it a little bit secure, but the controller does not have any extra security built in. Also, another thing that should be thought about is ACLs.

I have the code for the backend in a separate repository. It is worth considering whether this is the right approach or whether it should be merged into the main repository.

@jissereitsma
Copy link

Awesome stuff @michielgerritsen . You mentioned the backend code lives in another repo. Do you mean an acl.xml file and backend controller? Because it is just that, it would be quite easy to add to this PR, right? I would say the controller simply needs to be a regular admin controller with ACL resource defined, which then correlates to an ACL resource to the acl.xml file? Or did you had something else in mind?

@michielgerritsen
Copy link
Author

@jissereitsma The backend code lives in this repository:
https://github.com/michielgerritsen/magewire-backend

It holds a few things:

  • Files to work properly with RequireJS in the backend. It is comparable to the code in the magewire-requirejs repo, with some backend specific changes.
  • It sets a different base URL in the Magewire ViewModel.
  • It adds a different controller that lives in the adminhtml folder. This only extends from the frontend controller and does not add any logic.

So it's not super much, but a bit more than a simple acl.xml file.

@jissereitsma
Copy link

I'm currently working on a module in the Magento backend, using Magewire. To load things properly via AJAX, the Livewire controller in the backend module really really needs to be extending upon the admin action, not implementing the interfaces: Those interfaces are meant for the frontend only (as of yet). I'll update things on my side and hope to add a PR to your PR soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants