I want to add a field on each node which links to a particular page where module's controller will act. I want to actually add a link at bottom of node, and I want to do this programmatically. But I am not able to start, and I am very new to this.
Any ideas or suggestions to get me started? Or give me some reference in Drupal core modules or some other type of sample code to do so? I have done this till now to add the link:
function module_entity_view(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode, $langcode) {
if (TRUE) {
$entity->content['links']['module'] = array(
'#theme' => 'links__entity__module',
'#links' => $link_builder->buildLinks($entity),
);
}
}
but till now got no success. Am I using correct hook?Also I think that now the question makes sense.
hook_node_insert
to insert the link in field. Or if its a static link then just use template, orhook_node_view
.