Search

This is a question to all programmers: Is there a way to extend a field class via an extension? Something like:

Class fieldAdvancedselect extends fieldSelect {

    function displaySettingsPanel(&$wrapper, $errors=NULL) {        

        parent::displaySettingsPanel($wrapper, $errors);

        // do something here

    }

I can't find a way to get this work ...
My goal is to enhance a field without the need to replace the original one in the sections. But as I like to do some fancy stuff that involves the database javascript isn't a solution for me.

Yeah, two of my field extensions do it. Check out Reference Link and Enhanced Taglist

Hm, I'm not sure if this is what I'm looking for: I see that your fields extend other field classes but if I use one of the two I have to a add a new field (either Reference Link or Enhanced Taglist) to my section? Don't I?

This is what I'm looking for: I have a section using some of the build-in fields, e. g. a select box. I now like to have an extension that - after enabling it - adds more options to the existing fields in my section. So I do not have to add a new field and everything continues to work after disabling the extension again.

An example: I'm trying to build an extension to enhance select boxes with javascript, but I'd like to give the user a choice which select box fields should be transformed and which kind of layout should be used. So I like to add a few options to the settings of the build-in select box that are saved to the database based on which the javascript added to the section's publish area reacts. If the user doesn't need this extra functionality he should be able to uninstall the extension without loosing the data of the select boxes and without the need to change anything in the section settings.

I've been researching a bit and maybe I'm making an error in reasoning and class extending sounds like what I'd like do but isn't in fact. So I'd like to adjust my initial question:

I'm looking for a way to add functions to or override functions in an existing field class. I don't want to create a new class that can be used as new field besides the original one. I'd like to enhance all existing and all new fields of the original class.

Any ideas? PHP voodoo or object oriented magic? Symphony delegates?

Actually, that's precisely what I'd wanted to do with both of the above extensions since, in essence, they simply add a bit of functionality to already-existing fields. Aside from the question of whether it's possible to override the existing class, though, which I don't know, I was advised against doing it anyway. In particular I was advised against trying to use a field's existing DB table.

In particular I was advised against trying to use a field's existing DB table.

Interesting! Do you remember the reasons?

"Extending a field is a good idea (except that it creates a dependency on another Extension), but I wouldn't recommend using the same DB table. If the data is that similar, then migration shouldn't be very hard right? I just don't think you'll really save anything by doing it that way."

Hm, I see - I do not agree with it, but I understand the argumentation.

"If the data is that similar, then migration shouldn't be very hard right?"

I think this is where I disagree, as this statement only applies to skilled users. It's not possible for an extension developer to do this automatically because you don't know which fields should be replaced (all, just one, a few?). As a consequence you need to give the user a choice: Where do you do this? And what happens if you uninstall the extension? Does it delete all the data or does it try to revert data from your own field to its origin?

A main problem in switching fields lies in the point of time: If you are still building a site it doesn't matter if you have to transfer data from one field to another. If you like to enhance a live site, it becomes quite problematic: a manual transfer of thousands of entries seems inappropriate and any automatic system bears the risk of loosing data. In regard of usability, having to migrate data from one field to the other just to get a small extra feature seems to be quite an overhaul to me. Not forgetting the risk of loosing data because at some point you have to delete the original field. What if the user deletes the original field first and then creates the new one? Just a small mistake with the consequence of loosing all entered data.

Actually, that's precisely what I'd wanted to do with both of the above extensions since, in essence, they simply add a bit of functionality to already-existing fields.

That's exactly my point: it's all about enhancements, not about fundamental changes or additions. I think there needs to be a way to enhance a field (with more than just javascript [1]) in a way you can easily opt-in or opt-out. If I decide to remove an "enhancement extension" as it didn't really work in real life, this should be as simple as deactivating the extension.

Was it Alistair you have been discussing this problem with?


[1] Just thinking of adding one option in the section settings pane (Enhance field: yes/no) to manage javascript additions.

Well, yes, both Alistair and Rowan advised that it wouldn't be a good idea to alter the existing DB table.

As an addition a small definition:

Enhancement

The original field and the field extension are working with the same data basis. The inner concepts are the same. If the extension is deactivated the original field still works, no data is lost - the user just misses a few enchanting things the extension was offering.

Replacement

The original field and the field extension are trying to achieve similar things but are using different concepts - as a consequence the data basis may be different. The original field could not work with the data saved by the extension.

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details