Custom fields with positions

This commit is contained in:
Diego Najar 2019-09-09 20:34:50 +02:00
parent 23237cb05d
commit 3c72a8eafb
3 changed files with 188 additions and 50 deletions

View File

@ -113,18 +113,23 @@ EOF;
} }
$tip = ''; $tip = '';
if (isset($args['tip'])) { if (!empty($args['tip'])) {
$tip = '<small class="form-text text-muted">'.$args['tip'].'</small>'; $tip = '<small class="form-text text-muted">'.$args['tip'].'</small>';
} }
$label = ''; $class = 'form-group m-0';
if (isset($args['label'])) { if (isset($args['class'])) {
$label = '<label class="mt-4 mb-2 pb-2 border-bottom text-uppercase w-100" for="'.$id.'">'.$args['label'].'</label>'; $class = $args['class'];
} }
$class = 'form-control'; $labelClass = 'mt-4 mb-2 pb-2 border-bottom text-uppercase w-100';
if (isset($args['class'])) { if (isset($args['labelClass'])) {
$class = $class.' '.$args['class']; $labelClass = $args['labelClass'];
}
$label = '';
if (!empty($args['label'])) {
$label = '<label class="'.$labelClass.'" for="'.$id.'">'.$args['label'].'</label>';
} }
$type = 'text'; $type = 'text';
@ -133,9 +138,9 @@ EOF;
} }
return <<<EOF return <<<EOF
<div class="form-group m-0"> <div class="$class">
$label $label
<input type="text" value="$value" class="$class" id="$id" name="$name" placeholder="$placeholder" $disabled> <input type="text" value="$value" class="form-control" id="$id" name="$name" placeholder="$placeholder" $disabled>
$tip $tip
</div> </div>
EOF; EOF;
@ -275,7 +280,12 @@ EOF;
$class = 'form-group m-0'; $class = 'form-group m-0';
if (isset($args['class'])) { if (isset($args['class'])) {
$class = $class.' '.$args['class']; $class = $args['class'];
}
$labelClass = 'mt-4 mb-2 pb-2 border-bottom text-uppercase w-100';
if (isset($args['labelClass'])) {
$labelClass = $args['labelClass'];
} }
$type = 'text'; $type = 'text';
@ -285,7 +295,7 @@ EOF;
$label = ''; $label = '';
if (!empty($args['label'])) { if (!empty($args['label'])) {
$label = '<label class="mt-4 mb-2 pb-2 border-bottom text-uppercase w-100">'.$args['label'].'</label>'; $label = '<label class="'.$labelClass.'">'.$args['label'].'</label>';
} }
$checked = $args['checked']?'checked':''; $checked = $args['checked']?'checked':'';

View File

@ -53,7 +53,7 @@ echo Bootstrap::formOpen(array(
?> ?>
<!-- TOOLBAR --> <!-- TOOLBAR -->
<div id="jseditorToolbar"> <div id="jseditorToolbar" class="mb-1">
<div id="jseditorToolbarRight" class="btn-group btn-group-sm float-right" role="group" aria-label="Toolbar right"> <div id="jseditorToolbarRight" class="btn-group btn-group-sm float-right" role="group" aria-label="Toolbar right">
<button type="button" class="btn btn-light" id="jsmediaManagerOpenModal" data-toggle="modal" data-target="#jsmediaManagerModal"><span class="fa fa-image"></span> <?php $L->p('Images') ?></button> <button type="button" class="btn btn-light" id="jsmediaManagerOpenModal" data-toggle="modal" data-target="#jsmediaManagerModal"><span class="fa fa-image"></span> <?php $L->p('Images') ?></button>
<button type="button" class="btn btn-light" id="jsoptionsSidebar" style="z-index:30"><span class="fa fa-cog"></span> <?php $L->p('Options') ?></button> <button type="button" class="btn btn-light" id="jsoptionsSidebar" style="z-index:30"><span class="fa fa-cog"></span> <?php $L->p('Options') ?></button>
@ -292,24 +292,26 @@ echo Bootstrap::formOpen(array(
<div id="nav-custom" class="tab-pane fade" role="tabpanel" aria-labelledby="custom-tab"> <div id="nav-custom" class="tab-pane fade" role="tabpanel" aria-labelledby="custom-tab">
<?php <?php
$customFields = $site->customFields(); $customFields = $site->customFields();
foreach($customFields as $field=>$options) { foreach ($customFields as $field=>$options) {
if ($options['type']=="string") { if ( !isset($options['position']) ) {
echo Bootstrap::formInputTextBlock(array( if ($options['type']=="string") {
'name'=>'custom['.$field.']', echo Bootstrap::formInputTextBlock(array(
'value'=>(isset($options['default'])?$options['default']:''), 'name'=>'custom['.$field.']',
'tip'=>(isset($options['tip'])?$options['tip']:''), 'value'=>(isset($options['default'])?$options['default']:''),
'label'=>(isset($options['label'])?$options['label']:''), 'tip'=>(isset($options['tip'])?$options['tip']:''),
'placeholder'=>(isset($options['placeholder'])?$options['placeholder']:''), 'label'=>(isset($options['label'])?$options['label']:''),
'value'=>$page->custom($field) 'placeholder'=>(isset($options['placeholder'])?$options['placeholder']:''),
)); 'value'=>$page->custom($field)
} elseif ($options['type']=="bool") { ));
echo Bootstrap::formCheckbox(array( } elseif ($options['type']=="bool") {
'name'=>'custom['.$field.']', echo Bootstrap::formCheckbox(array(
'label'=>(isset($options['label'])?$options['label']:''), 'name'=>'custom['.$field.']',
'placeholder'=>(isset($options['placeholder'])?$options['placeholder']:''), 'label'=>(isset($options['label'])?$options['label']:''),
'checked'=>$page->custom($field), 'placeholder'=>(isset($options['placeholder'])?$options['placeholder']:''),
'labelForCheckbox'=>(isset($options['tip'])?$options['tip']:'') 'checked'=>$page->custom($field),
)); 'labelForCheckbox'=>(isset($options['tip'])?$options['tip']:'')
));
}
} }
} }
?> ?>
@ -361,14 +363,76 @@ echo Bootstrap::formOpen(array(
</div> </div>
</div> </div>
<!-- Custom fields: TOP -->
<?php
$customFields = $site->customFields();
foreach ($customFields as $field=>$options) {
if ( isset($options['position']) && ($options['position']=='top') ) {
if ($options['type']=="string") {
echo Bootstrap::formInputTextBlock(array(
'name'=>'custom['.$field.']',
'label'=>(isset($options['label'])?$options['label']:''),
'value'=>$page->custom($field),
'tip'=>(isset($options['tip'])?$options['tip']:''),
'placeholder'=>(isset($options['placeholder'])?$options['placeholder']:''),
'class'=>'mb-2',
'labelClass'=>'mb-2 pb-2 border-bottom text-uppercase w-100'
));
} elseif ($options['type']=="bool") {
echo Bootstrap::formCheckbox(array(
'name'=>'custom['.$field.']',
'label'=>(isset($options['label'])?$options['label']:''),
'placeholder'=>(isset($options['placeholder'])?$options['placeholder']:''),
'checked'=>$page->custom($field),
'labelForCheckbox'=>(isset($options['tip'])?$options['tip']:''),
'class'=>'mb-2',
'labelClass'=>'mb-2 pb-2 border-bottom text-uppercase w-100'
));
}
}
}
?>
<!-- Title --> <!-- Title -->
<div class="form-group mt-1 mb-1"> <div class="form-group mb-1">
<input id="jstitle" name="title" type="text" class="form-control form-control-lg rounded-0" value="<?php echo $page->title() ?>" placeholder="<?php $L->p('Enter title') ?>"> <input id="jstitle" name="title" type="text" class="form-control form-control-lg rounded-0" value="<?php echo $page->title() ?>" placeholder="<?php $L->p('Enter title') ?>">
</div> </div>
<!-- Editor --> <!-- Editor -->
<textarea id="jseditor" class="editable h-100" style=""><?php echo $page->contentRaw(true) ?></textarea> <textarea id="jseditor" class="editable h-100" style=""><?php echo $page->contentRaw(true) ?></textarea>
<!-- Custom fields: BOTTOM -->
<?php
$customFields = $site->customFields();
foreach ($customFields as $field=>$options) {
if ( isset($options['position']) && ($options['position']=='bottom') ) {
if ($options['type']=="string") {
echo Bootstrap::formInputTextBlock(array(
'name'=>'custom['.$field.']',
'label'=>(isset($options['label'])?$options['label']:''),
'value'=>$page->custom($field),
'tip'=>(isset($options['tip'])?$options['tip']:''),
'placeholder'=>(isset($options['placeholder'])?$options['placeholder']:''),
'class'=>'mt-2',
'labelClass'=>'mb-2 pb-2 border-bottom text-uppercase w-100'
));
} elseif ($options['type']=="bool") {
echo Bootstrap::formCheckbox(array(
'name'=>'custom['.$field.']',
'label'=>(isset($options['label'])?$options['label']:''),
'placeholder'=>(isset($options['placeholder'])?$options['placeholder']:''),
'checked'=>$page->custom($field),
'labelForCheckbox'=>(isset($options['tip'])?$options['tip']:''),
'class'=>'mt-2',
'labelClass'=>'mb-2 pb-2 border-bottom text-uppercase w-100'
));
}
}
}
?>
</form> </form>
<!-- Modal for Delete page --> <!-- Modal for Delete page -->

View File

@ -47,7 +47,7 @@ echo Bootstrap::formOpen(array(
?> ?>
<!-- TOOLBAR --> <!-- TOOLBAR -->
<div id="jseditorToolbar"> <div id="jseditorToolbar" class="mb-1">
<div id="jseditorToolbarRight" class="btn-group btn-group-sm float-right" role="group" aria-label="Toolbar right"> <div id="jseditorToolbarRight" class="btn-group btn-group-sm float-right" role="group" aria-label="Toolbar right">
<button type="button" class="btn btn-light" id="jsmediaManagerOpenModal" data-toggle="modal" data-target="#jsmediaManagerModal"><span class="fa fa-image"></span> <?php $L->p('Images') ?></button> <button type="button" class="btn btn-light" id="jsmediaManagerOpenModal" data-toggle="modal" data-target="#jsmediaManagerModal"><span class="fa fa-image"></span> <?php $L->p('Images') ?></button>
<button type="button" class="btn btn-light" id="jsoptionsSidebar" style="z-index:30"><span class="fa fa-cog"></span> <?php $L->p('Options') ?></button> <button type="button" class="btn btn-light" id="jsoptionsSidebar" style="z-index:30"><span class="fa fa-cog"></span> <?php $L->p('Options') ?></button>
@ -267,23 +267,25 @@ echo Bootstrap::formOpen(array(
<div id="nav-custom" class="tab-pane fade" role="tabpanel" aria-labelledby="custom-tab"> <div id="nav-custom" class="tab-pane fade" role="tabpanel" aria-labelledby="custom-tab">
<?php <?php
$customFields = $site->customFields(); $customFields = $site->customFields();
foreach($customFields as $field=>$options) { foreach ($customFields as $field=>$options) {
if ($options['type']=="string") { if ( !isset($options['position']) ) {
echo Bootstrap::formInputTextBlock(array( if ($options['type']=="string") {
'name'=>'custom['.$field.']', echo Bootstrap::formInputTextBlock(array(
'label'=>(isset($options['label'])?$options['label']:''), 'name'=>'custom['.$field.']',
'value'=>(isset($options['default'])?$options['default']:''), 'label'=>(isset($options['label'])?$options['label']:''),
'tip'=>(isset($options['tip'])?$options['tip']:''), 'value'=>(isset($options['default'])?$options['default']:''),
'placeholder'=>(isset($options['placeholder'])?$options['placeholder']:'') 'tip'=>(isset($options['tip'])?$options['tip']:''),
)); 'placeholder'=>(isset($options['placeholder'])?$options['placeholder']:'')
} elseif ($options['type']=="bool") { ));
echo Bootstrap::formCheckbox(array( } elseif ($options['type']=="bool") {
'name'=>'custom['.$field.']', echo Bootstrap::formCheckbox(array(
'label'=>(isset($options['label'])?$options['label']:''), 'name'=>'custom['.$field.']',
'placeholder'=>(isset($options['placeholder'])?$options['placeholder']:''), 'label'=>(isset($options['label'])?$options['label']:''),
'checked'=>(isset($options['checked'])?true:false), 'placeholder'=>(isset($options['placeholder'])?$options['placeholder']:''),
'labelForCheckbox'=>(isset($options['tip'])?$options['tip']:'') 'checked'=>(isset($options['checked'])?true:false),
)); 'labelForCheckbox'=>(isset($options['tip'])?$options['tip']:'')
));
}
} }
} }
?> ?>
@ -333,14 +335,76 @@ echo Bootstrap::formOpen(array(
</div> </div>
</div> </div>
<!-- Custom fields: TOP -->
<?php
$customFields = $site->customFields();
foreach ($customFields as $field=>$options) {
if ( isset($options['position']) && ($options['position']=='top') ) {
if ($options['type']=="string") {
echo Bootstrap::formInputTextBlock(array(
'name'=>'custom['.$field.']',
'label'=>(isset($options['label'])?$options['label']:''),
'value'=>(isset($options['default'])?$options['default']:''),
'tip'=>(isset($options['tip'])?$options['tip']:''),
'placeholder'=>(isset($options['placeholder'])?$options['placeholder']:''),
'class'=>'mb-2',
'labelClass'=>'mb-2 pb-2 border-bottom text-uppercase w-100'
));
} elseif ($options['type']=="bool") {
echo Bootstrap::formCheckbox(array(
'name'=>'custom['.$field.']',
'label'=>(isset($options['label'])?$options['label']:''),
'placeholder'=>(isset($options['placeholder'])?$options['placeholder']:''),
'checked'=>(isset($options['checked'])?true:false),
'labelForCheckbox'=>(isset($options['tip'])?$options['tip']:''),
'class'=>'mb-2',
'labelClass'=>'mb-2 pb-2 border-bottom text-uppercase w-100'
));
}
}
}
?>
<!-- Title --> <!-- Title -->
<div id="jseditorTitle" class="form-group mt-1 mb-1"> <div id="jseditorTitle" class="form-group mb-1">
<input id="jstitle" name="title" type="text" class="form-control form-control-lg rounded-0" value="" placeholder="<?php $L->p('Enter title') ?>"> <input id="jstitle" name="title" type="text" class="form-control form-control-lg rounded-0" value="" placeholder="<?php $L->p('Enter title') ?>">
</div> </div>
<!-- Editor --> <!-- Editor -->
<textarea id="jseditor" class="editable h-100 mb-1"></textarea> <textarea id="jseditor" class="editable h-100 mb-1"></textarea>
<!-- Custom fields: BOTTOM -->
<?php
$customFields = $site->customFields();
foreach ($customFields as $field=>$options) {
if ( isset($options['position']) && ($options['position']=='bottom') ) {
if ($options['type']=="string") {
echo Bootstrap::formInputTextBlock(array(
'name'=>'custom['.$field.']',
'label'=>(isset($options['label'])?$options['label']:''),
'value'=>(isset($options['default'])?$options['default']:''),
'tip'=>(isset($options['tip'])?$options['tip']:''),
'placeholder'=>(isset($options['placeholder'])?$options['placeholder']:''),
'class'=>'mt-2',
'labelClass'=>'mb-2 pb-2 border-bottom text-uppercase w-100'
));
} elseif ($options['type']=="bool") {
echo Bootstrap::formCheckbox(array(
'name'=>'custom['.$field.']',
'label'=>(isset($options['label'])?$options['label']:''),
'placeholder'=>(isset($options['placeholder'])?$options['placeholder']:''),
'checked'=>(isset($options['checked'])?true:false),
'labelForCheckbox'=>(isset($options['tip'])?$options['tip']:''),
'class'=>'mt-2',
'labelClass'=>'mb-2 pb-2 border-bottom text-uppercase w-100'
));
}
}
}
?>
</form> </form>
<!-- Modal for Media Manager --> <!-- Modal for Media Manager -->