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

Dropdown custom modal in admin not working when in edit page view. #181

Open
n-vs-m opened this issue Nov 28, 2023 · 3 comments
Open

Dropdown custom modal in admin not working when in edit page view. #181

n-vs-m opened this issue Nov 28, 2023 · 3 comments

Comments

@n-vs-m
Copy link

n-vs-m commented Nov 28, 2023

See this discussion: getgrav/grav-plugin-admin#2259

A custom modal button made like explained in the doc is not working when you are in edit page view. The button is displayed, but when you click on it a JS error prints.

admin.min.js?59588e338c:683 Uncaught TypeError: Cannot read properties of undefined (reading 'open')
    at HTMLAnchorElement.<anonymous> (admin.min.js?59588e338c:683:56)
    at HTMLDocument.dispatch (jquery-2.x.min.js?59588e338c:3:7537)
    at r.handle (jquery-2.x.min.js?59588e338c:3:5620)

It seems the file https://github.com/trilbymedia/grav-plugin-flex-objects/blob/develop/admin/templates/flex-objects/types/pages/edit.html.twig is missing some definition.

Adding a few lines before the closing if at the line 212

<div class="remodal" data-remodal-id="modal-page-copy" data-remodal-options="hashTracking: false, closeOnOutsideClick: false">
{% include 'partials/blueprints-copy.html.twig' with { blueprints: admin.blueprints('admin/pages/copy'), data: data({ title: object.title ~ ' (Copy)', folder: object.slug ~ '-copy' }), form_id: 'copy' } %}
</div>
{% endif %}
{# TODO: regular pages support extra modals from admin config #}

seems to work, here are the lines:

       {% for key, add_modal in config.plugins.admin.add_modals %}
          <div class="remodal {{ add_modal.modal_classes|defined('') }}" data-remodal-id="modal-add_modal-{{ key }}" data-remodal-options="hashTracking: false, closeOnOutsideClick: false">
            {% include add_modal.template|defined('partials/blueprints-new.html.twig') with {
              form: null,
              blueprints: admin.blueprints(add_modal.blueprint),
              data: null,
              form_id: 'add-modal'
            }|merge(add_modal.with|defined({})) %}
          </div>
        {% endfor %}

Sorry i can't make a proper PR as git is not configured on my grav.

@hughbris
Copy link

This worked a treat when I hacked the plugin, so thank you! I was trying to add it to my site repo as an override so I don't have to use a hacked plugin, but couldn't seem to find the right location. It works to override form plugin templates. I have tried:

  • user/admin/themes/grav/templates/flex-objects/types/pages/ and
  • user/admin/templates/flex-objects/types/pages/

but neither seemed to work. Any idea where I might put this modified template to get it working?

@n-vs-m
Copy link
Author

n-vs-m commented Nov 30, 2023

I didn't find any suited user directory...

@Xoriander
Copy link

Xoriander commented Feb 28, 2024

It is possible to override the edit.html.twig from a theme folder:

  • user/themes/{path-to-your-theme}/admin/templates/flex-objects/types/pages/
    or
  • user/data/{path-to-your-theme}/admin/templates/flex-objects/types/pages/

Thank you for the lines to make the custom modal working on edit page view.

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

No branches or pull requests

3 participants