input.block.php
Поле «Список блоков»
Вызывается из:
Исходный код
<?php
$attributes = $Field->getFieldInputAttributes(array(
'grid-margin' => $Field->getInputMargin(),
'grid-width' => $Field->getInputWidth(),
'class' => 'field-input field-input--' . $Field->type,
));
print '<span';
foreach ($attributes as $attributeName => $attributeValue) if ($attributeValue !== null) print ' ' . $attributeName . '="' . $attributeValue . '"';
print '>';
$Block = $App->get('block');
$blockCount = 0;
$blockDefault = $Block->getBlockDefault($Page);
$blockWrapper = $Block->getBlockWrapper($Page);
print '<div class="block-list" id="' . $Field->id('-input') . '">';
if (is_array($Field->list) && count($Field->list)) {
foreach ($Field->list as $item) {
$blockCount ++;
$attributes = array( 'class' => 'block-item' );
foreach ($item as $k => $v) if (is_scalar($v) || $v === null) $attributes['data-' . $k] = $v;
if ($blockWrapper[$item['block']]) $attributes['data-wrapper'] = 'Y';
print '<div';
foreach ($attributes as $attributeName => $attributeValue) if ($attributeValue !== null) print ' ' . $attributeName . '="' . htmlspecialchars($attributeValue) . '"';
print '><div class="block-inner">';
print '<span class="input-label--checkbox"><input type="checkbox" data-name="active" value="Y"' . ($item['active'] ? ' checked=""' : '') . ' class="input--checkbox" title="Показывать блок" uk-tooltip="">';
$html = '';
if ($item['data'] && $item['data']['title']) $html .= htmlspecialchars($item['data']['title']);
if ($item['title']) {
if ($html) $html .= ': ';
$html .= htmlspecialchars($item['title']);
}
$html = '<span class="label-text" data-title>' . $html . '</span>';
$html .= '<span class="uk-iconnav uk-flex-nowrap">';
if ($href = $Block->getBlockEditHref($Page, $item)) $html .= ' <span><a href="' . $href . '" data-panel="modal-form" data-modal-form="{"reload":false}" title="Редактировать блок" uk-tooltip=""><i class="las la-pen"></i></a></span>';
$html .= ' <span><a data-delete title="Удалить блок" uk-tooltip=""><i class="las la-times"></i></a></span>';
$html .= '</span>';
print $html;
print '</span>';
$attributes = array();
$attributes['type'] = 'hidden';
$attributes['name'] = $Field->name . '[]';
if (isset($item['data'])) {
$value = array(
'n' => $item['n'],
'block' => $item['block'],
'active' => $item['active'],
'order' => $item['order'],
'data' => $item['data'],
);
if (isset($item['parent_n']) && $item['parent_n'] && isset($item['parent_block']) && $item['parent_block']) {
$value['parent_n'] = $item['parent_n'];
$value['parent_block'] = $item['parent_block'];
}
$attributes['value'] = json_encode($value, defined('JSON_UNESCAPED_UNICODE') && defined('JSON_UNESCAPED_SLASHES') ? JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES : 0);
}
print '<input';
foreach ($attributes as $attributeName => $attributeValue) if ($attributeValue !== null) print ' ' . $attributeName . '="' . htmlspecialchars($attributeValue) . '"';
print '>';
if ($blockWrapper[$item['block']]) {
print '<div class="uk-placeholder uk-margin-small-top uk-margin-remove-bottom uk-padding-remove"><div class="uk-grid uk-grid-small uk-padding-small uk-child-width-1-1" uk-grid></div></div>';
}
print '</div></div>';
}
}
print '</div>';
print '<button type="button" class="uk-button uk-button-success' . ($blockCount ? ' uk-margin-small-top' : '') . '"><i class="las la-plus uk-margin-small-right"></i>' . $Main->translate('Добавить блок') . '</button>';
print '<div class="uk-dropdown uk-drop" uk-dropdown="mode: click"><ul class="uk-nav uk-dropdown-nav uk-text-default">';
foreach ($Block->getBlock($Page) as $block => $title) {
print '<li><a class="uk-drop-close" data-block="' . htmlspecialchars($block) . '"' . ($blockDefault[$block] ? ' data-default="Y"' : '') . ($blockWrapper[$block] ? ' data-wrapper="Y"' : '') . ' data-id="' . htmlspecialchars($Page->id) . '">' . htmlspecialchars($title) . '</a></li>';
}
print '</ul></div>';
print '</span>';
?>
<script>
cmsRequire(['form/script/input.block'], init => init(document.getElementById(<?=$Field->jId('-input')?>)));
</script>