@@ -10,7 +10,7 @@ class Generic extends Fieldtype
1010{
1111 private $ handler = null ;
1212
13- public function __construct ($ name , $ id = null )
13+ public function __construct (string $ name , $ id = null )
1414 {
1515 $ this ->name = $ name ;
1616 $ this ->id = $ id ;
@@ -34,19 +34,23 @@ public function getHandler()
3434 return $ this ->handler ;
3535 }
3636
37- public function apply (FieldContent $ content , $ parameters = [])
37+ public function apply (FieldContent $ content , array $ parameters = [])
3838 {
3939 $ handler = $ this ->getHandler ();
4040
4141 $ data = $ content ->getAttribute ('data ' );
42- $ processed = $ handler ->replace_tag ($ data , $ parameters );
4342
44- return FieldtypeOutput::make ($ processed );
43+ $ output = \Expressionengine \Coilpack \Facades \Coilpack::isolateTemplateLibrary (function ($ template ) use ($ handler , $ data , $ parameters ) {
44+ $ output = $ handler ->replace_tag ($ data , $ parameters );
45+ // If the Fieldtype stored data for us in the template library that is preferable to the generated output
46+ return $ template ->get_data () ?: $ output ;
47+ });
48+
49+ return FieldtypeOutput::make ($ output );
4550 }
4651
4752 public function modifiers ()
4853 {
49- // return [];
5054 // @todo Cache this statically
5155 return collect (get_class_methods ($ this ->getHandler ()))->flatMap (function ($ method ) {
5256 if (Str::startsWith ($ method , 'replace_ ' ) && $ method !== 'replace_tag ' ) {
0 commit comments