8
8
namespace Ibexa \Core \Persistence \Legacy \Content \FieldValue \Converter ;
9
9
10
10
use DOMDocument ;
11
+ use Ibexa \Contracts \Core \Exception \InvalidArgumentException ;
11
12
use Ibexa \Contracts \Core \Persistence \Content \FieldValue ;
12
13
use Ibexa \Contracts \Core \Persistence \Content \Type \FieldDefinition ;
13
14
use Ibexa \Core \FieldType \Author \Type as AuthorType ;
@@ -106,8 +107,11 @@ public function getIndexColumn(): string
106
107
* @param array $authorValue
107
108
*
108
109
* @return string The generated XML string
110
+ *
111
+ * @throws \DOMException
112
+ * @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException
109
113
*/
110
- private function generateXmlString (array $ authorValue ): string | false
114
+ private function generateXmlString (array $ authorValue ): string
111
115
{
112
116
$ doc = new DOMDocument ('1.0 ' , 'utf-8 ' );
113
117
@@ -119,14 +123,22 @@ private function generateXmlString(array $authorValue): string|false
119
123
120
124
foreach ($ authorValue as $ author ) {
121
125
$ authorNode = $ doc ->createElement ('author ' );
122
- $ authorNode ->setAttribute ('id ' , $ author ['id ' ]);
126
+ $ authorNode ->setAttribute ('id ' , ( string ) $ author ['id ' ]);
123
127
$ authorNode ->setAttribute ('name ' , $ author ['name ' ]);
124
128
$ authorNode ->setAttribute ('email ' , $ author ['email ' ]);
125
129
$ authors ->appendChild ($ authorNode );
126
130
unset($ authorNode );
127
131
}
128
132
129
- return $ doc ->saveXML ();
133
+ $ xml = $ doc ->saveXML ();
134
+ if (false === $ xml ) {
135
+ throw new InvalidArgumentException (
136
+ '$authorValue ' ,
137
+ 'AuthorConverter: an error occurred when trying to save author field data '
138
+ );
139
+ }
140
+
141
+ return $ xml ;
130
142
}
131
143
132
144
/**
0 commit comments