Use new code style

This commit is contained in:
David Stone
2025-02-07 19:02:33 -07:00
parent 0181024ae1
commit 8433379d90
672 changed files with 37107 additions and 45249 deletions

View File

@ -44,7 +44,7 @@
},
});
}); // end each;
});
function wu_fields_to_block_options(fields, props) {
@ -72,7 +72,7 @@
field_slug = _.first(_.keys(sub_fields));
} // end if;
}
const component = wu_get_field_component(field.type, field);
@ -80,7 +80,7 @@
field.required = {};
} // end if;
}
let should_display = true;
@ -113,7 +113,7 @@
},
}));
} // end if;
}
/*
* Handle header types differently
@ -126,7 +126,7 @@
new_panel = true;
} // end if;
}
if (new_panel) {
@ -141,7 +141,7 @@
first_panel = false;
} // end if;
}
current_panel = field;
@ -149,7 +149,7 @@
gt_fields = [];
} // end if;
}
});
@ -164,7 +164,7 @@
return el(InspectorControls, { key: 'wp-ultimo' }, gt_panels);
} // end wu_fields_to_block_options;
}
function wu_format_options(options) {
@ -205,7 +205,7 @@
component = NumberControl;
} // end if;
}
break;
@ -233,7 +233,7 @@
break;
} // end switch;
}
return component;

View File

@ -12,7 +12,7 @@ namespace WP_Ultimo\Builders\Block_Editor;
// Exit if accessed directly
defined('ABSPATH') || exit;
use \WP_Ultimo\Database\Sites\Site_Type;
use WP_Ultimo\Database\Sites\Site_Type;
/**
* Handles Block Editor Widget Support.
@ -32,16 +32,13 @@ class Block_Editor_Widget_Manager {
public function init() {
if (\WP_Ultimo\Compat\Gutenberg_Support::get_instance()->should_load()) {
add_action('wu_element_loaded', array($this, 'handle_element'));
add_action('init', array($this, 'register_scripts'));
add_action('wu_element_is_preview', array($this, 'is_block_preview'));
} // end if;
} // end init;
}
}
/**
* Adds the required scripts.
@ -56,8 +53,7 @@ class Block_Editor_Widget_Manager {
$blocks = apply_filters('wu_blocks', array());
wp_localize_script('wu-blocks', 'wu_blocks', $blocks);
} // end register_scripts;
}
/**
* Checks if we are inside a block preview render.
@ -69,14 +65,11 @@ class Block_Editor_Widget_Manager {
public function is_block_preview($is_preview) {
if (defined('REST_REQUEST') && true === REST_REQUEST && 'edit' === filter_input(INPUT_GET, 'context', FILTER_SANITIZE_STRING)) {
$is_preview = true;
} // end if;
}
return $is_preview;
} // end is_block_preview;
}
/**
* Gets called when a new element is registered
@ -89,16 +82,13 @@ class Block_Editor_Widget_Manager {
public function handle_element($element) {
if (wu_get_current_site()->get_type() === Site_Type::CUSTOMER_OWNED) {
return;
} // end if;
}
$this->register_block($element);
add_filter('wu_blocks', fn($blocks) => $this->load_block_settings($blocks, $element));
} // end handle_element;
}
/**
* Registers block with WordPress.
@ -111,20 +101,20 @@ class Block_Editor_Widget_Manager {
public function register_block($element) {
if (\WP_Block_Type_Registry::get_instance()->is_registered($element->get_id())) {
return;
} // end if;
}
$attributes = $this->get_attributes_from_fields($element);
register_block_type($element->get_id(), array(
'attributes' => $attributes,
'editor_script' => 'wu-blocks',
'render_callback' => \Closure::fromCallable([$element, 'display']),
));
} // end register_block;
register_block_type(
$element->get_id(),
array(
'attributes' => $attributes,
'editor_script' => 'wu-blocks',
'render_callback' => \Closure::fromCallable(array($element, 'display')),
)
);
}
/**
* Consolidate field attributes that are callables for blocks.
@ -150,52 +140,36 @@ class Block_Editor_Widget_Manager {
* Discard fields that are notes and start with _
*/
if (in_array($field['type'], $fields_to_ignore, true) && strncmp($field_slug, '_', strlen('_')) === 0) {
unset($fields[$field_slug]);
} // end if;
unset($fields[ $field_slug ]);
}
/*
* Deal with the group type.
* On those, we need to loop the sub-fields.
*/
if ($field['type'] === 'group') {
foreach ($field['fields'] as &$sub_field) {
foreach ($sub_field as $sub_item => &$sub_value) {
if (in_array($sub_item, $callable_keys, true) && is_callable($sub_value)) {
$sub_value = call_user_func($sub_value);
} // end if;
} // end foreach;
} // end foreach;
} // end if;
}
}
}
}
/*
* Deal with the regular field types and its
* callables.
*/
foreach ($field as $item => &$value) {
if (in_array($item, $callable_keys, true) && is_callable($value)) {
$value = call_user_func($value);
} // end if;
} // end foreach;
} // end foreach;
}
}
}
return $fields;
} // end consolidate_callables;
}
/**
* Registers the block so WP Multisite WaaS can add it on the JS side.
@ -219,8 +193,7 @@ class Block_Editor_Widget_Manager {
);
return $blocks;
} // end load_block_settings;
}
/**
* Generates the list of attributes supported based on the fields.
@ -238,32 +211,24 @@ class Block_Editor_Widget_Manager {
$_fields = array();
foreach ($fields as $field_id => $field) {
$type = 'string';
if ($field['type'] === 'toggle') {
$type = 'boolean';
} // end if;
}
if ($field['type'] === 'number') {
$type = 'integer';
} // end if;
}
$default_value = wu_get_isset($defaults, $field_id, '');
$_fields[$field_id] = array(
$_fields[ $field_id ] = array(
'default' => wu_get_isset($field, 'value', $default_value),
'type' => $type,
);
} // end foreach;
}
return $_fields;
} // end get_attributes_from_fields;
} // end class Block_Editor_Widget_Manager;
}
}