22
33namespace R64 \NovaFields ;
44
5+ use Config ;
6+
57trait Configurable
68{
79 /**
@@ -39,6 +41,13 @@ trait Configurable
3941 */
4042 public $ panelLabelClasses = 'w-1/4 py-4 ' ;
4143
44+ /**
45+ * The base label classes for the detail view.
46+ *
47+ * @var string
48+ */
49+ public $ indexLinkClasses = 'no-underline dim text-primary font-bold ' ;
50+
4251 /**
4352 * The base excerpt classes.
4453 *
@@ -189,6 +198,19 @@ public function panelLabelClasses($classes)
189198 return $ this ;
190199 }
191200
201+ /**
202+ * Set the link classes in index view that should be applied instead of the default.
203+ *
204+ * @param string $classes
205+ * @return $this
206+ */
207+ public function indexLinkClasses ($ classes )
208+ {
209+ $ this ->indexLinkClasses = $ classes ;
210+
211+ return $ this ;
212+ }
213+
192214 /**
193215 * Add classes to the base label classes for detail view.
194216 *
@@ -264,6 +286,16 @@ public function hideFromDetail()
264286 return $ this ->withMeta (['hideFromDetail ' => true ]);
265287 }
266288
289+ /**
290+ * Specify that the index view should show as a link to the resource
291+ *
292+ * @return $this
293+ */
294+ public function showLinkInIndex ()
295+ {
296+ return $ this ->withMeta (['showLinkInIndex ' => true ]);
297+ }
298+
267299 /**
268300 * Specify that the element should be shown only on detail view.
269301 *
@@ -372,6 +404,36 @@ public function onlyWhen($field)
372404 return $ this ->withMeta (['onlyWhen ' => $ field ]);
373405 }
374406
407+ /**
408+ * Overriding the base method in order to grab the model ID.
409+ *
410+ * @param mixed $resource The resource class
411+ * @param string $attribute The attribute of the resource
412+ *
413+ * @return mixed
414+ */
415+ protected function resolveAttribute ($ resource , $ attribute )
416+ {
417+ $ this ->setResourceId (data_get ($ resource , 'id ' ));
418+ return parent ::resolveAttribute ($ resource , $ attribute );
419+ }
420+ /**
421+ * Sets the
422+ *
423+ * @param mixed $id The ID of the resource model. Also sets the base URL based on the Nova config
424+ *
425+ * @return void
426+ */
427+ protected function setResourceId ($ id )
428+ {
429+ $ path = Config::get ('nova.path ' );
430+ // If the path is the site route, prevent a double-slash
431+ if ('/ ' === $ path ) {
432+ $ path = '' ;
433+ }
434+ return $ this ->withMeta (['id ' => $ id , 'nova_path ' => $ path ]);
435+ }
436+
375437 /**
376438 * Get additional meta information to merge with the element payload.
377439 *
@@ -386,7 +448,9 @@ public function meta()
386448 'panelFieldClasses ' => $ this ->panelFieldClasses ,
387449 'labelClasses ' => $ this ->labelClasses ,
388450 'panelLabelClasses ' => $ this ->panelLabelClasses ,
451+ 'indexLinkClasses ' => $ this ->indexLinkClasses ,
389452 'excerptClasses ' => $ this ->excerptClasses ,
390453 ], $ this ->meta );
391454 }
455+
392456}
0 commit comments