Filters enabled view modes to assure they are registered.

This commit is contained in:
mateuswetah 2024-10-31 15:18:47 -03:00
parent 94875d050b
commit 5a5f40c6c9
1 changed files with 5 additions and 1 deletions

View File

@ -81,9 +81,13 @@ export default (element) => {
// At first, we consider that all registered view modes are included. // At first, we consider that all registered view modes are included.
let possibleViewModes = registeredViewModes; let possibleViewModes = registeredViewModes;
if ( getDataAttribute(blockElement, 'enabled-view-modes') != undefined ) if ( getDataAttribute(blockElement, 'enabled-view-modes') != undefined ) {
possibleViewModes = getDataAttribute(blockElement, 'enabled-view-modes').split(','); possibleViewModes = getDataAttribute(blockElement, 'enabled-view-modes').split(',');
// Filter out the view modes that are not registered
possibleViewModes = possibleViewModes.filter(viewModeSlug => registeredViewModes.indexOf(viewModeSlug) >= 0);
}
// View Mode settings // View Mode settings
let possibleDefaultViewMode = 'masonry'; let possibleDefaultViewMode = 'masonry';
if ( getDataAttribute(blockElement, 'default-view-mode') != undefined ) if ( getDataAttribute(blockElement, 'default-view-mode') != undefined )