O'Reilly logo

Drupal 8 Blueprints by Alex Burrows

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Annotations

In Drupal 8 and Symfony, we use annotations as metadata; these appear to look as though they are comments, but we have some keywords that allow us to tell Drupal what the plugin is and what it does:

/**  * Class DonateForm  * @package Drupal\donate\Form  *  * @Block(  *   id = "donate_block",  *   admin_label = @Translation("Donation block"),  *   category = @Translation("Custom")  * )  */
  • id: This is our plugins, unique identifier.
  • admin_label: This shows the title of the plugin.
  • category: This shows which category our plugin is in.

The annotations are straightforward, but they are required for Drupal to know about the plugin.

We now need a method of build() that will then make our block. Inside this method, we want to locate the form_id ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required