File tree Expand file tree Collapse file tree 2 files changed +44
-0
lines changed Expand file tree Collapse file tree 2 files changed +44
-0
lines changed Original file line number Diff line number Diff line change 2323use App \Base \Models \Block ;
2424use Exception ;
2525use Throwable ;
26+ use App \Base \GraphQl \GraphQLExport ;
2627
2728/**
2829 * A model that will be shown on frontend
@@ -115,4 +116,22 @@ public function getContent() : string
115116 {
116117 return true ;
117118 }
119+
120+ /**
121+ * gets full frontend url for object
122+ *
123+ * @return string
124+ * @throws Exception
125+ */
126+ #[GraphQLExport]
127+ public function getAbsoluteFrontendUrl (): string
128+ {
129+ $ this ->checkLoaded ();
130+
131+ if (($ this ->getUrl () ?? $ this ->getUrlKey ()) === null ) {
132+ return "" ;
133+ }
134+
135+ return $ this ->getWebsite ()->getUrl () . $ this ->getFrontendUrl ();
136+ }
118137}
Original file line number Diff line number Diff line change @@ -83,4 +83,29 @@ public function postPersist(array $persistOptions = []): BaseModel
8383
8484 return parent ::postPersist ($ persistOptions );
8585 }
86+
87+ /**
88+ * Returns website URL
89+ *
90+ * @return string
91+ */
92+ #[GraphQLExport()]
93+ public function getUrl () : string
94+ {
95+ $ parsed = parse_url (
96+ sprintf (
97+ "%s://%s%s%s " ,
98+ (isset ($ _SERVER ['HTTPS ' ]) && $ _SERVER ['HTTPS ' ] != 'off ' ) ? 'https ' : 'http ' ,
99+ (is_numeric ($ _SERVER ['SERVER_PORT ' ]) && $ _SERVER ['SERVER_PORT ' ] != 80 && $ _SERVER ['SERVER_PORT ' ] != 443 ) ? ': ' . $ _SERVER ['SERVER_PORT ' ] : '' ,
100+ $ this ->getDomain (),
101+ '/ '
102+ )
103+ );
104+
105+ if ($ parsed ) {
106+ return $ parsed ['scheme ' ] . ':// ' . $ parsed ['host ' ];
107+ }
108+
109+ return 'https:// ' .$ this ->getDomain ();
110+ }
86111}
You can’t perform that action at this time.
0 commit comments