You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The Theme class in Theme.php could be refactored to do this, since its mostly Timber focused anyway. That said.... the requirements are also heavily ACF required, so... 🤷
Changes and/or things to put in Timber.php class
Move acf_block_gutenberg_callback() into it, so its only needed once (though, obviously, unique blocks can call their own).
Move elegant_get_timber_template_directories() into it, so its not a 'stand-alone' function on Theme.php and embarrassing me.
Move elegant_add_to_timber_paths() into it, so its not a 'stand-alone' function on Theme.php and embarrassing me.
New
Create a hook_load_point() and hook_save_point() function to leverage both the acf/settings/load_json filter and the acf/settings/save_json filter for the custom ACF blocks loaded within the Block directory.
Something like:
<?phpnamespaceElegant\ACFLoaderif ( !acf_function()) {
// Toss an error of 'ACF Pro Required'exit;
}
class ACFLoader {
publicfunctionrun() : void {
// Update the ACF-JSON Load Pointadd_filter('acf/settings/load_json', array( $this, 'acf_json_load_point' ));
// Update the ACF-JSON Save Pointadd_filter('acf/settings/save_json', array( $this, 'acf_json_save_point' ));
}
/** * ACF Compile Function * * Loads the default ACF file for this Module. * * Note: Any changes, when saved, will be saved in ACF's default save-point. * This loader function only loads the default settings. * * @since 0.1.2 * @param array $acf_paths - Current set of ACF directories. * @return array $acf_paths - New set of ACF directories to load. * @see https://www.advancedcustomfields.com/resources/local-json/ * @see https://www.awesomeacf.com/snippets/load-acf-json-files-from-multiple-locations/ */publicstaticfunctionacf_json_load_point( $acf_paths ) {
// Do things to set the Load Point// example pseudocode// Remove original path (optional).
unset($acf_paths[0]);
// Load Block ACFs.$block_paths = glob(get_template_directory() . '/inc/Block/' . "any" . '/' . "any" . '.php');
foreach($block_pathsas$block_path) {
$block_name = basename($block_path);
$file_name = get_template_directory() . '/inc/Block/' . "???" . '/' . $block_name . '.php'// This would require creating an /acf/ folder inside of each /Block/ folder.
if (file_exists($file_name)) {
$acf_paths[] = get_stylesheet_directory() . '/blocks/' . $block_name . '/acf/';
}
}
// Append the path.$acf_paths[] = get_stylesheet_directory() . '/inc/acf/json';
// Return the updated path.return$acf_paths;
}
/** * Helper Function to overwrite default acf-json folder. * * See previous function for notes. * * @since 1.0.1 * @param string $path used by ACF to determine where acf.json files are saved. * @return string $path * @see https://www.advancedcustomfields.com/resources/local-json/#saving-explained */publicstaticfunction acf_json_save_point( $path ) {
// Do things to set the Save Point
/**
* So each custom block created by ACF has a { location: [param:block]}
*
* The trick would be that IF'block' is selected, then it needs to go in /Block.
* Similarly, IF '<theme-setting>' is selected, it should be in (something like) /Module.
*
* The second trick is: It is NOT an array, like the load_point.
*
* Which means it would have to be reset-to-default EVERY time, in order not to lose anything.
* /
}
}
The text was updated successfully, but these errors were encountered:
cleverington
changed the title
Create a Timber.php Class and move acf_block_gutenberg_callback() into it, for cleaner code
Create a Timber.php Class and...
Jun 4, 2022
Alternative:
The
Theme
class inTheme.php
could be refactored to do this, since its mostly Timber focused anyway. That said.... the requirements are also heavily ACF required, so... 🤷Changes and/or things to put in
Timber.php
classacf_block_gutenberg_callback()
into it, so its only needed once (though, obviously, unique blocks can call their own).elegant_get_timber_template_directories()
into it, so its not a 'stand-alone' function onTheme.php
and embarrassing me.elegant_add_to_timber_paths()
into it, so its not a 'stand-alone' function onTheme.php
and embarrassing me.New
Create a
hook_load_point()
andhook_save_point()
function to leverage both theacf/settings/load_json
filter and theacf/settings/save_json
filter for the custom ACF blocks loaded within theBlock
directory.Something like:
The text was updated successfully, but these errors were encountered: