From 0c0d43197c6190a681d415c4d718fda602f816a5 Mon Sep 17 00:00:00 2001 From: robertgarrigos Date: Mon, 27 Jul 2020 19:09:54 +0200 Subject: [PATCH] add hook to alter link --- references_dialog.api.php | 17 +++++++++++++++++ references_dialog.module | 2 ++ 2 files changed, 19 insertions(+) diff --git a/references_dialog.api.php b/references_dialog.api.php index 73835c6..7977d01 100644 --- a/references_dialog.api.php +++ b/references_dialog.api.php @@ -101,6 +101,23 @@ function hook_references_dialog_search_attachables() { ); } +/** + * Allow other modules to alter the link + * + * @param $link + * The link array to be formed by l() + * @param $element + * The element to which the widget is attached + */ +function hook_references_dialog_link_alter(&$link, $element) { + if ($element['#field_name'] == 'field_source') { + // This example adds the query string to prepopulate the form + $link['query'] = [ + 'edit[field_trasnslations][und][0][nid]' => '[nid:' . $element['#entity']->nid . ']', + ]; + } +} + /** * @} End of "addtogroup hooks". */ diff --git a/references_dialog.module b/references_dialog.module index d22fbb9..961d075 100644 --- a/references_dialog.module +++ b/references_dialog.module @@ -328,6 +328,8 @@ function references_dialog_process_widget(&$element) { $links = $settings['function']($element, $widget_settings, $field, $instance); foreach ($links as $link) { $link['attributes']['class'][] = $operation . '-dialog'; + // Allow other modules to alter the link + backdrop_alter('references_dialog_link', $link, $element); $dialog_links[] = references_dialog_link($link); } }