grav-plugin-flex-objects icon indicating copy to clipboard operation
grav-plugin-flex-objects copied to clipboard

Custom field not showing up

Open stephan-strate opened this issue 4 years ago • 6 comments

We have added a custom form field in our theme, its working in regular page blueprints. Adding it to a custom flex object form, it does not even show up.

Maybe this has something to do with flex object being initialized earlier? I could not add flex object definitions in our theme either, needed to add it in a plugin.

stephan-strate avatar Dec 10 '20 13:12 stephan-strate

Can you give an example for me to work with? Saves some time if I know exactly what you're doing. Thanks.

mahagr avatar Dec 11 '20 08:12 mahagr

Sure! We have got a standard theme (generated using the devtools). Created custom form field like this: image

documentation.html.twig

{% extends 'forms/field.html.twig' %}

{% block contents %}
    some output
{% endblock %}

Added template path in my-theme.php like this:

'onTwigTemplatePaths'   => ['onTwigTemplatePaths', 0],
public function onTwigTemplatePaths()
{
    $this->grav['twig']->twig_paths[] = __DIR__ . '/templates';
}

flex-object form field:

title: Contacts
description: Contacts
type: flex-objects

extends@:
  type: contacts
  context: blueprints://flex-objects

form:
  validation: loose

  fields:

    documentation:
      type: documentation

stephan-strate avatar Dec 11 '20 08:12 stephan-strate

Yeah, because frontend templates are not being loaded in admin -- they break admin if you do so.

Move fields into admin/templates and use onAdminTwigTemplatePaths event:

    public function onAdminTwigTemplatePaths(Event $event)
    {
        $paths = $event['paths'];
        $paths[] = __DIR__ . '/admin/templates';
    }

mahagr avatar Dec 23 '20 14:12 mahagr

Got it! Is there a similar strategy to add the flex object blueprints in themes? I got it working in user/blueprints and in the plugins blueprints folder, but not in theme right now.

stephan-strate avatar Dec 24 '20 22:12 stephan-strate

Got it! Is there a similar strategy to add the flex object blueprints in themes? I got it working in user/blueprints and in the plugins blueprints folder, but not in theme right now.

Hello, I had the same question and it now seems fixed in next 1.7.8 release: https://github.com/getgrav/grav/issues/3255 I'll do tests as soon as 1.7.8 gets releases.

Hope this helps!

phmg701 avatar Mar 11 '21 14:03 phmg701

Yup, the missing blueprints issue has also been fixed, but you need to move the files around (to follow the same blueprints folder structure as in plugins) to enable it.

mahagr avatar Mar 12 '21 11:03 mahagr