Requires: xml_field_extras module.

In addition to the field instance default and schema (which are stored in the database via the Field API mechanism), this module allows for much finer-grained control of defaults and schemas, even down to the individual entity or even entity field level, e.g. $node->field_xml.

For this type of control, defaults and schemas are provided using include files in either your custom module or the public files directory. In both cases, we'll use the familiar form of suggestion filename convention found throughout Drupal.

For schema definitions use this cascade:

entity_type--entity_id--field_id.xsd
entity_type--entity_id.xsd    
entity_type--bundle_type--field_id.xsd
entity_type--bundle_type.xsd 
entity_type--field_id.xsd
entity_type.xsd
default.xsd

For field defaults use this cascade:

entity_type--entity_id--field_id.xml
entity_type--entity_id.xml    
entity_type--bundle_type--field_id.xml
entity_type--bundle_type.xml
entity_type--field_id.xml     
entity_type.xml
default.xml

Example

Create a file called paragraphs_item--field_xml_counter.xml. Notice the underscores are used not hypens in the entity type and field type portions of the filename.

Gotchas

  1. Did you enable xml_field_extras?
  2. Did you implement hook_xml_field_api()?
  3. Be sure to clear cache after adding/removing files.
  4. Did you use a double-hyphen in the filename?
  5. When editing a field instance, you will see a form field called XML Schema. This form field will disappear and become irrelevant if you add an include file that (in it's cascade) applies to said field instance. The same thing goes for the Default Value field. Another way to say this is that the file includes will override the field instance schema and default.

By Custom Module

If using a custom module you will place these files in:

my_module/includes/xml_field/

You must also implement hook_xml_field_api() in your module to let xml_field know to look in your module directory for these files. See xml_field.api.php for more info.

By User Files

You may also place include files in the public files of Drupal, however they will have the lowest weight when conflicting with a module-provided file of the same name.

public://xml_field/