Drupal investigation

quickedit.api.php 3.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. /**
  3. * @file
  4. * Hooks provided by the Edit module.
  5. */
  6. /**
  7. * @addtogroup hooks
  8. * @{
  9. */
  10. /**
  11. * Allow modules to alter in-place editor plugin metadata.
  12. *
  13. * This hook is called after the in-place editor plugins have been discovered,
  14. * but before they are cached. Hence any alterations will be cached.
  15. *
  16. * @param array &$editors
  17. * An array of metadata on existing in-place editors, as collected by the
  18. * annotation discovery mechanism.
  19. *
  20. * @see \Drupal\quickedit\Annotation\InPlaceEditor
  21. * @see \Drupal\quickedit\Plugin\EditorManager
  22. */
  23. function hook_quickedit_editor_alter(&$editors) {
  24. // Cleanly override editor.module's in-place editor plugin.
  25. $editors['editor']['class'] = 'Drupal\advanced_editor\Plugin\quickedit\editor\AdvancedEditor';
  26. }
  27. /**
  28. * Returns a renderable array for the value of a single field in an entity.
  29. *
  30. * To integrate with in-place field editing when a non-standard render pipeline
  31. * is used (FieldItemListInterface::view() is not sufficient to render back the
  32. * field following in-place editing in the exact way it was displayed
  33. * originally), implement this hook.
  34. *
  35. * Edit module integrates with HTML elements with data-edit-field-id attributes.
  36. * For example:
  37. * data-edit-field-id="node/1/<field-name>/und/<module-name>-<custom-id>"
  38. * After the editing is complete, this hook is invoked on the module with
  39. * the custom render pipeline identifier (last part of data-edit-field-id) to
  40. * re-render the field. Use the same logic used when rendering the field for
  41. * the original display.
  42. *
  43. * The implementation should take care of invoking the prepare_view steps. It
  44. * should also respect field access permissions.
  45. *
  46. * @param \Drupal\Core\Entity\EntityInterface $entity
  47. * The entity containing the field to display.
  48. * @param string $field_name
  49. * The name of the field to display.
  50. * @param string $view_mode_id
  51. * View mode ID for the custom render pipeline this field view was destined
  52. * for. This is not a regular view mode ID for the Entity/Field API render
  53. * pipeline and is provided by the renderer module instead. An example could
  54. * be Views' render pipeline. In the example of Views, the view mode ID would
  55. * probably contain the View's ID, display and the row index. Views would
  56. * know the internal structure of this ID. The only structure imposed on this
  57. * ID is that it contains dash separated values and the first value is the
  58. * module name. Only that module's hook implementation will be invoked. Eg.
  59. * 'views-...-...'.
  60. * @param string $langcode
  61. * (Optional) The language code the field values are to be shown in.
  62. *
  63. * @return
  64. * A renderable array for the field value.
  65. *
  66. * @see \Drupal\Core\Field\FieldItemListInterface::view()
  67. */
  68. function hook_quickedit_render_field(Drupal\Core\Entity\EntityInterface $entity, $field_name, $view_mode_id, $langcode) {
  69. return [
  70. '#prefix' => '<div class="example-markup">',
  71. 'field' => $entity->getTranslation($langcode)->get($field_name)->view($view_mode_id),
  72. '#suffix' => '</div>',
  73. ];
  74. }
  75. /**
  76. * @} End of "addtogroup hooks".
  77. */