* @copyright Copyright (c) 2020 Samuel Marshall / JCH Optimize
* @license GNU/GPLv3, or later. See LICENSE file
*
* If LICENSE file missing, see .
*/
defined( '_JEXEC' ) or die( 'No direct access' );
use Joomla\CMS\HTML\HTMLHelper;
require_once JPATH_ADMINISTRATOR . '/components/com_menus/helpers/menus.php';
class JFormFieldMenuselection extends JFormField
{
public $type = 'menuselection';
public function setup( SimpleXMLElement $element, $value, $group = null )
{
$script_options = array( 'framework' => false, 'relative' => true );
if ( version_compare( JVERSION, '3.99.99', '<' ) )
{
JHtml::script( 'jui/jquery.min.js' );
JHtml::_( 'script', 'jui/treeselectmenu.jquery.min.js', false, true );
}
else
{
HTMLHelper::_( 'script', 'vendor/jquery/jquery.min.js', $script_options );
$oDocument = JFactory::getDocument();
$oDocument->addScript( JUri::root( true ) . '/media/legacy/js/treeselectmenu.js' );
}
if ( ! is_array( $value ) )
{
$value = array();
}
return parent::setup( $element, $value, $group );
}
protected function getInput()
{
$menuTypes = MenusHelper::getMenuLinks();
$html = '';
if ( ! empty( $menuTypes ) ) :
$id = 'jform_menuselect';
$html .= '
';
foreach ( $menuTypes as &$type ) :
if ( count( $type->links ) ) :
$prevlevel = 0;
$html .= '-
';
foreach ( $type->links as $i => $link ) :
if ( $prevlevel < $link->level )
{
$html .= '';
}
elseif ( $prevlevel > $link->level )
{
$html .= str_repeat( '
', $prevlevel - $link->level );
}
else
{
$html .= '';
}
// $selected = 0;
// if ($pluginassignment == 0)
// {
// $selected = 1;
// } elseif ($pluginassingment < 0)
// {
// $selected = in_array(-$link->value, $this->value);
// } elseif ($pluginassignment > 0)
// {
$selected = in_array( $link->value, $this->value );
// }
$html .= '
';
$menuitems_limit = 50;
if ( ! isset( $type->links[ $i + 1 ] ) || $i > $menuitems_limit )
{
$html .= str_repeat( '', $link->level );
}
$prevlevel = $link->level;
if ( $i > $menuitems_limit )
{
break;
}
endforeach;
$html .= ' ';
endif;
endforeach;
$html .= '
' . JText::_( 'JGLOBAL_NO_MATCHING_RESULTS' ) . '
';
endif;
return $html;
}
}