mirror of
https://github.com/processwire/processwire.git
synced 2025-08-08 15:57:01 +02:00
Minor optimizations to ProcessPageEdit
This commit is contained in:
@@ -274,6 +274,18 @@ class ProcessPageEdit extends Process implements WirePageEditor, ConfigurableMod
|
|||||||
*/
|
*/
|
||||||
protected $session;
|
protected $session;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var Pages
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
protected $pages;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var Languages|null
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
protected $languages;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sanitized contents of get[modal]
|
* Sanitized contents of get[modal]
|
||||||
*
|
*
|
||||||
@@ -377,6 +389,8 @@ class ProcessPageEdit extends Process implements WirePageEditor, ConfigurableMod
|
|||||||
$this->user = $this->wire()->user;
|
$this->user = $this->wire()->user;
|
||||||
$this->sanitizer = $this->wire()->sanitizer;
|
$this->sanitizer = $this->wire()->sanitizer;
|
||||||
$this->session = $this->wire()->session;
|
$this->session = $this->wire()->session;
|
||||||
|
$this->pages = $this->wire()->pages;
|
||||||
|
$this->languages = $this->wire()->languages;
|
||||||
|
|
||||||
// predefined messages that maybe used in multiple places
|
// predefined messages that maybe used in multiple places
|
||||||
$this->set('noticeUnknown', $this->_("Unknown page")); // Init error: Unknown page
|
$this->set('noticeUnknown', $this->_("Unknown page")); // Init error: Unknown page
|
||||||
@@ -446,7 +460,7 @@ class ProcessPageEdit extends Process implements WirePageEditor, ConfigurableMod
|
|||||||
if($context) $this->requestContext = $this->sanitizer->name($context);
|
if($context) $this->requestContext = $this->sanitizer->name($context);
|
||||||
|
|
||||||
// optional language GET var
|
// optional language GET var
|
||||||
$languages = $this->wire()->languages;
|
$languages = $this->languages;
|
||||||
if($languages) {
|
if($languages) {
|
||||||
$this->hasLanguagePageNames = $languages->hasPageNames();
|
$this->hasLanguagePageNames = $languages->hasPageNames();
|
||||||
if($this->hasLanguagePageNames) {
|
if($this->hasLanguagePageNames) {
|
||||||
@@ -485,7 +499,7 @@ class ProcessPageEdit extends Process implements WirePageEditor, ConfigurableMod
|
|||||||
protected function ___loadPage($id) {
|
protected function ___loadPage($id) {
|
||||||
|
|
||||||
/** @var Page|NullPage $page */
|
/** @var Page|NullPage $page */
|
||||||
$page = $this->wire()->pages->get((int) $id);
|
$page = $this->pages->get((int) $id);
|
||||||
|
|
||||||
if($page instanceof NullPage) {
|
if($page instanceof NullPage) {
|
||||||
throw new WireException($this->noticeUnknown); // page doesn't exist
|
throw new WireException($this->noticeUnknown); // page doesn't exist
|
||||||
@@ -719,7 +733,7 @@ class ProcessPageEdit extends Process implements WirePageEditor, ConfigurableMod
|
|||||||
$url = '';
|
$url = '';
|
||||||
if(!$this->page) throw new WireException('No page yet');
|
if(!$this->page) throw new WireException('No page yet');
|
||||||
if($this->hasLanguagePageNames) {
|
if($this->hasLanguagePageNames) {
|
||||||
$languages = $this->wire()->languages;
|
$languages = $this->languages;
|
||||||
if($language) {
|
if($language) {
|
||||||
if(is_string($language) || is_int($language)) $language = $languages->get($language);
|
if(is_string($language) || is_int($language)) $language = $languages->get($language);
|
||||||
$userLanguage = $language;
|
$userLanguage = $language;
|
||||||
@@ -1269,7 +1283,7 @@ class ProcessPageEdit extends Process implements WirePageEditor, ConfigurableMod
|
|||||||
*/
|
*/
|
||||||
protected function ___buildFormSettings() {
|
protected function ___buildFormSettings() {
|
||||||
|
|
||||||
$user = $this->wire()->user;
|
$user = $this->user;
|
||||||
$superuser = $user->isSuperuser();
|
$superuser = $user->isSuperuser();
|
||||||
|
|
||||||
/** @var InputfieldWrapper $wrapper */
|
/** @var InputfieldWrapper $wrapper */
|
||||||
@@ -1365,37 +1379,33 @@ class ProcessPageEdit extends Process implements WirePageEditor, ConfigurableMod
|
|||||||
*/
|
*/
|
||||||
protected function buildFormTemplate() {
|
protected function buildFormTemplate() {
|
||||||
|
|
||||||
|
$template = $this->page->template;
|
||||||
|
$input = $this->input;
|
||||||
|
|
||||||
if($this->page->editable('template', false)) {
|
if($this->page->editable('template', false)) {
|
||||||
$languages = $this->wire()->languages;
|
|
||||||
$language = $this->user->language; /** @var Language|null $language */
|
|
||||||
$input = $this->wire()->input;
|
|
||||||
$ajax = $this->configSettings['ajaxTemplate'];
|
$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->required = true;
|
$field->required = true;
|
||||||
$field->collapsed = Inputfield::collapsedYesAjax;
|
$field->collapsed = Inputfield::collapsedYesAjax;
|
||||||
if(!$ajax || $input->get('renderInputfieldAjax') === 'template' || $input->post('template') !== null) {
|
if(!$ajax || $input->get('renderInputfieldAjax') === 'template' || $input->post('template') !== null) {
|
||||||
foreach($this->getAllowedTemplates() as $template) {
|
foreach($this->getAllowedTemplates() as $t) {
|
||||||
/** @var Template $template */
|
/** @var Template $t */
|
||||||
$label = '';
|
$field->addOption($t->id, $t->getLabel());
|
||||||
if($languages && $language) $label = $template->get('label' . $language->id);
|
|
||||||
if(!$label) $label = $template->label ? $template->label : $template->name;
|
|
||||||
$field->addOption($template->id, $label);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$template = $this->page->template;
|
|
||||||
$field->addOption($template->id, $template->getLabel());
|
$field->addOption($template->id, $template->getLabel());
|
||||||
}
|
}
|
||||||
|
$field->val($template->id);
|
||||||
} else {
|
} else {
|
||||||
/** @var InputfieldMarkup $field */
|
/** @var InputfieldMarkup $field */
|
||||||
$field = $this->modules->get('InputfieldMarkup');
|
$field = $this->modules->get('InputfieldMarkup');
|
||||||
$field->attr('value', "<p>" . $this->wire()->sanitizer->entities1($this->page->template->getLabel()) . "</p>");
|
$field->attr('value', "<p>" . $this->sanitizer->entities1($template->getLabel()) . "</p>");
|
||||||
}
|
}
|
||||||
|
|
||||||
$field->label = $this->_('Template') . ' (' . $this->page->template->getLabel() . ')'; // Settings: Template field label
|
$field->label = $this->_('Template') . ' (' . $template->getLabel() . ')'; // Settings: Template field label
|
||||||
$field->icon = 'cubes';
|
$field->icon = 'cubes';
|
||||||
|
|
||||||
return $field;
|
return $field;
|
||||||
@@ -1421,7 +1431,7 @@ class ProcessPageEdit extends Process implements WirePageEditor, ConfigurableMod
|
|||||||
if(count($parentTemplates)) {
|
if(count($parentTemplates)) {
|
||||||
$ptStr = implode('|', $parentTemplates);
|
$ptStr = implode('|', $parentTemplates);
|
||||||
$s = "include=unpublished, id!=$template->id, templates_id=$ptStr";
|
$s = "include=unpublished, id!=$template->id, templates_id=$ptStr";
|
||||||
$qty = $this->wire()->pages->count($s);
|
$qty = $this->pages->count($s);
|
||||||
if($qty < 100) {
|
if($qty < 100) {
|
||||||
$isTrash = $this->page->isTrash();
|
$isTrash = $this->page->isTrash();
|
||||||
$maxStatus = $isTrash ? Page::statusMax : Page::statusUnpublished;
|
$maxStatus = $isTrash ? Page::statusMax : Page::statusUnpublished;
|
||||||
@@ -1477,9 +1487,9 @@ class ProcessPageEdit extends Process implements WirePageEditor, ConfigurableMod
|
|||||||
protected function ___buildFormCreatedUser() {
|
protected function ___buildFormCreatedUser() {
|
||||||
|
|
||||||
$templates = $this->wire()->templates;
|
$templates = $this->wire()->templates;
|
||||||
$modules = $this->wire()->modules;
|
$modules = $this->modules;
|
||||||
$config = $this->wire()->config;
|
$config = $this->config;
|
||||||
$pages = $this->wire()->pages;
|
$pages = $this->pages;
|
||||||
|
|
||||||
$selector = "parent_id=$config->usersPageID, include=all, limit=100";
|
$selector = "parent_id=$config->usersPageID, include=all, limit=100";
|
||||||
$usersPageIDs = $config->usersPageIDs;
|
$usersPageIDs = $config->usersPageIDs;
|
||||||
@@ -1607,8 +1617,8 @@ class ProcessPageEdit extends Process implements WirePageEditor, ConfigurableMod
|
|||||||
$input = $this->input;
|
$input = $this->input;
|
||||||
$modules = $this->modules;
|
$modules = $this->modules;
|
||||||
$sanitizer = $this->sanitizer;
|
$sanitizer = $this->sanitizer;
|
||||||
$languages = $this->wire()->languages;
|
$languages = $this->languages;
|
||||||
$pages = $this->wire()->pages;
|
$pages = $this->pages;
|
||||||
|
|
||||||
if($this->isPost && $input->post('_prevpath_add') === null) return null;
|
if($this->isPost && $input->post('_prevpath_add') === null) return null;
|
||||||
if(!$modules->isInstalled('PagePathHistory')) return null;
|
if(!$modules->isInstalled('PagePathHistory')) return null;
|
||||||
@@ -1930,7 +1940,7 @@ class ProcessPageEdit extends Process implements WirePageEditor, ConfigurableMod
|
|||||||
|
|
||||||
if(!$this->page->isTrash()) return false;
|
if(!$this->page->isTrash()) return false;
|
||||||
if(!$this->page->restorable()) return false;
|
if(!$this->page->restorable()) return false;
|
||||||
$info = $this->wire()->pages->trasher()->getRestoreInfo($this->page);
|
$info = $this->pages->trasher()->getRestoreInfo($this->page);
|
||||||
if(!$info['restorable']) return false;
|
if(!$info['restorable']) return false;
|
||||||
|
|
||||||
/** @var InputfieldWrapper $wrapper */
|
/** @var InputfieldWrapper $wrapper */
|
||||||
@@ -2077,8 +2087,9 @@ class ProcessPageEdit extends Process implements WirePageEditor, ConfigurableMod
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(count($addRoles)) {
|
if(count($addRoles)) {
|
||||||
|
$roles = $this->wire()->roles;
|
||||||
foreach($addRoles as $roleID) {
|
foreach($addRoles as $roleID) {
|
||||||
$role = $this->wire('roles')->get($roleID);
|
$role = $roles->get($roleID);
|
||||||
if(!$role->id) continue;
|
if(!$role->id) continue;
|
||||||
if(!$role->hasPermission("page-add", $this->page)) continue;
|
if(!$role->hasPermission("page-add", $this->page)) continue;
|
||||||
$table->row(array($role->name, $addLabel));
|
$table->row(array($role->name, $addLabel));
|
||||||
@@ -2113,8 +2124,8 @@ class ProcessPageEdit extends Process implements WirePageEditor, ConfigurableMod
|
|||||||
*/
|
*/
|
||||||
protected function processSave() {
|
protected function processSave() {
|
||||||
|
|
||||||
$input = $this->wire()->input;
|
$input = $this->input;
|
||||||
$pages = $this->wire()->pages;
|
$pages = $this->pages;
|
||||||
$page = $this->page;
|
$page = $this->page;
|
||||||
$user = $this->user;
|
$user = $this->user;
|
||||||
$form = $this->form;
|
$form = $this->form;
|
||||||
@@ -2319,8 +2330,8 @@ 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;
|
$input = $this->input;
|
||||||
$languages = $this->wire()->languages;
|
$languages = $this->languages;
|
||||||
$page = $this->page;
|
$page = $this->page;
|
||||||
|
|
||||||
static $skipFields = array(
|
static $skipFields = array(
|
||||||
@@ -2588,17 +2599,17 @@ class ProcessPageEdit extends Process implements WirePageEditor, ConfigurableMod
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$redirectUrl = $this->wire()->config->urls->admin . "page/?open={$this->parent->id}";
|
$redirectUrl = $this->config->urls->admin . "page/?open={$this->parent->id}";
|
||||||
if($this->wire()->page->process != $this->className()) $redirectUrl = "../";
|
if($this->wire()->page->process != $this->className()) $redirectUrl = "../";
|
||||||
$pagePath = $page->path();
|
$pagePath = $page->path();
|
||||||
|
|
||||||
if(($this->isTrash || $page->template->noTrash) && $page->deleteable()) {
|
if(($this->isTrash || $page->template->noTrash) && $page->deleteable()) {
|
||||||
$this->wire()->session->message(sprintf($this->_('Deleted page: %s'), $pagePath)); // Page deleted message
|
$this->session->message(sprintf($this->_('Deleted page: %s'), $pagePath)); // Page deleted message
|
||||||
$this->pages->delete($page, true);
|
$this->pages->delete($page, true);
|
||||||
$this->deletedPage($page, $redirectUrl, false);
|
$this->deletedPage($page, $redirectUrl, false);
|
||||||
|
|
||||||
} else if($this->pages->trash($page)) {
|
} else if($this->pages->trash($page)) {
|
||||||
$this->wire()->session->message(sprintf($this->_('Moved page to trash: %s'), $pagePath)); // Page moved to trash message
|
$this->session->message(sprintf($this->_('Moved page to trash: %s'), $pagePath)); // Page moved to trash message
|
||||||
$this->deletedPage($page, $redirectUrl, true);
|
$this->deletedPage($page, $redirectUrl, true);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@@ -2620,7 +2631,7 @@ class ProcessPageEdit extends Process implements WirePageEditor, ConfigurableMod
|
|||||||
*/
|
*/
|
||||||
protected function ___deletedPage($page, $redirectUrl, $trashed = false) {
|
protected function ___deletedPage($page, $redirectUrl, $trashed = false) {
|
||||||
if($page || $trashed) {} // ignore
|
if($page || $trashed) {} // ignore
|
||||||
$this->wire()->session->location($redirectUrl);
|
$this->session->location($redirectUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -2641,7 +2652,7 @@ class ProcessPageEdit extends Process implements WirePageEditor, ConfigurableMod
|
|||||||
if($page->hasStatus(Page::statusLocked)) throw new WireException($this->noticeLocked);
|
if($page->hasStatus(Page::statusLocked)) throw new WireException($this->noticeLocked);
|
||||||
if(!$this->ajaxEditable($page)) throw new WirePermissionException($this->noticeNoAccess);
|
if(!$this->ajaxEditable($page)) throw new WirePermissionException($this->noticeNoAccess);
|
||||||
|
|
||||||
$this->wire()->session->CSRF->validate(); // throws exception when invalid
|
$this->session->CSRF->validate(); // throws exception when invalid
|
||||||
|
|
||||||
/** @var InputfieldWrapper $form */
|
/** @var InputfieldWrapper $form */
|
||||||
$form = $this->wire(new InputfieldWrapper());
|
$form = $this->wire(new InputfieldWrapper());
|
||||||
@@ -2682,7 +2693,7 @@ class ProcessPageEdit extends Process implements WirePageEditor, ConfigurableMod
|
|||||||
$lastFieldName = null;
|
$lastFieldName = null;
|
||||||
$savedNames = array();
|
$savedNames = array();
|
||||||
$saved = false; // was page saved?
|
$saved = false; // was page saved?
|
||||||
$languages = $this->wire()->languages;
|
$languages = $this->languages;
|
||||||
$changes = array();
|
$changes = array();
|
||||||
|
|
||||||
foreach($form->children() as $inputfield) {
|
foreach($form->children() as $inputfield) {
|
||||||
@@ -3224,7 +3235,7 @@ class ProcessPageEdit extends Process implements WirePageEditor, ConfigurableMod
|
|||||||
public function getAllowedStatuses() {
|
public function getAllowedStatuses() {
|
||||||
|
|
||||||
$page = $this->page;
|
$page = $this->page;
|
||||||
$config = $this->wire()->config;
|
$config = $this->config;
|
||||||
$statuses = array();
|
$statuses = array();
|
||||||
$superuser = $this->user->isSuperuser();
|
$superuser = $this->user->isSuperuser();
|
||||||
|
|
||||||
@@ -3241,7 +3252,7 @@ class ProcessPageEdit extends Process implements WirePageEditor, ConfigurableMod
|
|||||||
}
|
}
|
||||||
|
|
||||||
if($superuser) {
|
if($superuser) {
|
||||||
$uniqueNote = ($this->wire('languages') ? ' ' . $this->_('(in default language only)') : '');
|
$uniqueNote = ($this->languages ? ' ' . $this->_('(in default language only)') : '');
|
||||||
$statuses[Page::statusUnique] = sprintf($this->_('Unique: Require page name “%s” to be globally unique'), $this->page->name) . $uniqueNote;
|
$statuses[Page::statusUnique] = sprintf($this->_('Unique: Require page name “%s” to be globally unique'), $this->page->name) . $uniqueNote;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3454,9 +3465,9 @@ class ProcessPageEdit extends Process implements WirePageEditor, ConfigurableMod
|
|||||||
*/
|
*/
|
||||||
public function getModuleConfigInputfields(array $data) {
|
public function getModuleConfigInputfields(array $data) {
|
||||||
|
|
||||||
$config = $this->wire()->config;
|
$config = $this->config;
|
||||||
$pages = $this->wire()->pages;
|
$pages = $this->pages;
|
||||||
$modules = $this->wire()->modules;
|
$modules = $this->modules;
|
||||||
$inputfields = new InputfieldWrapper();
|
$inputfields = new InputfieldWrapper();
|
||||||
|
|
||||||
$this->wire($inputfields);
|
$this->wire($inputfields);
|
||||||
|
Reference in New Issue
Block a user