radio.php 0000644 00000002544 15155472353 0006372 0 ustar 00 <?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access pages directly.
/**
*
* Field: Radio
*
* @since 1.0.0
* @version 1.0.0
*
*/
class CSFramework_Option_radio extends CSFramework_Options {
public function __construct( $field, $value = '', $unique = '' ) {
parent::__construct( $field, $value, $unique );
}
public function output(){
echo $this->element_before();
if( isset( $this->field['options'] ) ) {
$options = $this->field['options'];
$options = ( is_array( $options ) ) ? $options : array_filter( $this->element_data( $options ) );
if( ! empty( $options ) ) {
echo '<ul'. $this->element_class() .'>';
foreach ( $options as $key => $value ) {
echo '<li><label><input type="radio" name="'. $this->element_name() .'" value="'. $key .'"'. $this->element_attributes( $key ) . $this->checked( $this->element_value(), $key ) .'/> '. $value .'</label></li>';
}
echo '</ul>';
}
} else {
$label = ( isset( $this->field['label'] ) ) ? $this->field['label'] : '';
echo '<label><input type="radio" name="'. $this->element_name() .'" value="1"'. $this->element_class() . $this->element_attributes() . checked( $this->element_value(), 1, false ) .'/> '. $label .'</label>';
}
echo $this->element_after();
}
}
block.json 0000644 00000001661 15155666301 0006545 0 ustar 00 {
"$schema": "https://schemas.wp.org/trunk/block.json",
"apiVersion": 2,
"name": "woocommerce/product-radio-field",
"title": "Product radio control",
"category": "woocommerce",
"description": "The product radio.",
"keywords": ["products", "radio", "input"],
"textdomain": "default",
"attributes": {
"title": {
"type": "string"
},
"description": {
"type": "string"
},
"property": {
"type": "string"
},
"options": {
"type": "array",
"items": {
"type": "object"
},
"default": [],
"__experimentalRole": "content"
}
},
"supports": {
"align": false,
"html": false,
"multiple": true,
"reusable": false,
"inserter": false,
"lock": false,
"__experimentalToolbar": false
}
}
edit.js 0000644 00000001210 15155666301 0006031 0 ustar 00 "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Edit=void 0;const element_1=require("@wordpress/element"),block_editor_1=require("@wordpress/block-editor"),core_data_1=require("@wordpress/core-data"),radio_field_1=require("../../components/radio-field");function Edit({attributes:e}){const t=(0,block_editor_1.useBlockProps)(),{description:r,options:o,property:i,title:d}=e,[s,n]=(0,core_data_1.useEntityProp)("postType","product",i);return(0,element_1.createElement)("div",{...t},(0,element_1.createElement)(radio_field_1.RadioField,{title:d,description:r,selected:s,options:o,onChange:e=>n(e||"")}))}exports.Edit=Edit; index.js 0000644 00000001136 15155666301 0006222 0 ustar 00 "use strict";var __importDefault=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.init=exports.settings=exports.name=exports.metadata=void 0;const init_block_1=require("../../utils/init-block"),block_json_1=__importDefault(require("./block.json")),edit_1=require("./edit"),{name,...metadata}=block_json_1.default;function init(){return(0,init_block_1.initBlock)({name,metadata,settings:exports.settings})}exports.name=name,exports.metadata=metadata,exports.settings={example:{},edit:edit_1.Edit},exports.init=init; types.js 0000644 00000000104 15155666301 0006251 0 ustar 00 "use strict";Object.defineProperty(exports,"__esModule",{value:!0});