1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-17 12:10:45 +02:00

Apply solution for processwire/processwire-issues#252 - publish via page tree was showing "pub" button even when page was missing requirements. Note that this solution takes effect only upon page save in the page editor, so will not affect pages in an existing installation that may not be meeting requirements.

This commit is contained in:
Ryan Cramer
2019-02-26 09:43:08 -05:00
parent 9a75980f8d
commit 1b53ed15a9
4 changed files with 47 additions and 10 deletions

View File

@@ -184,6 +184,13 @@ class Page extends WireData implements \Countable, WireMatchable {
*/
const statusOn = 1;
/**
* Reserved status
* #pw-internal
*
*/
const statusReserved = 2;
/**
* Indicates page is locked for changes (name: "locked")
*
@@ -206,6 +213,7 @@ class Page extends WireData implements \Countable, WireMatchable {
/**
* Page has a globally unique name and no other pages may have the same name
* #pw-internal
*
*/
const statusUnique = 32;
@@ -224,8 +232,16 @@ class Page extends WireData implements \Countable, WireMatchable {
*/
const statusVersions = 128;
/**
* Page might have incomplete data because there were errors when last saved interactively or may be missing required fields
* #pw-internal
*
*/
const statusIncomplete = 256;
/**
* Page is temporary. 1+ day old unpublished pages with this status may be automatically deleted (name: "temp").
* Applies only if this status is combined with statusUnpublished.
* #pw-internal
*
*/
@@ -287,11 +303,14 @@ class Page extends WireData implements \Countable, WireMatchable {
*
*/
static protected $statuses = array(
'reserved' => self::statusReserved,
'locked' => self::statusLocked,
'systemID' => self::statusSystemID,
'system' => self::statusSystem,
'unique' => self::statusUnique,
'draft' => self::statusDraft,
'versions' => self::statusVersions,
'incomplete' => self::statusIncomplete,
'temp' => self::statusTemp,
'hidden' => self::statusHidden,
'unpublished' => self::statusUnpublished,
@@ -3712,7 +3731,7 @@ class Page extends WireData implements \Countable, WireMatchable {
* - `integer|string|array`: Status number(s) or status name(s) to set the current page status (same as $page->status = $value)
* @param int|null $status If you specified `true` for first argument, optionally specify status value you want to use (if not the current).
* @return int|array|Page If setting status, `$this` is returned. If getting status: current status or array of status names is returned.
* @see Page::addStauts(), Page::removeStatus(), Page::hasStatus()
* @see Page::addStatus(), Page::removeStatus(), Page::hasStatus()
*
*/
public function status($value = false, $status = null) {

View File

@@ -14,6 +14,7 @@
* @property string $noticeUnknown
* @property string $noticeLocked
* @property string $noticeNoAccess
* @property string $noticeIncomplete
* @property string $viewAction One of 'panel', 'modal', 'new', 'this' (see getViewActions method)
* @property bool $useBookmarks
*
@@ -349,6 +350,7 @@ class ProcessPageEdit extends Process implements WirePageEditor, ConfigurableMod
$this->set('noticeUnknown', $this->_("Unknown page")); // Init error: Unknown page
$this->set('noticeLocked', $this->_("This page is locked for edits")); // Init error: Page is locked
$this->set('noticeNoAccess', $this->_("You don't have access to edit")); // Init error: User doesn't have access
$this->set('noticeIncomplete', $this->_("This page might have one or more incomplete fields (attempt to save or publish for more info)")); // Init error: User doesn't have access
$settings = $this->config->pageEdit;
if(is_array($settings)) $this->configSettings = array_merge($this->configSettings, $settings);
@@ -539,6 +541,8 @@ class ProcessPageEdit extends Process implements WirePageEditor, ConfigurableMod
} else {
$this->error($this->noticeLocked); // Page locked error
}
} else if(!$this->isPost && $this->page->status(Page::statusIncomplete) && !$this->input->get('s')) {
$this->warning($this->noticeIncomplete);
}
return $this->renderEdit();
@@ -582,7 +586,7 @@ class ProcessPageEdit extends Process implements WirePageEditor, ConfigurableMod
$config = $this->config;
$file = $config->debug ? 'dropdown.js' : 'dropdown.min.js';
$config->scripts->add($config->urls->InputfieldSubmit . $file);
$config->scripts->add($config->urls('InputfieldSubmit') . $file);
$input = "<input type='hidden' id='after-submit-action' name='_after_submit_action' value='' />";
$out = str_replace('</form>', "$input</form>", $out);
@@ -915,7 +919,7 @@ class ProcessPageEdit extends Process implements WirePageEditor, ConfigurableMod
$submit2->attr('id', 'submit_save_unpublished');
$submit2->showInHeader();
$submit2->setSecondary();
if($this->session->clientWidth > 900) {
if($this->session->get('clientWidth') > 900) {
$submit2->attr('value', $this->_('Save + Keep Unpublished')); // Button: save unpublished
} else {
$submit2->attr('value', $saveLabel); // Button: save unpublished
@@ -1909,6 +1913,17 @@ class ProcessPageEdit extends Process implements WirePageEditor, ConfigurableMod
if($notice instanceof NoticeError) $formErrors++;
}
// if any Inputfields threw errors during processing, give the page an 'incomplete' status
// so that it can later be identified the page may be missing something
if($formErrors && count($this->form->getErrors())) {
// add incomplete status when form had errors
$this->page->addStatus(Page::statusIncomplete);
} else if($this->page->hasStatus(Page::statusIncomplete)) {
// if no errors, remove incomplete status
$this->page->removeStatus(Page::statusIncomplete);
$this->message($this->_('Removed incomplete status because no errors reported during save'));
}
$isUnpublished = $this->page->hasStatus(Page::statusUnpublished);
if($this->input->post('submit_publish') || $this->input->post('submit_save')) {

View File

@@ -125,12 +125,14 @@ class ProcessPageListActions extends Wire {
if(!$locked && !$trash && !$noSettings && $statusEditable) {
if($page->publishable()) {
if($page->isUnpublished()) {
$extras['pub'] = array(
'cn' => 'Publish',
'name' => $this->actionLabels['pub'],
'url' => "$adminUrl?action=pub&id=$page->id",
'ajax' => true,
);
if(!$page->hasStatus(Page::statusIncomplete)) {
$extras['pub'] = array(
'cn' => 'Publish',
'name' => $this->actionLabels['pub'],
'url' => "$adminUrl?action=pub&id=$page->id",
'ajax' => true,
);
}
} else if(!$page->template->noUnpublish) {
$extras['unpub'] = array(
'cn' => 'Unpublish',
@@ -282,7 +284,7 @@ class ProcessPageListActions extends Wire {
}
if($success) try {
if($needSave) $success = $page->save();
if(!$success) $message = sprintf($this->_('Error executing: %s', $message));
if(!$success) $message = sprintf($this->_('Error executing: %s'), $message);
} catch(\Exception $e) {
$success = false;
$message = $e->getMessage();

View File

@@ -81,6 +81,7 @@ class ProcessPageListRenderJSON extends ProcessPageListRender {
if($page->hasStatus(Page::statusTemp)) $icons[] = 'bolt';
if($page->hasStatus(Page::statusLocked)) $icons[] = 'lock';
if($page->hasStatus(Page::statusDraft)) $icons[] = 'paperclip';
if($page->hasStatus(Page::statusIncomplete)) $icons[] = 'exclamation-triangle';
$numChildren = $this->numChildren($page, 1);
$numTotal = strpos($this->qtyType, 'total') !== false ? $page->numDescendants : $numChildren;
}