Skip to content

Commit

Permalink
improved meta field rendering when Custom Meta is not supported in po…
Browse files Browse the repository at this point in the history
…st type.
  • Loading branch information
Fellan-91 committed Oct 31, 2024
1 parent 00d063d commit 0bb2470
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions assets/components/render-controls/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { cloneDeep } from 'lodash';
import { Component, Fragment, RawHTML } from '@wordpress/element';
import { applyFilters } from '@wordpress/hooks';
import { PanelBody, Notice } from '@wordpress/components';
import { select } from '@wordpress/data';
import { __ } from '@wordpress/i18n';

/**
* Internal dependencies.
Expand Down Expand Up @@ -316,12 +318,36 @@ export default class RenderControls extends Component {

if (controlResult) {
const val = controlRenderData.getValue();
let controlNotice = '';
const controlNotice = [];

// Display an error for meta controls when the post type doesn't support custom fields and the control is configured to save_in_meta fields.
if (controlData.save_in_meta === 'true') {
const postType = select('core/editor').getCurrentPostType();
const postTypeObject = select('core').getPostType(postType);

const postTypeSupportMeta =
postTypeObject?.supports?.['custom-fields'] || false;
if (!postTypeSupportMeta) {
controlNotice.push(
<Notice
key={`notice-${controlData.name}`}
status="error"
isDismissible={false}
className="lzb-constructor-notice"
>
{__(
"This post type doesn't support custom fields",
'lazy-blocks'
)}
</Notice>
);
}
}

// show error for required fields
const requiredError = checkControlValidity(val, controlData);
if (allowErrorNotice && requiredError) {
controlNotice = (
controlNotice.push(
<Notice
key={`notice-${controlData.name}`}
status="error"
Expand Down

0 comments on commit 0bb2470

Please sign in to comment.