mirror of
https://github.com/processwire/processwire.git
synced 2025-08-18 20:41:16 +02:00
Add a getNonEmptyValue() method to LanguagesPageFieldValue class and make use of it in ProcessPageEdit to avoid situations where headline was otherwise blank
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
/**
|
||||
* Serves as a multi-language value placeholder for field values that contain a value in more than one language.
|
||||
*
|
||||
* ProcessWire 3.x, Copyright 2016 by Ryan Cramer
|
||||
* ProcessWire 3.x, Copyright 2019 by Ryan Cramer
|
||||
* https://processwire.com
|
||||
*
|
||||
*/
|
||||
@@ -191,6 +191,32 @@ class LanguagesPageFieldValue extends Wire implements LanguagesValueInterface, \
|
||||
return $this->data[$this->defaultLanguagePageID];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get non-empty value in this order: current lang, default lang, other lang, failValue
|
||||
*
|
||||
* @param string $failValue Value to use if we cannot find a non-empty value
|
||||
* @return string
|
||||
* @since 3.0.147
|
||||
*
|
||||
*/
|
||||
public function getNonEmptyValue($failValue = '') {
|
||||
|
||||
$value = (string) $this;
|
||||
if(strlen($value)) return $value;
|
||||
|
||||
$value = (string) $this->getDefaultValue();
|
||||
if(strlen($value)) return $value;
|
||||
|
||||
foreach($this->wire('languages') as $language) {
|
||||
$value = $this->getLanguageValue($language->id);
|
||||
if(strlen($value)) break;
|
||||
}
|
||||
|
||||
if(!strlen($value)) $value = $failValue;
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* The string value is the value in the current user's language
|
||||
*
|
||||
@@ -245,7 +271,7 @@ class LanguagesPageFieldValue extends Wire implements LanguagesValueInterface, \
|
||||
*
|
||||
* Fulfills \IteratorAggregate interface.
|
||||
*
|
||||
* @return ArrayObject
|
||||
* @return \ArrayObject
|
||||
*
|
||||
*/
|
||||
public function getIterator() {
|
||||
|
@@ -2984,10 +2984,16 @@ class ProcessPageEdit extends Process implements WirePageEditor, ConfigurableMod
|
||||
public function setupHeadline() {
|
||||
|
||||
$titlePage = null;
|
||||
$page = $this->page;
|
||||
|
||||
if($this->page && $this->page->id) {
|
||||
$page = $this->page;
|
||||
if($page && $page->id) {
|
||||
$title = $page->get('title');
|
||||
if(is_object($title) && !strlen("$title") && wireInstanceOf($title, 'LanguagesPageFieldValue')) {
|
||||
/** @var LanguagesPageFieldValue $title */
|
||||
$title = $title->getNonEmptyValue($page->name);
|
||||
} else {
|
||||
$title = (string) $title;
|
||||
}
|
||||
if(empty($title)) {
|
||||
if($this->wire('pages')->names()->isUntitledPageName($page->name)) {
|
||||
$title = $page->template->getLabel();
|
||||
@@ -2995,6 +3001,7 @@ class ProcessPageEdit extends Process implements WirePageEditor, ConfigurableMod
|
||||
$title = $page->get('name');
|
||||
}
|
||||
}
|
||||
if(empty($title)) $title = $page->name;
|
||||
} else if($this->parent && $this->parent->id) {
|
||||
$titlePage = $this->parent;
|
||||
$title = rtrim($this->parent->path, '/') . '/[...]';
|
||||
@@ -3004,6 +3011,7 @@ class ProcessPageEdit extends Process implements WirePageEditor, ConfigurableMod
|
||||
}
|
||||
|
||||
$browserTitle = sprintf($this->_('Edit Page: %s'), $title);
|
||||
$headline = '';
|
||||
|
||||
if($this->field) {
|
||||
if(count($this->fields) == 1) {
|
||||
@@ -3019,10 +3027,9 @@ class ProcessPageEdit extends Process implements WirePageEditor, ConfigurableMod
|
||||
|
||||
} else if($titlePage) {
|
||||
$headline = $titlePage->get('title|name');
|
||||
|
||||
} else {
|
||||
$headline = $title;
|
||||
}
|
||||
|
||||
if(empty($headline)) $headline = $title;
|
||||
|
||||
$this->headline($headline);
|
||||
$this->browserTitle($browserTitle);
|
||||
|
Reference in New Issue
Block a user