Besides the constructor above, a schema extender really requires only one function: getFields
, which returns a list of fields to add.
24 def getFields(self): 25 return self._fields
The list of fields doesn't live within the getFields
method; it comes instead from the _fields
attribute of the class. We could have written getFields
like this...
def getFields(self): return [ _StringExtensionField('mobilePhone', required=False, searchable=True, schemata="Contact Information", widget=StringWidget( label=u"Mobile Phone", description=u"Demo field added by the MobilePhoneExtender product.", ) ) ]
...and it would have worked, but it would also have been deathly slow, as it would require the expensive construction of a _StringExtensionField
each time the schema is computed which is over 70 times for a default edit page in Plone 3.
To improve speed, we make our list of fields once and sock it away in the _fields
attribute for later:
9 _fields = [ 10 _StringExtensionField...