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