From 4e09581b39b1e0b1cbe8f139b2d9a1a462518462 Mon Sep 17 00:00:00 2001 From: Greg Roach Date: Fri, 29 Oct 2021 12:56:29 +0100 Subject: Fix: #3027 - expand/collapse subfields and show grouping during edit --- app/Contracts/ElementInterface.php | 7 +++ app/Elements/AbstractElement.php | 84 ++++++++++++++++++++---------------- app/Elements/AbstractXrefElement.php | 10 +++++ app/Elements/PlaceName.php | 10 +++++ app/Elements/TextFromSource.php | 1 - 5 files changed, 74 insertions(+), 38 deletions(-) (limited to 'app') 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 @@ -35,6 +35,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. * 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 @@ -85,6 +85,34 @@ abstract class AbstractElement implements ElementInterface return trim($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); + } + + /** + * 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. * @@ -169,7 +197,7 @@ abstract class AbstractElement implements ElementInterface */ public function editTextArea(string $id, string $name, string $value): string { - return ''; + return ''; } /** @@ -283,42 +311,6 @@ abstract class AbstractElement implements ElementInterface return []; } - /** - * 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. * @@ -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 @@ -31,6 +31,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. * 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 @@ -67,6 +67,16 @@ class PlaceName extends AbstractElement return $value; } + /** + * Should we collapse the children of this element when editing? + * + * @return bool + */ + public function collapseChildren(): bool + { + return true; + } + /** * An edit control for this data. * 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. * -- cgit v1.3