How to do it...

  1. We will need to create the src/Plugin/Field/FieldType directory in the module's base location. The Field module discovers field types in the Plugin\Field\FieldType namespace.
  2. We will create a RealName.php file in the newly created directory so that we can define the RealName class. This will provide our realname field for the first and last names:
  1. The RealName class will extend the \Drupal\Core\Field\FieldItemBase class:
<?php namespace Drupal\mymodule\Plugin\Field\FieldType; use Drupal\Core\Field\FieldItemBase; use Drupal\Core\Field\FieldStorageDefinitionInterface; use Drupal\Core\TypedData\DataDefinition; class RealName ...

Get Drupal 8 Development Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.