You are here

README.txt in Typed Data API enhancements 8

Typed Data API Enhancements
===========================

Project site: http://www.drupal.org/project/typed_data

Code: https://www.drupal.org/project/typed_data/git-instructions

Issues: https://www.drupal.org/project/issues/typed_data

For example usage, see the Rules module: https://www.drupal.org/project/rules


Introduction
------------
The Typed Data API Enhancements module adds functionality to the core Drupal
TypedData API without altering the operation of the existing core API. These new
features are available for developers to use within modules that rely on
manipulation of typed data. Specifically, the functionality in this module was
originally part of Rules (https://www.drupal.org/project/rules), but was split
off because it can be of general use.

This module should only be installed as a dependency, if required by another
module, as it does nothing by itself.

The new features added by this module are:
 * TypedData Form Widgets
 * TypedData Tokens
 * DataFetcher Utility


TypedData Form Widgets
----------------------
This module adds a new plugin type - TypedDataFormWidget.

Each typed data datatype may have its own associated form widget, implemented
by a plugin, and used as a UI component for entering data of that type.

Similar in concept to Field Widgets, but can be used by any typed data
datatype, not just Fields.

    # Form widgets for data types
    plugin.manager.typed_data_form_widget:
      class: Drupal\typed_data\Widget\FormWidgetManager
      arguments: ['@container.namespaces', '@module_handler']


TypedData Tokens
----------------
Provided by PlaceholderResolver service to parse and replace these tokens.
Like core token service, except instead of core tokens like [node:title]
we use Twig-like tokens with typed data variables enclosed within {{ and }},
e.g. {{node.title}} Note that unlike core tokens, which must be strings, we
may use any typed data datatype inside these new tokens. Making data available
is as simple as creating a typed data datatype and does not involve implementing
hooks as core tokens do.

    # PlaceholderResolver needed to parse tokens
    typed_data.placeholder_resolver:
      class: Drupal\typed_data\PlaceholderResolver
      arguments: ['@typed_data.data_fetcher', '@plugin.manager.typed_data_filter']

As part of the PlaceholderResolver we have a new plugin type, TypedDataFilter,
which may be used to transform a typed data value in a typed data token.
For example, {{node.title|lower}} will be the lower case version of the node
title. Or, as an example non-string typed data, {{account|entity_url}} will
resolve to the canonical URL of the entity.

These TypedDataFilter plugins provide a powerful mechanism to manipulate
the typed data values. The Twig syntax makes them consistent with Drupal
front-end templates, which makes it easier for site builders to create Rules.

    # Token filters
    plugin.manager.typed_data_filter:
      class: Drupal\typed_data\DataFilterManager
      parent: default_plugin_manager


DataFetcher Utility
-------------------
Intended primarily for internal use by the TypedData API Enhancements module.

    # Retrieves data values for token replacement
    typed_data.data_fetcher:
      class: Drupal\typed_data\DataFetcher

May be useful when a hierarchical array representation of a datatype is needed.

File

README.txt
View source
  1. Typed Data API Enhancements
  2. ===========================
  3. Project site: http://www.drupal.org/project/typed_data
  4. Code: https://www.drupal.org/project/typed_data/git-instructions
  5. Issues: https://www.drupal.org/project/issues/typed_data
  6. For example usage, see the Rules module: https://www.drupal.org/project/rules
  7. Introduction
  8. ------------
  9. The Typed Data API Enhancements module adds functionality to the core Drupal
  10. TypedData API without altering the operation of the existing core API. These new
  11. features are available for developers to use within modules that rely on
  12. manipulation of typed data. Specifically, the functionality in this module was
  13. originally part of Rules (https://www.drupal.org/project/rules), but was split
  14. off because it can be of general use.
  15. This module should only be installed as a dependency, if required by another
  16. module, as it does nothing by itself.
  17. The new features added by this module are:
  18. * TypedData Form Widgets
  19. * TypedData Tokens
  20. * DataFetcher Utility
  21. TypedData Form Widgets
  22. ----------------------
  23. This module adds a new plugin type - TypedDataFormWidget.
  24. Each typed data datatype may have its own associated form widget, implemented
  25. by a plugin, and used as a UI component for entering data of that type.
  26. Similar in concept to Field Widgets, but can be used by any typed data
  27. datatype, not just Fields.
  28. # Form widgets for data types
  29. plugin.manager.typed_data_form_widget:
  30. class: Drupal\typed_data\Widget\FormWidgetManager
  31. arguments: ['@container.namespaces', '@module_handler']
  32. TypedData Tokens
  33. ----------------
  34. Provided by PlaceholderResolver service to parse and replace these tokens.
  35. Like core token service, except instead of core tokens like [node:title]
  36. we use Twig-like tokens with typed data variables enclosed within {{ and }},
  37. e.g. {{node.title}} Note that unlike core tokens, which must be strings, we
  38. may use any typed data datatype inside these new tokens. Making data available
  39. is as simple as creating a typed data datatype and does not involve implementing
  40. hooks as core tokens do.
  41. # PlaceholderResolver needed to parse tokens
  42. typed_data.placeholder_resolver:
  43. class: Drupal\typed_data\PlaceholderResolver
  44. arguments: ['@typed_data.data_fetcher', '@plugin.manager.typed_data_filter']
  45. As part of the PlaceholderResolver we have a new plugin type, TypedDataFilter,
  46. which may be used to transform a typed data value in a typed data token.
  47. For example, {{node.title|lower}} will be the lower case version of the node
  48. title. Or, as an example non-string typed data, {{account|entity_url}} will
  49. resolve to the canonical URL of the entity.
  50. These TypedDataFilter plugins provide a powerful mechanism to manipulate
  51. the typed data values. The Twig syntax makes them consistent with Drupal
  52. front-end templates, which makes it easier for site builders to create Rules.
  53. # Token filters
  54. plugin.manager.typed_data_filter:
  55. class: Drupal\typed_data\DataFilterManager
  56. parent: default_plugin_manager
  57. DataFetcher Utility
  58. -------------------
  59. Intended primarily for internal use by the TypedData API Enhancements module.
  60. # Retrieves data values for token replacement
  61. typed_data.data_fetcher:
  62. class: Drupal\typed_data\DataFetcher
  63. May be useful when a hierarchical array representation of a datatype is needed.