As an Drupal 7 developer I'm currently trying to get into Drupal 8. I got a problem finding the right plugin.

For example, I simple want to change the text of a node link "read more" into "read more >".

Leaving the templates out, I would google for Drupal 7 something like "drupal hook -what I want- alter" and found the correct hook. How can I find the correct plugin?

Especially for this case, there hook_node_links_alter(). Should I use this, or is it just for legacy and I should prefer a other way?

  • One thing that helps transition from Drupal 6 or Drupal 7 to Drupal 8 is the list of Change Records. – mradcliffe May 6 '16 at 13:00
  • Not everything in Drupal is a plugin. Generally speaking, there isn't a way to find a plugin, if you don't know at least which class is used to annotate it. – kiamlaluno May 6 '16 at 13:32
  • Should I use this, or is it just for legacy The docs are usually very good with deprecation notices. If you don't see a deprecation notice for a function, there's a good chance it hasn't been deprecated – Clive May 6 '16 at 13:43

In the specific example you make, there aren't plugins involved. The hook in invoked from NodeViewBuilder::renderLinks(), which executes the following code.

  $links = array(
    '#theme' => 'links__node',
    '#pre_render' => array('drupal_pre_render_links'),
    '#attributes' => array('class' => array('links', 'inline')),

  if (!$is_in_preview) {
    $entity = Node::load($node_entity_id)->getTranslation($langcode);
    $links['node'] = static::buildLinks($entity, $view_mode);

    // Allow other modules to alter the node links.
    $hook_context = array(
      'view_mode' => $view_mode,
      'langcode' => $langcode,
    \Drupal::moduleHandler()->alter('node_links', $links, $entity, $hook_context);
  return $links;

To know if a plugin is involved, you need to read the documentation. Plugin API in Drupal 8 give the general documentation, but then you need to read more specific documentation pages, for example Block API in Drupal 8.
A plugin could be annotated, so in some cases you can find any plugin implemented by Drupal core by looking at the classes annotated with a specific class, which is what happens with form input elements, which are classes annotated with \Drupal\Core\Render\Annotation\FormElement. The documentation page gives a list of the classes annotated with that Annotation class, so you can find any plugins of that type.

Then, as @CLive said, if you are simply wondering if you should use a hook, just look at the documentation page for that hook: If it has been deprecated, the documentation reports that, and tells you exactly what you should use: a different hook, a plugin, a specific class.
Also, as said from @mradcliffe, change records reports the changes done in Drupal, and for which version. They are helpful if you want to look at the changes that could interest the code you are writing.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.