FieldTypePluginManagerInterface.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. namespace Drupal\Core\Field;
  3. use Drupal\Component\Plugin\CategorizingPluginManagerInterface;
  4. use Drupal\Component\Plugin\PluginManagerInterface;
  5. use Drupal\Core\Entity\FieldableEntityInterface;
  6. /**
  7. * Defines an interface for the field type plugin manager.
  8. *
  9. * @ingroup field_types
  10. */
  11. interface FieldTypePluginManagerInterface extends PluginManagerInterface, CategorizingPluginManagerInterface {
  12. /**
  13. * Creates a new field item list.
  14. *
  15. * The provided entity is assigned as the parent of the created item list.
  16. * However, it is the responsibility of the caller (usually the parent entity
  17. * itself) to make the parent aware of the field as a new child.
  18. *
  19. * @param \Drupal\Core\Entity\FieldableEntityInterface $entity
  20. * The entity this field item list will be part of.
  21. * @param string $field_name
  22. * The name of the field.
  23. * @param mixed $values
  24. * (optional) The data value. If set, it has to match one of the supported
  25. * data type format as documented for the data type classes.
  26. *
  27. * @return \Drupal\Core\Field\FieldItemListInterface
  28. * The instantiated object.
  29. */
  30. public function createFieldItemList(FieldableEntityInterface $entity, $field_name, $values = NULL);
  31. /**
  32. * Creates a new field item as part of a field item list.
  33. *
  34. * The provided item list is assigned as the parent of the created item. It
  35. * However, it is the responsibility of the caller (usually the parent list
  36. * itself) to have the parent aware of the item as a new child.
  37. *
  38. * @param \Drupal\Core\Field\FieldItemListInterface $items
  39. * The field item list, for which to create a new item.
  40. * @param int $index
  41. * The list index at which the item is created.
  42. * @param array|null $values
  43. * (optional) The values to assign to the field item properties.
  44. *
  45. * @return \Drupal\Core\Field\FieldItemInterface
  46. * The instantiated object.
  47. */
  48. public function createFieldItem(FieldItemListInterface $items, $index, $values = NULL);
  49. /**
  50. * Returns the default field-level settings for a field type.
  51. *
  52. * @param string $type
  53. * A field type name.
  54. *
  55. * @return array
  56. * The field's default settings, as provided by the plugin definition, or
  57. * an empty array if type or settings are undefined.
  58. */
  59. public function getDefaultFieldSettings($type);
  60. /**
  61. * Returns the default storage-level settings for a field type.
  62. *
  63. * @param string $type
  64. * A field type name.
  65. *
  66. * @return array
  67. * The type's default settings, as provided by the plugin definition, or an
  68. * empty array if type or settings are undefined.
  69. */
  70. public function getDefaultStorageSettings($type);
  71. /**
  72. * Gets the definition of all field types that can be added via UI.
  73. *
  74. * @return array
  75. * An array of field type definitions.
  76. */
  77. public function getUiDefinitions();
  78. /**
  79. * Returns preconfigured field options for a field type.
  80. *
  81. * This is a wrapper around
  82. * \Drupal\Core\Field\PreconfiguredFieldUiOptionsInterface::getPreconfiguredOptions()
  83. * allowing modules to alter the result of this method by implementing
  84. * hook_field_ui_preconfigured_options_alter().
  85. *
  86. * @param string $field_type
  87. * The field type plugin ID.
  88. *
  89. * @return array
  90. * A multi-dimensional array as returned from
  91. * \Drupal\Core\Field\PreconfiguredFieldUiOptionsInterface::getPreconfiguredOptions().
  92. *
  93. * @see \Drupal\Core\Field\PreconfiguredFieldUiOptionsInterface::getPreconfiguredOptions()
  94. * @see hook_field_ui_preconfigured_options_alter()
  95. */
  96. public function getPreconfiguredOptions($field_type);
  97. /**
  98. * Returns the PHP class that implements the field type plugin.
  99. *
  100. * @param string $type
  101. * A field type name.
  102. *
  103. * @return string
  104. * Field type plugin class name.
  105. */
  106. public function getPluginClass($type);
  107. }