mirror of
https://github.com/flextype/flextype.git
synced 2025-08-12 16:14:16 +02:00
Admin Panel: Fieldsets Manager - using New Fieldsets API
This commit is contained in:
@@ -73,130 +73,6 @@ class EntriesManager
|
||||
return $files;
|
||||
}
|
||||
|
||||
public static function displayEntryForm(array $fieldsets, array $values = []) : void
|
||||
{
|
||||
echo Form::open(null, ['id' => 'form']);
|
||||
echo Form::hidden('token', Token::generate());
|
||||
echo Form::hidden('action', 'save-form');
|
||||
|
||||
if (count($fieldsets['sections']) > 0) {
|
||||
|
||||
echo ('<ul class="nav nav-pills nav-justified" id="pills-tab" role="tablist">');
|
||||
|
||||
foreach ($fieldsets['sections'] as $key => $section) {
|
||||
echo ('<li class="nav-item">
|
||||
<a class="nav-link '.(($key == 'main') ? 'active' : '').'" id="pills-'.$key.'-tab" data-toggle="pill" href="#pills-'.$key.'" role="tab" aria-controls="pills-'.$key.'" aria-selected="true">'.$section['title'].'</a>
|
||||
</li>');
|
||||
}
|
||||
|
||||
echo ('</ul>');
|
||||
|
||||
echo ('<div class="tab-content" id="pills-tabContent">');
|
||||
|
||||
foreach ($fieldsets['sections'] as $key => $section) {
|
||||
|
||||
echo ('<div class="tab-pane fade show '.(($key == 'main') ? 'active' : '').'" id="pills-'.$key.'" role="tabpanel" aria-labelledby="pills-'.$key.'-tab">');
|
||||
echo ('<div class="row">');
|
||||
|
||||
foreach ($section['fields'] as $element => $property) {
|
||||
|
||||
// Create attributes
|
||||
$property['attributes'] = Arr::keyExists($property, 'attributes') ? $property['attributes'] : [];
|
||||
|
||||
// Create attribute class
|
||||
$property['attributes']['class'] = Arr::keyExists($property, 'attributes.class') ? 'form-control ' . $property['attributes']['class'] : 'form-control';
|
||||
|
||||
// Create attribute size
|
||||
$property['size'] = Arr::keyExists($property, 'size') ? $property['size'] : 'col-12';
|
||||
|
||||
// Create attribute value
|
||||
$property['value'] = Arr::keyExists($property, 'value') ? $property['value'] : '';
|
||||
|
||||
$pos = strpos($element, '.');
|
||||
|
||||
if ($pos === false) {
|
||||
$form_element_name = $element;
|
||||
} else {
|
||||
$form_element_name = str_replace(".", "][", "$element") . ']';
|
||||
}
|
||||
|
||||
$pos = strpos($form_element_name, ']');
|
||||
|
||||
if ($pos !== false) {
|
||||
$form_element_name = substr_replace($form_element_name, '', $pos, strlen(']'));
|
||||
}
|
||||
|
||||
// Form value
|
||||
$form_value = Arr::keyExists($values, $element) ? Arr::get($values, $element) : $property['value'];
|
||||
|
||||
// Form label
|
||||
$form_label = Form::label($element, __($property['title']));
|
||||
|
||||
// Form elements
|
||||
switch ($property['type']) {
|
||||
|
||||
// Simple text-input, for multi-line fields.
|
||||
case 'textarea':
|
||||
$form_element = Form::textarea($element, $form_value, $property['attributes']);
|
||||
break;
|
||||
|
||||
// The hidden field is like the text field, except it's hidden from the content editor.
|
||||
case 'hidden':
|
||||
$form_element = Form::hidden($element, $form_value);
|
||||
break;
|
||||
|
||||
// A WYSIWYG HTML field.
|
||||
case 'html':
|
||||
$property['attributes']['class'] .= ' js-html-editor';
|
||||
$form_element = Form::textarea($element, $form_value, $property['attributes']);
|
||||
break;
|
||||
|
||||
// Selectbox field
|
||||
case 'select':
|
||||
$form_element = Form::select($form_element_name, $property['options'], $form_value, $property['attributes']);
|
||||
break;
|
||||
|
||||
// Template select field for selecting entry template
|
||||
case 'template_select':
|
||||
$form_element = Form::select($form_element_name, Themes::getTemplates(), $form_value, $property['attributes']);
|
||||
break;
|
||||
|
||||
// Visibility select field for selecting entry visibility state
|
||||
case 'visibility_select':
|
||||
$form_element = Form::select($form_element_name, ['draft' => __('admin_entries_draft'), 'visible' => __('admin_entries_visible'), 'hidden' => __('admin_entries_hidden')], (!empty($form_value) ? $form_value : 'visible'), $property['attributes']);
|
||||
break;
|
||||
|
||||
// Media select field
|
||||
case 'media_select':
|
||||
$form_element = Form::select($form_element_name, EntriesManager::getMediaList(Http::get('entry'), false), $form_value, $property['attributes']);
|
||||
break;
|
||||
|
||||
// Simple text-input, for single-line fields.
|
||||
default:
|
||||
$form_element = Form::input($form_element_name, $form_value, $property['attributes']);
|
||||
break;
|
||||
}
|
||||
|
||||
// Render form elments with labels
|
||||
if ($property['type'] == 'hidden') {
|
||||
echo $form_element;
|
||||
} else {
|
||||
echo '<div class="form-group ' . $property['size'] . '">';
|
||||
echo $form_label . $form_element;
|
||||
echo '</div>';
|
||||
}
|
||||
}
|
||||
|
||||
echo ('</div>');
|
||||
echo ('</div>');
|
||||
}
|
||||
|
||||
echo ('</div>');
|
||||
}
|
||||
|
||||
echo Form::close();
|
||||
}
|
||||
|
||||
protected static function getEntriesQuery() : string
|
||||
{
|
||||
if (Http::get('entry') && Http::get('entry') != '') {
|
||||
|
Reference in New Issue
Block a user