Provide an alter hook for the area links generated by the Farm UI module.
This commit is contained in:
parent
79332abad6
commit
06438909fc
|
@ -242,6 +242,28 @@ function hook_farm_ui_actions() {
|
|||
return $actions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Alter area link in area details created by Farm UI.
|
||||
*
|
||||
* @param $link
|
||||
* An array with keys for the link 'href' and 'title', which will be used
|
||||
* directly in the l() function.
|
||||
* @param $entity_info
|
||||
* Information about the entity type that the link is being built for. This
|
||||
* will contain keys:
|
||||
* - entity_type: The entity type.
|
||||
* - bundle: The entity bundle.
|
||||
* - entity_ids: An array of entity IDs that are extracted from the entity
|
||||
* View results (which may be paged, in which case you only get the
|
||||
* first page).
|
||||
*/
|
||||
function hook_farm_area_link_alter(&$link, $entity_info) {
|
||||
$link = array(
|
||||
'title' => 'New title',
|
||||
'href' => 'new-path',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
|
|
@ -115,6 +115,21 @@ function farm_ui_area_links($id, $entity_type) {
|
|||
'href' => $path,
|
||||
);
|
||||
|
||||
// Build an array of entity IDs included in the View.
|
||||
$entity_ids = array();
|
||||
foreach ($view->result as $delta => $record) {
|
||||
$entity_ids[] = $record->id;
|
||||
}
|
||||
|
||||
// Allow other modules to modify the link. Pass in some additional info
|
||||
// about the entities it represents.
|
||||
$entity_info = array(
|
||||
'entity_type' => $entity_type,
|
||||
'bundle' => $bundle,
|
||||
'entity_ids' => $entity_ids,
|
||||
);
|
||||
drupal_alter('farm_area_link', $link, $entity_info);
|
||||
|
||||
// Add the link.
|
||||
$links[] = l($link['title'], $link['href']);
|
||||
}
|
||||
|
|
|
@ -21,6 +21,9 @@ function farm_ui_hook_info() {
|
|||
$hooks['farm_ui_actions'] = array(
|
||||
'group' => 'farm_ui',
|
||||
);
|
||||
$hooks['farm_area_link_alter'] = array(
|
||||
'group' => 'farm_area',
|
||||
);
|
||||
return $hooks;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue