<?php
/*
 * Copyright (c) 2013, webvariants GbR, http://www.webvariants.de
 *
 * This file is released under the terms of the MIT license. You can find the
 * complete text in the attached LICENSE file or online at:
 *
 * http://www.opensource.org/licenses/mit-license.php
 */

$artID    = $this->getDisplayValue();
$category = 0;
$value    = sly_Form_Widget_Link::getFullName($artID);
$name     = sly_html($this->getName());
$id       = sly_html($this->getID());

if ($value === '') {
	$artID = '';
}
else {
	$category = sly_Util_Article::findById($artID)->getCategoryId();
}

$typeFilter     = '';
$categoryFilter = '';

if (!empty($this->types)) {
	$typeFilter = ' data-articletypes="'.sly_html(implode('|', $this->types)).'"';
}

if (!empty($this->categories)) {
	$categoryFilter = ' data-categories="'.implode('|', $this->categories).'"';
}

$cls = 'sly-widget sly-link'.(isset($this->attributes['class']) ? ' '.sly_html($this->attributes['class']) : '');

if ($this->getAttribute('required') === 'required') {
	$cls .= ' required';
}

?>

<span class="<?php echo $cls ?>" data-catid="<?php echo $category ?>"<?php echo $typeFilter.$categoryFilter ?>>
	<input class="value" type="hidden" name="<?php echo $name ?>" value="<?php echo sly_html($artID) ?>" />
	<input class="name sly-form-text" type="text" id="<?php echo $id ?>" value="<?php echo sly_html($value) ?>" readonly="readonly" />

	<span class="sly-icons"><a href="#" class="fct-open" title="<?php echo t('select_link') ?>"></a></span>
	<span class="sly-icons"><a href="#" class="fct-delete" title="<?php echo t('remove_link') ?>"></a></span>
</span>
