• Resolved Rookie

    (@alriksson)


    Is it possible to change the predefined paths if would like to load if from another folder?

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author Konrad Chmielewski

    (@hwk-fr)

    Hello,

    Thanks for the feedback! The Dynamic Block Types module will look for Style/JS/Template files in the following folders:

    /home/domain.com/wp-content/themes/child-theme/[input]
    /home/domain.com/wp-content/themes/parent-theme/[input]
    [input]
    /home/domain.com/[input]
    /home/domain.com/wp-content/[input]
    

    Where [input] is the setting entered in the Style/JS/Template settings fields. If you want to load files from a plugin folder, simply enter the path from the /wp-content/ folder, as it will match the rule: /home/domain.com/wp-content/[input].

    See screenshot: https://i.imgur.com/m4D6PS1.png

    If you want to change the displayed input prepend, you can use the following filters:

    filter('acfe/block_type/prepend/template', $prepend, $name);
    filter('acfe/block_type/prepend/template/name=my_template', $prepend, $name);
    
    filter('acfe/block_type/prepend/style', $prepend, $name);
    filter('acfe/block_type/prepend/style/name=my_template', $prepend, $name);
    
    filter('acfe/block_type/prepend/script', $prepend, $name);
    filter('acfe/block_type/prepend/script/name=my_template', $prepend, $name);
    

    See screenshot: https://i.imgur.com/RYPQNsY.png
    Usage example:

    add_filter('acfe/block_type/prepend/style', 'my_acf_block_type_setting_prepend', 10, 2);
    function my_acf_block_type_setting_prepend($prepend, $name){
        
        return '/my-path/';
        
    }
    

    Please note that those filters will only change the input prepend for DISPLAY, it won’t actually change where the system will look for the files, as it will keep to look for the folders at the beginning of the answer.

    Hope it helps!

    Regards.

    Thread Starter Rookie

    (@alriksson)

    @hwk-fr Many thanks for the answers!

    Have a few questions.

    Is there an option to deside it the custom field editor should be inline or in the sidebar?

    Also seems to miss support for the latest dashicons and would like to see an option to use cusotm svg icon form the media library.

    • This reply was modified 5 years, 8 months ago by Rookie.
    • This reply was modified 5 years, 8 months ago by Rookie.
    • This reply was modified 5 years, 8 months ago by Rookie.
    • This reply was modified 5 years, 8 months ago by Rookie.
    Plugin Author Konrad Chmielewski

    (@hwk-fr)

    Hello,

    What do you mean by “the custom field editor should be inline or in sidebar”? If you’re talking about the preview mode, the setting is called “Mode” and you can choose between preview / auto / edit. See documentation

    The “icon” setting follow the specs from the ACF documentation, you can set foreground/background colors, dashicons icon or svg path. See documentation.

    The ACF Block Type allow SVG as icon in the following format: <svg viewBox="0 0 24 24" ...>. The WordPress media library doesn’t allow SVG upload out of the box, due to possible security issues. If you enable SVG in the media library using a plugin, the output format won’t follow the ACF block type specifications, as it simply return the file path, ie: /wp-content/uploads/icon.svg. I’ll investigate it, see if that’s possible to make it compatible, but I can’t garantee it.

    Regards.

    Thread Starter Rookie

    (@alriksson)

    What do you mean by “the custom field editor should be inline or in sidebar”? If you’re talking about the preview mode, the setting is called “Mode” and you can choose between preview / auto / edit. See documentation

    I refer to block previews which is available in ACF documentation:
    https://www.advancedcustomfields.com/resources/acf_register_block_type/
    https://raw.githubusercontent.com/AdvancedCustomFields/docs/master/assets/acf-blocks-example-setting.png

    'is_preview' => true

    auto: Preview is shown by default but changes to edit form when block is selected. preview: Preview is always shown. Edit form appears in sidebar when block is selected. edit: Edit form is always shown.

    Yeah this is great but I prefer edit form inline, but as. saying above appears in sidebar. Would maybe be nice with options to chose? Having preview but chose edit form inline or sidebar.

    The ACF Block Type allow SVG as icon in the following format: <svg viewBox=”0 0 24 24″ …>. The WordPress media library doesn’t allow SVG upload out of the box, due to possible security issues. If you enable SVG in the media library using a plugin, the output format won’t follow the ACF block type specifications, as it simply return the file path, ie: /wp-content/uploads/icon.svg. I’ll investigate it, see if that’s possible to make it compatible, but I can’t garantee it.

    Okay so I can insert inline svg in the icon field? Didn’t try but as it said specify dashicon I though it wouldn’t render it andd detect it is an icon and not a src for dash icon.

    Using inline svg is completely fine just didn’t know you supproted it already. Thanks.

    My last thing is that I would prefer to handle the style and js with version control from the UI. Right now it picks the wp version to the ?query. I would like to better control it and add my own verison as I could do with wp_enqueue_style and scripts. Possible to add?

    • This reply was modified 5 years, 8 months ago by Rookie.
    Plugin Author Konrad Chmielewski

    (@hwk-fr)

    Hello,

    is_preview => true

    This setting cannot be set within the ACF Extended UI, since the attributes must be set manually for each block types, and depending the fields that are in the block. Code example:

    'example'           => array(
        'attributes' => array(
            'mode' => 'preview',
            'data' => array(
                'testimonial'   => "Blocks are...",
                'author'        => "Jane Smith",
                'role'          => "Person",
                'is_preview'    => true
            )
        )
    )
    

    If you want to use this advanced setting, and still keep your block type registered in the ACF Extended UI, you’ll have to use the acf/register_block_type_args hook. See documentation: https://www.advancedcustomfields.com/resources/acf-register_block_type_args/

    Yeah this is great but I prefer edit form inline, but as. saying above appears in sidebar. Would maybe be nice with options to chose? Having preview but chose edit form inline or sidebar.

    ACF Extended: Dynamic Forms follows ACF specifications and execute the native ACF acf_register_block_type() function behind the scene. If ACF doesn’t allow this setting, then you won’t be able to do it from the UI. Please refer to the ACF documentation for a detailed description of Block Types settings.

    My last thing is that I would prefer to handle the style and js with version control from the UI. Right now it picks the wp version to the ?query. I would like to better control it and add my own verison as I could do with wp_enqueue_style and scripts. Possible to add?

    This is due to how WordPress manage enqueued files. ACF Extended does not enqueue Block Types CSS/JS. As explained earlier, ACF Extended execute acf_register_block_type(), so it’s ACF which enqueue those files for each Block Types.

    If you want to remove/change those version in URLs, you’ll have to setup/configure a cache plugin or use hooks. There are some topics on stackoverflow about that (example here & here).

    Hope it helps!

    Regards.

    Thread Starter Rookie

    (@alriksson)

    This setting cannot be set within the ACF Extended UI, since the attributes must be set manually for each block types, and depending the fields that are in the block. Code example:

    ‘example’ => array(
    ‘attributes’ => array(
    ‘mode’ => ‘preview’,
    ‘data’ => array(
    ‘testimonial’ => “Blocks are…”,
    ‘author’ => “Jane Smith”,
    ‘role’ => “Person”,
    ‘is_preview’ => true
    )
    )
    )
    If you want to use this advanced setting, and still keep your block type registered in the ACF Extended UI, you’ll have to use the acf/register_block_type_args hook. See documentation: https://www.advancedcustomfields.com/resources/acf-register_block_type_args/

    Okay wouldn’t this be possible to setup in ACFE UI? Not following why this can’t be setup in the dynamic block in ACFE?

    ACF Extended: Dynamic Forms follows ACF specifications and execute the native ACF acf_register_block_type() function behind the scene. If ACF doesn’t allow this setting, then you won’t be able to do it from the UI. Please refer to the ACF documentation for a detailed description of Block Types settings.

    Ok noted, seems like sidebar is default and both seems to be settings in ACF PRO.

    This is due to how WordPress manage enqueued files. ACF Extended does not enqueue Block Types CSS/JS. As explained earlier, ACF Extended execute acf_register_block_type(), so it’s ACF which enqueue those files for each Block Types.

    If you want to remove/change those version in URLs, you’ll have to setup/configure a cache plugin or use hooks. There are some topics on stackoverflow about that (example here & here).

    ACF just enque it nativly in wordpress. So the same you add it in the dynamic blocks right now you can specify the version there as well? So in the UI we can specify the version 1.0 or 1.2 etc. I use cache plugin which grabs them but it’s not always ideal as the files are already once written manually optimized and not including unused css.

    wp_enqueue_style( 'style', get_template_directory_uri().'/style.css', array(), '1.0');

    Plugin Author Konrad Chmielewski

    (@hwk-fr)

    Hello,

    Okay wouldn’t this be possible to setup in ACFE UI? Not following why this can’t be setup in the dynamic block in ACFE?

    You should test this setting with a real life case, you’ll see that the arguments names are dynamic and based of the fields inside the field group attached to the block type.

    Example:

    'data' => array(
        'my_field'   => "Blocks are...",
        'my_text'    => "Jane Smith",
        'my_textarea'=> "Person"
    )
    

    This would require a massive work on UI to allow users to define default values for any possible field inside the preview, without the garantee to be able to fulfill everyone needs. The UI could use Repeater/Flexible Content, but the experience wouldn’t be perfect, since it won’t work with sub fields (array in side array), as Flexible Content can’t have inifite virtual childs flexible content.

    ACF just enque it nativly in wordpress. So the same you add it in the dynamic blocks right now you can specify the version there as well? So in the UI we can specify the version 1.0 or 1.2 etc. I use cache plugin which grabs them but it’s not always ideal as the files are already once written manually optimized and not including unused css.

    As explained earlier, ACF Extended uses the native ACF Block Type acf_register_block_type() behind the scene (the UI is simply a way to set arguments passed to this function). Rewriting the whole acf_register_block_type() function just to change the version of the files enqueued by ACF doesn’t make sense. Additionally, managing enqueued files & versions of WordPress is out of the scope of ACF Extended. If you want to change that behavior you’ll have to rely on WordPress hooks.

    Hope it helps!

    Regards.

    Thread Starter Rookie

    (@alriksson)

    Right now will all this I think it’s easier to use the native way than involving ACFE in the blocks. Even if the idea is great and handle everything I feel features missing in the interface which I will need or wish to use.

    Maybe they can be added somehow in the future or it’s limited to do so. For me I think using the native way if not possible to add is the way to go.

    As version contorlling is possible to add en enqueue the css and js assets to a block in the native way in register a block. While not possible in ACFE interface.

    While I do not want to load it globlaly only in wp admin and frontend where the block is used. It’s hard to know where it is used and restrict it to urls or cpt. So using the native way is the way to go for now.

    Thanks for answering all the questions and I understand it might be complex to implement in the UI.

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘Enqueue css and/or js for dynamic block type outside themes folder’ is closed to new replies.