input.menu.php
Поле «Редактирование меню»
Вызывается из:
Исходный код
<?php
$attributes = $Field->getFieldInputAttributes(array(
'grid-margin' => $Field->getInputMargin(),
'grid-width' => $Field->getInputWidth(),
'class' => 'field-input field-input--' . $Field->type,
));
print '<div';
foreach ($attributes as $attributeName => $attributeValue) if ($attributeValue !== null) print ' ' . $attributeName . '="' . $attributeValue . '"';
print '>';
$menuLevel = $Field->level > 0 ? intval($Field->level) : 0;
$menuImage = $Field->image ? true : false;
?>
<div class="uk-grid uk-child-width-1-2@l" id="<?=$Field->id('-menu')?>">
<div>
<div class="uk-placeholder uk-height-viewport">
<ul class="uk-list uk-position-sticky uk-position-top uk-position-z-index" data-menu-menu>
<div class="uk-text-center"><a data-menu-add><?=$Main->translate('Добавьте пункт меню')?></a></div>
<div class="uk-text-center uk-text-muted uk-margin-bottom"><?=$Main->translate('Перетащите сюда пункты меню')?></div>
</ul>
</div>
</div>
<div data-menu-sitemap>
</div>
</div>
<?php
$value = $Field->value;
if (is_string($value) && $value[0] === '[' && $value[strlen($value) - 1] === ']') {
$value = $value;
} elseif (is_array($value)) {
$value = json_encode($value, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
} elseif (is_array($Field->list)) {
$value = array();
foreach ($Field->list as $item) {
$value[] = array(
'id' => $item['id'],
'item' => array(
'href' => $Main->href($item['id']),
'title' => $item['title'],
),
);
}
$value = json_encode($value, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
} else {
$value = '[]';
}
$attributes = $Field->getInputAttributes(array(
'type' => 'hidden',
'name' => $Field->name,
'value' => $Field->v($value),
'placeholder' => strval($Field->placeholder) !== '' ? htmlspecialchars($Field->placeholder) : null,
'required' => $Field->required ? '' : null,
'readonly' => $Field->readonly ? '' : null,
'disabled' => $Field->disabled ? '' : null,
'id' => $Field->id('-input'),
));
print '<input';
foreach ($attributes as $attributeName => $attributeValue) if ($attributeValue !== null) print ' ' . $attributeName . '="' . $attributeValue . '"';
print '>';
?>
<?php
print '</div>';
?>
<script>
cmsRequire(['form/script/input.menu'], init => init(document.getElementById(<?=$Field->jId('-input')?>), { el: document.getElementById(<?=$Field->jId('-menu')?>), menuLevel: <?=json_encode($menuLevel, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE)?>, menuImage: <?=json_encode($menuImage, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE)?>, emptyHref: <?=json_encode('#', JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE)?>, emptyTitle: <?=json_encode($Main->translate('Текст ссылки'), JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE)?>, emptyImage: <?=json_encode($Main->translate('Изображение'), JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE)?> }));
</script>