diff options
| author | Greg Roach <greg@subaqua.co.uk> | 2021-10-29 12:56:29 +0100 |
|---|---|---|
| committer | Greg Roach <greg@subaqua.co.uk> | 2021-10-29 13:21:57 +0100 |
| commit | 4e09581b39b1e0b1cbe8f139b2d9a1a462518462 (patch) | |
| tree | 08cc55030f9699ad5837defe79b0757fbf368545 /app | |
| parent | 2ebcf907ed34213f816592af04e6c160335d6311 (diff) | |
| download | webtrees-4e09581b39b1e0b1cbe8f139b2d9a1a462518462.tar.gz webtrees-4e09581b39b1e0b1cbe8f139b2d9a1a462518462.tar.bz2 webtrees-4e09581b39b1e0b1cbe8f139b2d9a1a462518462.zip | |
Fix: #3027 - expand/collapse subfields and show grouping during edit
Diffstat (limited to 'app')
| -rw-r--r-- | app/Contracts/ElementInterface.php | 7 | ||||
| -rw-r--r-- | app/Elements/AbstractElement.php | 84 | ||||
| -rw-r--r-- | app/Elements/AbstractXrefElement.php | 10 | ||||
| -rw-r--r-- | app/Elements/PlaceName.php | 10 | ||||
| -rw-r--r-- | app/Elements/TextFromSource.php | 1 |
5 files changed, 74 insertions, 38 deletions
diff --git a/app/Contracts/ElementInterface.php b/app/Contracts/ElementInterface.php index b47890d8e1..9c1e12f960 100644 --- a/app/Contracts/ElementInterface.php +++ b/app/Contracts/ElementInterface.php @@ -36,6 +36,13 @@ interface ElementInterface public function canonical(string $value): string; /** + * Should we collapse the children of this element when editing? + * + * @return bool + */ + public function collapseChildren(): bool; + + /** * Create a default value for this element. * * @param Tree $tree diff --git a/app/Elements/AbstractElement.php b/app/Elements/AbstractElement.php index 754cdada22..5a052b2f7f 100644 --- a/app/Elements/AbstractElement.php +++ b/app/Elements/AbstractElement.php @@ -86,6 +86,34 @@ abstract class AbstractElement implements ElementInterface } /** + * Convert a multi-line value to a canonical form. + * + * @param string $value + * + * @return string + */ + protected function canonicalText(string $value): string + { + // Browsers use MS-DOS line endings in multi-line data. + $value = strtr($value, ["\t" => ' ', "\r\n" => "\n", "\r" => "\n"]); + + // Remove blank lines at start/end + $value = preg_replace('/^( *\n)+/', '', $value); + + return preg_replace('/(\n *)+$/', '', $value); + } + + /** + * Should we collapse the children of this element when editing? + * + * @return bool + */ + public function collapseChildren(): bool + { + return false; + } + + /** * Create a default value for this element. * * @param Tree $tree @@ -169,7 +197,7 @@ abstract class AbstractElement implements ElementInterface */ public function editTextArea(string $id, string $name, string $value): string { - return '<textarea class="form-control" id="' . e($id) . '" name="' . e($name) . '" rows="5" dir="auto">' . e($value) . '</textarea>'; + return '<textarea class="form-control" id="' . e($id) . '" name="' . e($name) . '" rows="3" dir="auto">' . e($value) . '</textarea>'; } /** @@ -284,42 +312,6 @@ abstract class AbstractElement implements ElementInterface } /** - * Display the value of this type of element. - * - * @param string $value - * - * @return string - */ - public function valueNumeric(string $value): string - { - $canonical = $this->canonical($value); - - if (is_numeric($canonical)) { - return I18N::number((int) $canonical); - } - - return e($value); - } - - /** - * Convert a multi-line value to a canonical form. - * - * @param string $value - * - * @return string - */ - protected function canonicalText(string $value): string - { - // Browsers use MS-DOS line endings in multi-line data. - $value = strtr($value, ["\t" => ' ', "\r\n" => "\n", "\r" => "\n"]); - - // Remove blank lines at start/end - $value = preg_replace('/^( *\n)+/', '', $value); - - return preg_replace('/(\n *)+$/', '', $value); - } - - /** * Display the value of this type of element - convert URLs to links. * * @param string $value @@ -379,4 +371,22 @@ abstract class AbstractElement implements ElementInterface return e($value); } + + /** + * Display the value of this type of element. + * + * @param string $value + * + * @return string + */ + public function valueNumeric(string $value): string + { + $canonical = $this->canonical($value); + + if (is_numeric($canonical)) { + return I18N::number((int) $canonical); + } + + return e($value); + } } diff --git a/app/Elements/AbstractXrefElement.php b/app/Elements/AbstractXrefElement.php index 021cc4df6f..ccd8ae7839 100644 --- a/app/Elements/AbstractXrefElement.php +++ b/app/Elements/AbstractXrefElement.php @@ -32,6 +32,16 @@ use function preg_match; class AbstractXrefElement extends AbstractElement { /** + * Should we collapse the children of this element when editing? + * + * @return bool + */ + public function collapseChildren(): bool + { + return true; + } + + /** * Escape @ signs in a GEDCOM export. * * @param string $value diff --git a/app/Elements/PlaceName.php b/app/Elements/PlaceName.php index d1cf5867c5..692a70de78 100644 --- a/app/Elements/PlaceName.php +++ b/app/Elements/PlaceName.php @@ -68,6 +68,16 @@ class PlaceName extends AbstractElement } /** + * Should we collapse the children of this element when editing? + * + * @return bool + */ + public function collapseChildren(): bool + { + return true; + } + + /** * An edit control for this data. * * @param string $id diff --git a/app/Elements/TextFromSource.php b/app/Elements/TextFromSource.php index 0acbca6730..4e1ed9a7d9 100644 --- a/app/Elements/TextFromSource.php +++ b/app/Elements/TextFromSource.php @@ -59,7 +59,6 @@ class TextFromSource extends AbstractElement return $this->editTextArea($id, $name, $value); } - /** * Display the value of this type of element. * |
