mirror of
https://github.com/processwire/processwire.git
synced 2025-08-09 00:06:55 +02:00
Update ProcessPageEdit so that the template selection input (settings tab) is Ajax-loaded, like the parent selection input
This commit is contained in:
@@ -317,6 +317,7 @@ class ProcessPageEdit extends Process implements WirePageEditor, ConfigurableMod
|
|||||||
'confirm' => true,
|
'confirm' => true,
|
||||||
'ajaxChildren' => true,
|
'ajaxChildren' => true,
|
||||||
'ajaxParent' => true,
|
'ajaxParent' => true,
|
||||||
|
'ajaxTemplate' => true,
|
||||||
'editCrumbs' => false,
|
'editCrumbs' => false,
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -1187,12 +1188,14 @@ class ProcessPageEdit extends Process implements WirePageEditor, ConfigurableMod
|
|||||||
$field->addOption(__('Native Fields', __FILE__), $options); // Optgroup label for sorting by fields native to ProcessWire
|
$field->addOption(__('Native Fields', __FILE__), $options); // Optgroup label for sorting by fields native to ProcessWire
|
||||||
|
|
||||||
$customOptions = array();
|
$customOptions = array();
|
||||||
|
$fields = $caller->wire()->fields;
|
||||||
|
$fieldsInfo = $fields->getAllValues(array('flags', 'type'), 'name');
|
||||||
|
|
||||||
foreach($caller->wire('fields') as $f) {
|
foreach($fieldsInfo as $name => $f) {
|
||||||
//if(!($f->flags & Field::flagAutojoin)) continue;
|
//if(!($f->flags & Field::flagAutojoin)) continue;
|
||||||
if($f->flags & Field::flagSystem && $f->name != 'title' && $f->name != 'email') continue;
|
if($f['flags'] & Field::flagSystem && $name != 'title' && $name != 'email') continue;
|
||||||
if($f->type instanceof FieldtypeFieldsetOpen) continue;
|
if(wireInstanceOf($f['type'], 'FieldtypeFieldsetOpen')) continue;
|
||||||
$customOptions[$f->name] = $f->name;
|
$customOptions[$name] = $name;
|
||||||
}
|
}
|
||||||
|
|
||||||
ksort($customOptions);
|
ksort($customOptions);
|
||||||
@@ -1316,31 +1319,33 @@ class ProcessPageEdit extends Process implements WirePageEditor, ConfigurableMod
|
|||||||
protected function buildFormTemplate() {
|
protected function buildFormTemplate() {
|
||||||
|
|
||||||
if($this->page->editable('template', false)) {
|
if($this->page->editable('template', false)) {
|
||||||
/** @var Languages $languages */
|
$languages = $this->wire()->languages;
|
||||||
$languages = $this->wire('languages');
|
$language = $this->user->language; /** @var Language|null $language */
|
||||||
/** @var Language $language */
|
$input = $this->wire()->input;
|
||||||
$language = $this->user->language;
|
$ajax = $this->configSettings['ajaxTemplate'];
|
||||||
|
|
||||||
/** @var InputfieldSelect $field */
|
/** @var InputfieldSelect $field */
|
||||||
$field = $this->modules->get('InputfieldSelect');
|
$field = $this->modules->get('InputfieldSelect');
|
||||||
$field->attr('id+name', 'template');
|
$field->attr('id+name', 'template');
|
||||||
$field->attr('value', $this->page->template->id);
|
$field->attr('value', $this->page->template->id);
|
||||||
$field->required = true;
|
$field->required = true;
|
||||||
|
$field->collapsed = Inputfield::collapsedYesAjax;
|
||||||
foreach($this->getAllowedTemplates() as $template) {
|
if(!$ajax || $input->get('renderInputfieldAjax') === 'template' || $input->post('template') !== null) {
|
||||||
/** @var Template $template */
|
foreach($this->getAllowedTemplates() as $template) {
|
||||||
$label = '';
|
/** @var Template $template */
|
||||||
if($languages && $language) $label = $template->get('label' . $language->id);
|
$label = '';
|
||||||
if(!$label) $label = $template->label ? $template->label : $template->name;
|
if($languages && $language) $label = $template->get('label' . $language->id);
|
||||||
$field->addOption($template->id, $label);
|
if(!$label) $label = $template->label ? $template->label : $template->name;
|
||||||
|
$field->addOption($template->id, $label);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/** @var InputfieldMarkup $field */
|
/** @var InputfieldMarkup $field */
|
||||||
$field = $this->modules->get('InputfieldMarkup');
|
$field = $this->modules->get('InputfieldMarkup');
|
||||||
$field->attr('value', "<p>" . $this->page->template->getLabel() . "</p>");
|
$field->attr('value', "<p>" . $this->wire()->sanitizer->entities1($this->page->template->getLabel()) . "</p>");
|
||||||
}
|
}
|
||||||
|
|
||||||
$field->label = $this->_('Template'); // Settings: Template field label
|
$field->label = $this->_('Template') . ' (' . $this->page->template->getLabel() . ')'; // Settings: Template field label
|
||||||
$field->icon = 'cubes';
|
$field->icon = 'cubes';
|
||||||
|
|
||||||
return $field;
|
return $field;
|
||||||
@@ -2183,20 +2188,22 @@ class ProcessPageEdit extends Process implements WirePageEditor, ConfigurableMod
|
|||||||
*/
|
*/
|
||||||
protected function ___processInput(InputfieldWrapper $form, $level = 0, $formRoot = null) {
|
protected function ___processInput(InputfieldWrapper $form, $level = 0, $formRoot = null) {
|
||||||
|
|
||||||
|
$input = $this->wire()->input;
|
||||||
|
$languages = $this->wire()->languages;
|
||||||
|
|
||||||
static $skipFields = array(
|
static $skipFields = array(
|
||||||
'sortfield_reverse',
|
'sortfield_reverse',
|
||||||
'submit_publish',
|
'submit_publish',
|
||||||
'submit_save',
|
'submit_save',
|
||||||
'delete_page',
|
'delete_page',
|
||||||
);
|
);
|
||||||
|
|
||||||
if(!$level) {
|
if(!$level) {
|
||||||
$form->processInput($this->input->post);
|
$form->processInput($input->post);
|
||||||
$formRoot = $form;
|
$formRoot = $form;
|
||||||
$this->page->setQuietly('_forceAddStatus', 0);
|
$this->page->setQuietly('_forceAddStatus', 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
$languages = $this->wire()->languages;
|
|
||||||
$errorAction = (int) $this->page->template->errorAction;
|
$errorAction = (int) $this->page->template->errorAction;
|
||||||
|
|
||||||
foreach($form as $inputfield) {
|
foreach($form as $inputfield) {
|
||||||
@@ -2772,6 +2779,7 @@ class ProcessPageEdit extends Process implements WirePageEditor, ConfigurableMod
|
|||||||
|
|
||||||
$allTemplates = count($this->predefinedTemplates) ? $this->predefinedTemplates : $this->wire('templates');
|
$allTemplates = count($this->predefinedTemplates) ? $this->predefinedTemplates : $this->wire('templates');
|
||||||
|
|
||||||
|
// note: this triggers load of all templates, fieldgroups and fields
|
||||||
foreach($allTemplates as $template) {
|
foreach($allTemplates as $template) {
|
||||||
/** @var Template $template */
|
/** @var Template $template */
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user