Inventory_Presser_Slider::form( array $instance )

Outputs the widget settings form that is shown in the dashboard.


Parameters Parameters

$instance

(array) (Required)


Top ↑

Return Return

(void)


Top ↑

Source Source

File: includes/widget/class-widget-inventory-slider.php

	public function form( $instance ) {

		$title     = isset( $instance['title'] ) ? $instance['title'] : '';
		$showcount = (int) isset( $instance['showcount'] ) ? $instance['showcount'] : 3;

		$featured_select_slugs = array_keys( $this->featured_select_options() );
		$featured_select       = isset( $instance['featured_select'] ) ? $instance['featured_select'] : $featured_select_slugs[0];

		$text_displays_slugs = array_keys( $this->text_displays );
		$showtext            = isset( $instance['showtext'] ) ? $instance['showtext'] : $text_displays_slugs[0]; // "none"

		// Widget admin form.
		?>
		<p>
		<label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php esc_html_e( 'Title:', 'inventory-presser' ); ?></label>
		<input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" />
		</p>
		<p>
		<label for="<?php echo esc_attr( $this->get_field_id( 'showcount' ) ); ?>"><?php esc_html_e( 'Vehicles to show at one time:', 'inventory-presser' ); ?></label>
		<select class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'showcount' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'showcount' ) ); ?>">
		<?php
		for ( $i = 1; $i < 8; $i++ ) {
			printf(
				'<option value="%1$d"%2$s>%1$d</option>',
				esc_attr( $i ),
				selected( $i === $showcount, true, false )
			);
		}
		?>
		</select></p><p class="description">
		<?php

		esc_html_e( 'Limited to two (2) on display widths of 480px and less.', 'inventory-presser' );

		?>
		</p>

		<p>
		<label for="<?php echo esc_attr( $this->get_field_id( 'featured_select' ) ); ?>"><?php esc_html_e( 'Vehicle Selection:', 'inventory-presser' ); ?></label>
		<select class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'featured_select' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'featured_select' ) ); ?>">
		<?php
		foreach ( $this->featured_select_options() as $slug => $label ) {
			printf(
				'<option value="%s"%s>%s</option>',
				esc_attr( $slug ),
				selected( true, $slug === $featured_select, false ),
				esc_html( $label )
			);
		}
		?>
		</select>
		</p>

		<p>
		<label for="<?php echo esc_attr( $this->get_field_id( 'showtext' ) ); ?>"><?php esc_html_e( 'Text Overlay:', 'inventory-presser' ); ?></label>
		<select class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'showtext' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'showtext' ) ); ?>">
		<?php
		foreach ( $this->text_displays as $slug => $label ) {
			printf(
				'<option value="%s"%s>%s</option>',
				esc_attr( $slug ),
				selected( $slug === $showtext, true, false ),
				esc_html( $label )
			);
		}
		?>
		</select>
		</p>
		<?php

		/**
		 * This inline JavaScript disables two checkboxes depending on the
		 * value of the Text Overlay dropdown above. Some trickery is
		 * involved, because the readonly attribute only locks an inputs
		 * value and a checkbox being checked isn't the value, it's the
		 * state. A click handler is added and removed to prevent state
		 * changes to the two checkboxes if Text Overlay is set to None.
		 */

		?>
		<script type="text/javascript">
		<!--
			function __return_false(){ return false; }
			jQuery(document).ready(function(){
				var sel = jQuery('#<?php echo $this->get_field_id( 'showtext' ); ?>');
				sel.on('change', function(){
					var chks =jQuery('#<?php echo $this->get_field_id( 'cb_showtitle' ); ?>,#<?php echo $this->get_field_id( 'cb_showprice' ); ?>');
					chks.attr('readonly', ('none'==sel.val()));            
					if('none'==sel.val())
					{
						chks.on('click',__return_false);
					}
					else
					{
						chks.off('click', __return_false);
					}
				});
			});
		//-->
		</script>
		<p>
		<label for="<?php echo esc_attr( $this->get_field_id( 'cb_showtitle' ) ); ?>"><input type="checkbox" id="<?php echo esc_attr( $this->get_field_id( 'cb_showtitle' ) ); ?>" name="<?php echo $this->get_field_name( 'cb_showtitle' ); ?>" value="true"<?php checked( true, ( isset( $instance['cb_showtitle'] ) && 'true' === $instance['cb_showtitle'] ) ); ?>> <?php esc_html_e( 'Overlay year, make, & model', 'inventory-presser' ); ?></label>
		</p>
		<p>
		<label for="<?php echo esc_attr( $this->get_field_id( 'cb_showprice' ) ); ?>"><input type="checkbox" id="<?php echo esc_attr( $this->get_field_id( 'cb_showprice' ) ); ?>" name="<?php echo $this->get_field_name( 'cb_showprice' ); ?>" value="true"<?php checked( true, ( isset( $instance['cb_showprice'] ) && 'true' === $instance['cb_showprice'] ) ); ?>> <?php esc_html_e( 'Overlay price', 'inventory-presser' ); ?></label>
		</p>

		<?php
	}