クラス
Semantic
ソース ソース
ファイル: src/Components/CustomFields/Templates/Semantic.php
class Semantic
{
    /**
     * Flag for custom fields meta
     *
     * @var boolean
     */
    public $hasCustomFields;
    /**
     * Array of custom fields
     *
     * @var array
     */
    public $customFields;
    /**
     * Sets custom fields
     *
     * @author Evan D Shaw <evandanielshaw@gmail.com>
     * @param boolean $hasCustomFields
     * @param array   $customFields
     * @return void
     */
    public function __construct($hasCustomFields, $customFields) {
        $this->hasCustomFields = $hasCustomFields;
        $this->customFields = $customFields;
    }
    /**
     * Loads assets for this template
     *
     * @author Evan D Shaw <evandanielshaw@gmail.com>
     * @return void
     */
    public function init() {
        add_action('wp_enqueue_scripts', function () {
            $load_dropdown = false;
            $load_checkbox = false;
            if ($this->hasCustomFields === true) {
                foreach ($this->customFields as $key => $vals) {
                    if ($vals['means'] === 3 || $vals['means'] === 4) {
                        $load_checkbox = true;
                    } elseif ($vals['means'] === 0 || $vals['means'] === 1) {
                        $load_dropdown = true;
                    }
                }
            }
            $semantic = new ScriptsSemantic();
            $semantic->loadInputCss();
            $semantic->loadFormCss();
            if ($load_checkbox === true) {
                $semantic->loadCheckboxCss();
            }
            if ($load_dropdown === true) {
                $semantic->loadDropdownCss();
            }
        });
    }
    /**
     * Displays custom fields meta.
     *
     * @author Evan D Shaw <evandanielshaw@gmail.com>
     * @param array  $data
     * @param string $custom_field
     * @param string $position
     * @return void
     */
    public function uscesCustomFieldInput($data, $custom_field, $position) {
        global $usces_essential_mark;
        $label = 'custom_' . $custom_field;
        $meta = usces_has_custom_field_meta($custom_field);
        ob_start();
        if (!empty($meta) && is_array($meta)) {
            foreach ($meta as $key => $entry) {
                if ($custom_field === 'order' || $entry['position'] === $position) {
                    $name = $entry['name'];
                    $means = (int)$entry['means'];
                    $essential = (int)$entry['essential'];
                    $value = '';
                    if (is_array($entry['value'])) {
                        foreach ($entry['value'] as $k => $v) {
                            $value .= $v . "\n";
                        }
                    }
                    $value = usces_change_line_break($value);
                    $e = '';
                    if ($essential === 1) {
                        $e = isset($usces_essential_mark[$key])
                            ? usces_get_essential_mark($key)
                            : '<em>' . __('*', 'usces') . '</em>';
                    }
                    /**
                     * Mirrored Welcart filter
                     *
                     * @ignore
                     */
                    $heading = $e . esc_html($name) . apply_filters(
                        'usces_filter_custom_field_input_label',
                        null,
                        $key,
                        $entry
                    );
                    switch ($means) {
                        case 0: // シングルセレクト
                        case 1: // マルチセレクト NOTE: multi-select isnt an option for custom fields
                            $selects = explode("\n", $value);
                            ?>
                            <div class="field">
                                <label><?php echo $heading ?></label>
                                <select
                                    v-model="customFields.<?php echo esc_attr($key) ?>.value"
                                    name="<?php echo esc_attr($label) ?>[<?php echo esc_attr($key) ?>]"
                                    class="ui dropdown"
                                >
                                    <option value="#NONE#"><?php echo esc_html__('Choose', 'usces') ?></option>
                                    <?php
                                    foreach ($selects as $v) :
                                        $selected = (isset($data[$label][$key]) && $data[$label][$key] == $v)
                                            ? ' selected'
                                            : '';
                                        ?>
                                        <option value="<?php echo esc_attr($v) ?>" <?php echo esc_attr($selected) ?>>
                                            <?php echo esc_html($v) ?>
                                        </option>
                                        <?php
                                    endforeach;
                                    ?>
                                </select>
                            </div>
                            <!-- <div v-cloak v-if="errorMessages.<?php // echo esc_attr($key) ?>" class="error_message">
                                <?php // echo '{{ errorMessages.' . esc_attr($key) . '}}' ?>
                            </div> -->
                            <?php
                            break;
                        case 2: // テキスト
                            ?>
                            <div class="field">
                                <label><?php echo $heading ?></label>
                                <input
                                    type="text"
                                    v-model="customFields.<?php echo esc_attr($key) ?>.value"
                                    name="<?php echo esc_attr($label) ?>[<?php echo esc_attr($key) ?>]"
                                >
                            </div>
                            <?php
                            break;
                        case 3: // ラジオボタン
                            ?>
                            <div class="grouped fields customkey_<?php echo esc_attr($key) ?>">
                                <label><?php echo $heading ?></label>
                                <?php
                                $selects = explode("\n", $value);
                                foreach ($selects as $v) :
                                    $checked = (isset($data[$label][$key]) && $data[$label][$key] == $v)
                                        ? ' checked'
                                        : '';
                                    ?>
                                    <div class="field">
                                        <div class="ui radio checkbox">
                                            <input
                                                type="radio"
                                                v-model="customFields.<?php echo esc_attr($key) ?>.value"
                                                name="<?php echo esc_attr($label) ?>[<?php echo esc_attr($key) ?>]"
                                                id="<?php echo esc_attr($label) ?>[<?php echo esc_attr($key) ?>][<?php echo esc_attr($v) ?>]"
                                                value="<?php echo esc_attr($v) ?>"<?php echo esc_attr($checked) ?>
                                            >
                                            <label class="iopt_label"><?php echo esc_html($v) ?></label>
                                        </div>
                                    </div>
                                    <?php
                                endforeach;
                                ?>
                            </div>
                            <?php
                            break;
                        case 4: // チェックボックス
                            $selects = explode("\n", $value);
                            ?>
                            <div class="grouped fields customkey_<?php echo esc_attr($key) ?>">
                                <label><?php echo $heading ?></label>
                                <?php
                                foreach ($selects as $v) :
                                    if (isset($data[$label][$key]) && is_array($data[$label][$key])) {
                                        $checked = (isset($data[$label][$key]) && array_key_exists($v, $data[$label][$key]))
                                            ? ' checked'
                                            : '';
                                    } else {
                                        $checked = (isset($data[$label][$key]) && $data[$label][$key] == $v)
                                            ? ' checked'
                                            : '';
                                    }
                                    ?>
                                    <div class="field">
                                        <div class="ui checkbox">
                                            <input
                                                type="checkbox"
                                                v-model="customFields.<?php echo esc_attr($key) ?>.value[<?php echo '\'' . esc_attr($v) . '\'' ?>]"
                                                name="<?php echo esc_attr($label) ?>[<?php echo esc_attr($key) ?>][<?php echo esc_attr($v) ?>]"
                                                value="<?php echo esc_attr($v) ?>"<?php echo esc_attr($checked) ?>
                                            >
                                        <label><?php echo esc_html($v) ?></label>
                                        </div>
                                    </div>
                                    <?php
                                endforeach;
                                ?>
                            </div>
                            <?php
                            break;
                        case 5: // Text-area
                            ?>
                            <div class="field">
                                <label><?php echo $heading ?></label>
                                <textarea
                                    v-model="customFields.<?php echo esc_attr($key) ?>.value"
                                    name="<?php echo esc_attr($label) ?>[<?php echo esc_attr($key) ?>]"
                                ></textarea>
                            </div>
                            <?php
                            break;
                    }
                }
            }
        }
        $html = ob_get_clean();
        if (!empty($html)) {
            $html = '<div class="ui form aap" id="' . esc_attr('custom_' . $custom_field) . '">' . $html . '</div>';
        }
        /**
         * Filters the custom fields HTML shown on the Quickpay page
         *
         * @param string $html
         * @param array  $data
         * @param string $custom_field
         * @param string $position
         */
        $html = apply_filters('wcexaap_filter_custom_field_input', $html, $data, $custom_field, $position);
        echo stripslashes($html);
    }
}
- __construct — Sets custom fields
 - init — Loads assets for this template
 - uscesCustomFieldInput — Displays custom fields meta.