@@ -56,16 +56,34 @@ protected function _toHtml(): string
56
56
*/
57
57
private function createPrismicDocument (): void
58
58
{
59
- $ data = $ this ->getData ('data ' ) ?? [];
60
- if (! (isset ($ this ->contentType , $ this ->identifier ) || isset ($ data ['uid ' ]) || isset ($ data ['identifier ' ]))) {
59
+ $ contentType = $ this ->contentType ;
60
+ $ identifier = $ this ->identifier ;
61
+
62
+
63
+ // Allow using "template" to reference a document (saves XML)
64
+ $ reference = $ this ->getReference ();
65
+ if ($ reference !== '* ' ) {
66
+ $ this ->setReference ('* ' );
67
+
68
+ $ elements = explode ('. ' , $ reference );
69
+
70
+ if (count ($ elements ) > 1 ) {
71
+ [$ contentType , $ identifier ] = $ elements ;
72
+ } else {
73
+ [$ identifier ] = $ elements ;
74
+ }
75
+ }
76
+
77
+ $ data = $ this ->getData ('data ' ) ?? $ this ->getData () ?? [];
78
+ if (! ($ identifier || isset ($ data ['uid ' ]) || isset ($ data ['identifier ' ]))) {
61
79
return ;
62
80
}
63
81
64
- $ document = new stdClass () ;
82
+ $ document = new \ stdClass ;
65
83
$ options = $ this ->api ->getOptions ();
66
84
67
- $ document ->uid = $ data ['uid ' ] ?? $ data ['identifier ' ] ?? $ this -> identifier ;
68
- $ document ->type = $ data ['content_type ' ] ?? $ this -> contentType ;
85
+ $ document ->uid = $ data ['uid ' ] ?? $ data ['identifier ' ] ?? $ identifier ;
86
+ $ document ->type = $ data ['content_type ' ] ?? $ contentType ;
69
87
$ document ->lang = $ data ['lang ' ] ?? $ options ['lang ' ];
70
88
71
89
$ this ->setDocument ($ document );
0 commit comments