| 1 |
import { __ } from '@wordpress/i18n'; |
| 2 |
import { PanelBody, TextControl, SelectControl } from '@wordpress/components'; |
| 3 |
import BaseFieldEdit from '../../components/BaseFieldEdit'; |
| 4 |
|
| 5 |
// Public taxonomies published by the editor bridge (the same set the classic |
| 6 |
// Manage Fields <select> uses; value = taxonomy slug, label = taxonomy label). |
| 7 |
// Falls back to an empty list so a missing payload degrades to an empty |
| 8 |
// control. |
| 9 |
function getTaxonomyOptions() { |
| 10 |
const fb = ( typeof window !== 'undefined' && window.wppbFb ) || {}; |
| 11 |
const list = ( fb.selectFields && fb.selectFields.taxonomies ) || []; |
| 12 |
return Array.isArray( list ) ? list : []; |
| 13 |
} |
| 14 |
|
| 15 |
export default function Edit( props ) { |
| 16 |
const { attributes, setAttributes } = props; |
| 17 |
const options = getTaxonomyOptions(); |
| 18 |
|
| 19 |
const extraPanels = ( |
| 20 |
<PanelBody title={ __( 'Select (Taxonomy) Settings', 'profile-builder' ) }> |
| 21 |
<SelectControl |
| 22 |
label={ __( 'Show Taxonomy Term', 'profile-builder' ) } |
| 23 |
value={ attributes.taxonomy } |
| 24 |
options={ options } |
| 25 |
onChange={ ( val ) => setAttributes( { taxonomy: val } ) } |
| 26 |
help={ __( 'Terms from this taxonomy will be displayed in the select.', 'profile-builder' ) } |
| 27 |
/> |
| 28 |
<TextControl |
| 29 |
label={ __( 'Default Option', 'profile-builder' ) } |
| 30 |
value={ attributes[ 'default-option' ] } |
| 31 |
onChange={ ( val ) => setAttributes( { 'default-option': val } ) } |
| 32 |
help={ __( 'Enter the ID of the default term.', 'profile-builder' ) } |
| 33 |
/> |
| 34 |
</PanelBody> |
| 35 |
); |
| 36 |
|
| 37 |
return ( |
| 38 |
<BaseFieldEdit { ...props } inspectorPanels={ extraPanels }> |
| 39 |
<select disabled style={ { width: '100%' } }> |
| 40 |
<option>{ __( '(List of taxonomy terms will be generated here)', 'profile-builder' ) }</option> |
| 41 |
</select> |
| 42 |
</BaseFieldEdit> |
| 43 |
); |
| 44 |
} |
| 45 |
|