You are here

README.txt in Extra Field 8.2

Same filename and directory in other branches
  1. 8 README.txt
Extra Field module
------------------
Provides two plugin types. One for extra fields in entity forms and one for
extra fields in entity views.

Developer usage
---------------
This module allows developers to add custom form elements to fieldable entities
by providing a plugin. Two plugin types are provided: ExtraFieldForm and
ExtraFieldDisplay. ExtraFieldForm elements typically provide form alters and can
be positioned in an entity form (mode) just like field widgets.
ExtraFieldDisplay elements typically combine existing entity data and format it
for display. They can be positioned in an entity view mode just like field
widgets. Unlike normal entity fields, the extra fields do not 'own' data and do
not store. But they use entity data of the entity they are applied to.

Examples
--------
The Extra Field Example module (modules/extra_field_example) contains ready to
use plugins of both Display and Form plugins. You can copy an example over to
your (custom) module and modify it to suit your needs.

Site builder usage
------------------
Once created, the extra fields can be used in form and view modes like other
fields. Extra fields are created for specific entity/entity type combinations.
That is why you find extra field plugins only in specific form or view modes,
not in all.

In the Manage form display tab of the entity for which the plugin is created,
enable and position an ExtraFieldForm element relative to other fields. In the
Manage display tab of an entity you can enable and position an ExtraFieldDisplay
element relative to other fields.

(Optionally) print the output of an ExtraFieldDisplay element in a twig
template. As any other field, the extra field is rendered in the entity's view
mode. The render array of the element is provided as extra_field_[plugin_name].
For example in a node template: {{ content.extra_field_[plugin_name] }}.

API
---
Extra fields uses hook_entity_extra_field_info() to declare fields per entity
type and bundle. Plugins can be configured (with annotation) per entity type and
per bundle.

In ExtraFieldForm plugins, the form and form state provided as parameter to
the ExtraFieldFormInterface::formElement. The method must return a renderable
form array.

In ExtraFieldDisplay plugins, the object of the entity being viewed is provided
as parameter to ExtraFieldDisplayInterface::view. The method must return a
renderable array.

As usual with plugins, an alter hook is available. See extra_field.api.php for
documentation of hook_extra_field_form_info_alter() and
hook_extra_field_display_info_alter().

Form Plugins
------------
Plugins of type "ExtraFieldForm" are used to provide Extra field forms.
Plugin examples can be found in the included extra_field_example module.

Form plugins must be placed in: [module name]/src/Plugin/ExtraField/Form.
After creating a plugin, clear the cache to make Drupal recognise it.

Form plugins must at least extend the ExtraFieldFormInterface.

ExtraFieldForm annotation should at least contain:
```
 * @ExtraFieldForm(
 *   id = "plugin_id",
 *   label = @Translation("Field name"),
 *   bundles = {
 *     "entity_type.bundle_name"
 *   }
 * )
```

To define a plugin for all bundles of a given entity type, use the '*' wildcard:
```
 *   bundles = {
 *     "entity_type.*"
 *   }
```

Other annotation options:
```
 *   weight = 10,
 *   visible = true
```

Display Plugins
---------------
Plugins of type "ExtraFieldDisplay" can be used to provide Extra field displays.
Plugin examples can be found in the included extra_field_example module.

Display plugins must be placed in: [module name]/src/Plugin/ExtraField/Display.
After creating a plugin, clear the cache to make Drupal recognize it.

Display plugins must at least extend the ExtraFieldDisplayInterface.

ExtraFieldDisplay annotation should at least contain:
```
 * @ExtraFieldDisplay(
 *   id = "plugin_id",
 *   label = @Translation("Field name"),
 *   bundles = {
 *     "entity_type.bundle_name"
 *   }
 * )
```

See Form Plugins for more annotation options.

Plugin base classes
-------------------
Different bases classes are provided each containing different tools.

ExtraFieldFormBase (form plugin)
  Provides form plugins with some helpers to get additional form rendering
	context data.

ExtraFieldDisplayBase (display plugin)
  When using this base class, all output formatting has to take place in the
  plugin. No HTML wrappers are provided around the plugin output.

ExtraFieldDisplayFormattedBase (display plugin)
  When using this base class, the field output will be wrapped with field html
  wrappers. The field template can be used to override the html output as usual.

File

README.txt
View source
  1. Extra Field module
  2. ------------------
  3. Provides two plugin types. One for extra fields in entity forms and one for
  4. extra fields in entity views.
  5. Developer usage
  6. ---------------
  7. This module allows developers to add custom form elements to fieldable entities
  8. by providing a plugin. Two plugin types are provided: ExtraFieldForm and
  9. ExtraFieldDisplay. ExtraFieldForm elements typically provide form alters and can
  10. be positioned in an entity form (mode) just like field widgets.
  11. ExtraFieldDisplay elements typically combine existing entity data and format it
  12. for display. They can be positioned in an entity view mode just like field
  13. widgets. Unlike normal entity fields, the extra fields do not 'own' data and do
  14. not store. But they use entity data of the entity they are applied to.
  15. Examples
  16. --------
  17. The Extra Field Example module (modules/extra_field_example) contains ready to
  18. use plugins of both Display and Form plugins. You can copy an example over to
  19. your (custom) module and modify it to suit your needs.
  20. Site builder usage
  21. ------------------
  22. Once created, the extra fields can be used in form and view modes like other
  23. fields. Extra fields are created for specific entity/entity type combinations.
  24. That is why you find extra field plugins only in specific form or view modes,
  25. not in all.
  26. In the Manage form display tab of the entity for which the plugin is created,
  27. enable and position an ExtraFieldForm element relative to other fields. In the
  28. Manage display tab of an entity you can enable and position an ExtraFieldDisplay
  29. element relative to other fields.
  30. (Optionally) print the output of an ExtraFieldDisplay element in a twig
  31. template. As any other field, the extra field is rendered in the entity's view
  32. mode. The render array of the element is provided as extra_field_[plugin_name].
  33. For example in a node template: {{ content.extra_field_[plugin_name] }}.
  34. API
  35. ---
  36. Extra fields uses hook_entity_extra_field_info() to declare fields per entity
  37. type and bundle. Plugins can be configured (with annotation) per entity type and
  38. per bundle.
  39. In ExtraFieldForm plugins, the form and form state provided as parameter to
  40. the ExtraFieldFormInterface::formElement. The method must return a renderable
  41. form array.
  42. In ExtraFieldDisplay plugins, the object of the entity being viewed is provided
  43. as parameter to ExtraFieldDisplayInterface::view. The method must return a
  44. renderable array.
  45. As usual with plugins, an alter hook is available. See extra_field.api.php for
  46. documentation of hook_extra_field_form_info_alter() and
  47. hook_extra_field_display_info_alter().
  48. Form Plugins
  49. ------------
  50. Plugins of type "ExtraFieldForm" are used to provide Extra field forms.
  51. Plugin examples can be found in the included extra_field_example module.
  52. Form plugins must be placed in: [module name]/src/Plugin/ExtraField/Form.
  53. After creating a plugin, clear the cache to make Drupal recognise it.
  54. Form plugins must at least extend the ExtraFieldFormInterface.
  55. ExtraFieldForm annotation should at least contain:
  56. ```
  57. * @ExtraFieldForm(
  58. * id = "plugin_id",
  59. * label = @Translation("Field name"),
  60. * bundles = {
  61. * "entity_type.bundle_name"
  62. * }
  63. * )
  64. ```
  65. To define a plugin for all bundles of a given entity type, use the '*' wildcard:
  66. ```
  67. * bundles = {
  68. * "entity_type.*"
  69. * }
  70. ```
  71. Other annotation options:
  72. ```
  73. * weight = 10,
  74. * visible = true
  75. ```
  76. Display Plugins
  77. ---------------
  78. Plugins of type "ExtraFieldDisplay" can be used to provide Extra field displays.
  79. Plugin examples can be found in the included extra_field_example module.
  80. Display plugins must be placed in: [module name]/src/Plugin/ExtraField/Display.
  81. After creating a plugin, clear the cache to make Drupal recognize it.
  82. Display plugins must at least extend the ExtraFieldDisplayInterface.
  83. ExtraFieldDisplay annotation should at least contain:
  84. ```
  85. * @ExtraFieldDisplay(
  86. * id = "plugin_id",
  87. * label = @Translation("Field name"),
  88. * bundles = {
  89. * "entity_type.bundle_name"
  90. * }
  91. * )
  92. ```
  93. See Form Plugins for more annotation options.
  94. Plugin base classes
  95. -------------------
  96. Different bases classes are provided each containing different tools.
  97. ExtraFieldFormBase (form plugin)
  98. Provides form plugins with some helpers to get additional form rendering
  99. context data.
  100. ExtraFieldDisplayBase (display plugin)
  101. When using this base class, all output formatting has to take place in the
  102. plugin. No HTML wrappers are provided around the plugin output.
  103. ExtraFieldDisplayFormattedBase (display plugin)
  104. When using this base class, the field output will be wrapped with field html
  105. wrappers. The field template can be used to override the html output as usual.