Skip to content

Commit

Permalink
Merge pull request #11 from robertgarrigos/add-hook
Browse files Browse the repository at this point in the history
add hook to alter link
  • Loading branch information
robertgarrigos authored Jul 27, 2020
2 parents d8c11fd + 0c0d431 commit 5b214a0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
17 changes: 17 additions & 0 deletions references_dialog.api.php
Original file line number Diff line number Diff line change
Expand Up @@ -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".
*/
2 changes: 2 additions & 0 deletions references_dialog.module
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down

0 comments on commit 5b214a0

Please sign in to comment.