summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGreg Roach <greg@subaqua.co.uk>2022-10-17 11:46:23 +0100
committerGreg Roach <greg@subaqua.co.uk>2022-10-17 11:51:33 +0100
commit5aa15f0cb4850a749ed8a36424cc3c3da095c70d (patch)
tree579c5d7364b6496f9e02e95168b309ea72f8a127
parenta962cdb53edf017394834fe7a03e96e6dc3793b7 (diff)
downloadwebtrees-5aa15f0cb4850a749ed8a36424cc3c3da095c70d.tar.gz
webtrees-5aa15f0cb4850a749ed8a36424cc3c3da095c70d.tar.bz2
webtrees-5aa15f0cb4850a749ed8a36424cc3c3da095c70d.zip
Fix: #4580, Fix: #4577 - SOUR:PUBL, SOUR:TITL and SOUR:AUTH allow multi-line text
-rw-r--r--app/Elements/AbstractElement.php9
-rw-r--r--app/Elements/DescriptiveTitle.php28
-rw-r--r--app/Elements/SourceOriginator.php28
-rw-r--r--tests/app/Elements/DescriptiveTitleTest.php10
-rw-r--r--tests/app/Elements/SourceOriginatorTest.php10
5 files changed, 83 insertions, 2 deletions
diff --git a/app/Elements/AbstractElement.php b/app/Elements/AbstractElement.php
index e6f66a64ab..487f3fc806 100644
--- a/app/Elements/AbstractElement.php
+++ b/app/Elements/AbstractElement.php
@@ -322,11 +322,16 @@ abstract class AbstractElement implements ElementInterface
if (str_contains($canonical, 'http://') || str_contains($canonical, 'https://')) {
$html = Registry::markdownFactory()->autolink($canonical);
+ $html = strip_tags($html, ['a', 'br']);
+ } else {
+ $html = nl2br(e($canonical), false);
+ }
- return strip_tags($html, ['a']);
+ if (str_contains($html, '<br>')) {
+ return '<span class="ut d-inline-block">' . $html . '</span>';
}
- return e($canonical);
+ return '<span class="ut">' . $html . '</span>';
}
/**
diff --git a/app/Elements/DescriptiveTitle.php b/app/Elements/DescriptiveTitle.php
index e5fad86ea2..cfd4d40232 100644
--- a/app/Elements/DescriptiveTitle.php
+++ b/app/Elements/DescriptiveTitle.php
@@ -19,10 +19,38 @@ declare(strict_types=1);
namespace Fisharebest\Webtrees\Elements;
+use Fisharebest\Webtrees\Tree;
+
/**
* DESCRIPTIVE_TITLE := {Size=1:248}
* The title of a work, record, item, or object.
*/
class DescriptiveTitle extends AbstractElement
{
+ /**
+ * Convert a value to a canonical form.
+ *
+ * @param string $value
+ *
+ * @return string
+ */
+ public function canonical(string $value): string
+ {
+ return $this->canonicalText($value);
+ }
+
+ /**
+ * An edit control for this data.
+ *
+ * @param string $id
+ * @param string $name
+ * @param string $value
+ * @param Tree $tree
+ *
+ * @return string
+ */
+ public function edit(string $id, string $name, string $value, Tree $tree): string
+ {
+ return $this->editTextArea($id, $name, $value);
+ }
}
diff --git a/app/Elements/SourceOriginator.php b/app/Elements/SourceOriginator.php
index 58095d5098..f759c1b924 100644
--- a/app/Elements/SourceOriginator.php
+++ b/app/Elements/SourceOriginator.php
@@ -19,6 +19,8 @@ declare(strict_types=1);
namespace Fisharebest\Webtrees\Elements;
+use Fisharebest\Webtrees\Tree;
+
/**
* SOURCE_ORIGINATOR := {Size=1:248}
* The person, agency, or entity who created the record. For a published work, this could be the
@@ -27,4 +29,30 @@ namespace Fisharebest\Webtrees\Elements;
*/
class SourceOriginator extends AbstractElement
{
+ /**
+ * Convert a value to a canonical form.
+ *
+ * @param string $value
+ *
+ * @return string
+ */
+ public function canonical(string $value): string
+ {
+ return $this->canonicalText($value);
+ }
+
+ /**
+ * An edit control for this data.
+ *
+ * @param string $id
+ * @param string $name
+ * @param string $value
+ * @param Tree $tree
+ *
+ * @return string
+ */
+ public function edit(string $id, string $name, string $value, Tree $tree): string
+ {
+ return $this->editTextArea($id, $name, $value);
+ }
}
diff --git a/tests/app/Elements/DescriptiveTitleTest.php b/tests/app/Elements/DescriptiveTitleTest.php
index 15d3bef0ad..f7e25979a7 100644
--- a/tests/app/Elements/DescriptiveTitleTest.php
+++ b/tests/app/Elements/DescriptiveTitleTest.php
@@ -36,4 +36,14 @@ class DescriptiveTitleTest extends AbstractElementTest
self::$element = new DescriptiveTitle('label');
}
+
+ /**
+ * @return void
+ */
+ public function testCanonical(): void
+ {
+ self::assertSame('Foo bAr baZ', self::$element->canonical('Foo bAr baZ'));
+ self::assertSame(' Foo bAr baZ ', self::$element->canonical("\t Foo\t bAr \tbaZ\t "));
+ self::assertSame("Foo \n\n bAr \n baZ", self::$element->canonical("\nFoo \n\r bAr \r\n baZ\r"));
+ }
}
diff --git a/tests/app/Elements/SourceOriginatorTest.php b/tests/app/Elements/SourceOriginatorTest.php
index ee4c6c68dd..62a014e37a 100644
--- a/tests/app/Elements/SourceOriginatorTest.php
+++ b/tests/app/Elements/SourceOriginatorTest.php
@@ -36,4 +36,14 @@ class SourceOriginatorTest extends AbstractElementTest
self::$element = new SourceOriginator('label');
}
+
+ /**
+ * @return void
+ */
+ public function testCanonical(): void
+ {
+ self::assertSame('Foo bAr baZ', self::$element->canonical('Foo bAr baZ'));
+ self::assertSame(' Foo bAr baZ ', self::$element->canonical("\t Foo\t bAr \tbaZ\t "));
+ self::assertSame("Foo \n\n bAr \n baZ", self::$element->canonical("\nFoo \n\r bAr \r\n baZ\r"));
+ }
}