<?php
/**
 * @version    $Id$
* @package    IT_Theme_Framework
* @author     InnoThemes Team <support@innothemes.com>
* @copyright  Copyright (C) 2012 InnoThemes.com. All Rights Reserved.
* @license    GNU/GPL v2 or later http://www.gnu.org/licenses/gpl-2.0.html
*
* Websites: http://www.innothemes.com
*/

/**
 * Menu selector field renderer.
*
* @package  IT_Theme_Framework
* @since    1.0.0
*/
class IT_Form_Field_Menu_Selector extends IT_Form_Field_Select {
	/**
	 * Field type.
	 *
	 * @var  string
	 */
	protected $type = 'menu-selector';

	/**
	 * Constructor.
	 *
	 * @param   array  $config  Field declaration.
	 *
	 * @return  void
	 */
	public function __construct( $config ) {
		parent::__construct( $config );

		// Get all menus
		$locations = get_registered_nav_menus();
		$menus     = wp_get_nav_menus();

		foreach ( $menus as $menu ) {
			$truncated_name = wp_html_excerpt( $menu->name, 40 );

			$this->choices[ $menu->term_id ] = ( $truncated_name == $menu->name ) ? $menu->name : trim( $truncated_name ) . '&hellip;';
		}

		// Reset field type to select
		$this->type = 'select';
	}
}
