a name of the control * value => a value to show in the control * default => a default value of the control if the "value" option is not specified * items => a callback to return items or an array of items to select * * @author Alex Kovalev * @copyright (c) 2018, Webcraftic Ltd * * @package factory-forms * @since 1.0.0 */ // Exit if accessed directly if ( ! defined( 'ABSPATH' ) ) { exit; } if ( ! class_exists( 'Wbcr_FactoryForms480_DropdownControl' ) ) { class Wbcr_FactoryForms480_DropdownControl extends Wbcr_FactoryForms480_Control { public $type = 'dropdown'; /** * Returns a set of available items for the list. * * @since 1.0.0 * @return mixed[] */ private function getItems() { $data = $this->getOption( 'data', array() ); // if the data options is a valid callback for an object method if ( ( is_array( $data ) && count( $data ) == 2 && is_object( $data[0] ) ) || is_string( $data ) ) { return call_user_func( $data ); } // if the data options is an array of values return $data; } /** * Returns true, if the data should be loaded via ajax. * * @since 1.0.0 * @return bool */ protected function isAjax() { $data = $this->getOption( 'data', array() ); return is_array( $data ) && isset( $data['ajax'] ); } /** * Shows the html markup of the control. * * @since 1.0.0 * @return void */ public function html() { $way = $this->getOption( 'way', 'default' ); $this->addHtmlData( 'way', $way ); $events_data = $this->getOption( 'events', array() ); if ( ! empty( $events_data ) ) { $events_string_data = json_encode( $events_data ); $name_on_form = $this->getNameOnForm(); $value = $this->getValue(); if ( empty( $value ) || ( is_array( $value ) && empty( $value[0] ) ) ) { $value = null; } if ( ! empty( $value ) && isset( $events_data[ $value ] ) && is_array( $events_data[ $value ] ) ) { $print_styles = ''; foreach ( $events_data[ $value ] as $eventName => $selectors ) { if ( $eventName == 'hide' ) { $print_styles .= $selectors . '{display:none;}'; } else if ( $eventName == 'show' ) { $print_styles .= $selectors . '{display:block;}'; } } echo ''; } ?> isAjax() ) { $data = $this->getOption( 'data', array() ); $ajax_id = 'factory-dropdown-' . rand( 1000000, 9999999 ); $value = $this->getValue(); if ( empty( $value ) || ( is_array( $value ) && empty( $value[0] ) ) ) { $value = null; } ?>
addHtmlData( 'ajax', true ); $this->addHtmlData( 'ajax-data-id', $ajax_id ); $this->addCssClass( 'factory-hidden' ); } if ( 'buttons' == $way ) { $this->buttonsHtml(); } elseif ( 'ddslick' == $way ) { $this->ddslickHtml(); } else { $this->defaultHtml(); } } /** * Shows the Buttons Dropdown. * * @since 1.0.0 * @return void */ protected function buttonsHtml() { $items = $this->getItems(); $value = $this->getValue(); $name_on_form = $this->getNameOnForm(); $this->addCssClass( 'factory-buttons-way' ); ?>
attrs() ?>>
>
getItems(); $value = $this->getValue(); $name_on_form = $this->getNameOnForm(); $this->addCssClass( 'factory-ddslick-way' ); $this->addHtmlData( 'name', $name_on_form ); $this->addHtmlData( 'width', $this->getOption( 'width', 300 ) ); $this->addHtmlData( 'align', $this->getOption( 'imagePosition', 'right' ) ); ?>
attrs() ?>>
getItems(); $value = esc_attr( $this->getValue() ); $name_on_form = $this->getNameOnForm(); $this->addHtmlAttr( 'id', $name_on_form ); $this->addHtmlAttr( 'name', $name_on_form ); $this->addCssClass( 'form-control' ); $hasGroups = $this->getOption( 'hasGroups', true ); $has_hints = $this->getOption( 'hasHints', false ); foreach ( $items as $item ) { if ( isset( $item['type'] ) && $item['type'] == 'group' && ! empty( $item['items'] ) ) { foreach ( (array) $item['items'] as $group_item ) { $is_hint = ( isset( $group_item['hint'] ) && ! empty( $group_item['hint'] ) ) || ( isset( $group_item[2] ) && ! empty( $group_item[2] ) ); if ( ! $is_hint ) { continue; } $has_hints = true; break; } if ( $has_hints ) { break; } } else { $is_hint = ( isset( $item['hint'] ) && ! empty( $item['hint'] ) ) || ( isset( $item[2] ) && ! $item[2] ); if ( ! $is_hint ) { continue; } $has_hints = true; break; } } $is_empty = $this->isAjax() || empty( $items ); $empty_list = $this->getOption( 'empty', __( '- empty -', 'wbcr_factory_forms_480' ) ); ?>
printHint( $hint, $value, $value !== $value ); } } else { $hint = isset( $item[2] ) ? esc_attr( $item[2] ) : null; $hint = isset( $item['hint'] ) ? esc_attr( $item['hint'] ) : $hint; $value = isset( $item[0] ) ? esc_attr( $item[0] ) : null; $value = isset( $item['value'] ) ? esc_attr( $item['value'] ) : $value; $this->printHint( $hint, $value, $value !== $value ); } } ?>
printItems( $subitems, $selected ); ?> $values ) { $strData = $strData . ' data-' . $key . '="' . ( is_array( $values ) ? implode( ',', $values ) : $values ) . '"'; } } ?>