quickedit.api.php 3.04 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
<?php

/**
 * @file
 * Hooks provided by the Edit module.
 */

/**
 * @addtogroup hooks
 * @{
 */

/**
 * Allow modules to alter in-place editor plugin metadata.
 *
 * This hook is called after the in-place editor plugins have been discovered,
 * but before they are cached. Hence any alterations will be cached.
 *
 * @param array &$editors
20
 *   An array of metadata on existing in-place editors, as collected by the
21 22
 *   annotation discovery mechanism.
 *
23 24
 * @see \Drupal\quickedit\Annotation\InPlaceEditor
 * @see \Drupal\quickedit\Plugin\EditorManager
25
 */
26
function hook_quickedit_editor_alter(&$editors) {
27
  // Cleanly override editor.module's in-place editor plugin.
28
  $editors['editor']['class'] = 'Drupal\advanced_editor\Plugin\quickedit\editor\AdvancedEditor';
29 30
}

31 32 33 34
/**
 * Returns a renderable array for the value of a single field in an entity.
 *
 * To integrate with in-place field editing when a non-standard render pipeline
35 36 37
 * is used (FieldItemListInterface::view() is not sufficient to render back the
 * field following in-place editing in the exact way it was displayed
 * originally), implement this hook.
38
 *
39 40 41
 * Edit module integrates with HTML elements with data-edit-field-id attributes.
 * For example:
 *   data-edit-field-id="node/1/<field-name>/und/<module-name>-<custom-id>"
42
 * After the editing is complete, this hook is invoked on the module with
43
 * the custom render pipeline identifier (last part of data-edit-field-id) to
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
 * re-render the field. Use the same logic used when rendering the field for
 * the original display.
 *
 * The implementation should take care of invoking the prepare_view steps. It
 * should also respect field access permissions.
 *
 * @param \Drupal\Core\Entity\EntityInterface $entity
 *   The entity containing the field to display.
 * @param string $field_name
 *   The name of the field to display.
 * @param string $view_mode_id
 *   View mode ID for the custom render pipeline this field view was destined
 *   for. This is not a regular view mode ID for the Entity/Field API render
 *   pipeline and is provided by the renderer module instead. An example could
 *   be Views' render pipeline. In the example of Views, the view mode ID would
 *   probably contain the View's ID, display and the row index. Views would
 *   know the internal structure of this ID. The only structure imposed on this
 *   ID is that it contains dash separated values and the first value is the
 *   module name. Only that module's hook implementation will be invoked. Eg.
 *   'views-...-...'.
 * @param string $langcode
 *   (Optional) The language code the field values are to be shown in.
 *
 * @return
 *   A renderable array for the field value.
 *
70
 * @see \Drupal\Core\Field\FieldItemListInterface::view()
71
 */
72
function hook_quickedit_render_field(Drupal\Core\Entity\EntityInterface $entity, $field_name, $view_mode_id, $langcode) {
73 74
  return array(
    '#prefix' => '<div class="example-markup">',
75
    'field' => $entity->getTranslation($langcode)->get($field_name)->view($view_mode_id),
76 77 78 79
    '#suffix' => '</div>',
  );
}

80 81 82
/**
 * @} End of "addtogroup hooks".
 */