Creating a custom FieldType (D8) I'm trying to create a custom FieldType which provides the fields for a complete address (street, house_number, post_code and city).

I created a FieldWidget, FieldFormatter and FieldType class and a "field"-template. (followed the guide at http://www.computerminds.co.uk/drupal-code/drupal-8-creating-custom-field-part-1-field-type and "seeing" Drupal core FieldTypes)

The widget does not get rendered unless I add an element_info()-Hook and a address_preprocess-Hook where I have to define the same stuff like in the FildWidget::formElement() method. But this is the Drupal7 way. Am I missing something?

FieldWidget class

public function formElement(FieldItemListInterface $items, $delta, array $element, array &amp;$form, FormStateInterface $form_state)
{
  $element             = $element + array(
    'street'    =&gt; array(
      '#title'            =&gt; $this-&gt;t('Street'),
      '#type'             =&gt; 'textfield',
      '#default_value'    =&gt; isset($items[$delta]-&gt;street) ? $items[$delta]-&gt;street : null,
      '#required'         =&gt; false,

    ),
    'street_nr' =&gt; array(
      ...
    ),
    'zip'       =&gt; array(
      ...
    ),
    'city'      =&gt; array(
      ...
    ),
  );
  $form['#validate'][] = array($this, 'validateCompleteAddress');

  return $element;
}


FieldFormater class

public function viewElements(FieldItemListInterface $items)
{
  $elements = array();

  $elements['addresses'] = array(
    '#type' =&gt; 'fieldset',
    '#tree' =&gt; true,
  );

  foreach ($items as $delta =&gt; $item)
  {
    $elements['addresses'][$delta] = array(
      '#theme'     =&gt; 'fields_address',
      'elements' =&gt; $item,

      //'street'    =&gt; String::checkPlain($item-&gt;street),
      //'street_nr' =&gt; String::checkPlain($item-&gt;street_nr),
      //'zip'       =&gt; String::checkPlain($item-&gt;zip),
      //'city'      =&gt; String::checkPlain($item-&gt;city),
    );
  }


FieldType class

public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition)
{
  $properties = array(
    'street' =&gt; DataDefinition::create('string')-&gt;setLabel(t('Street'))-&gt;addConstraint('Length', array('max' =&gt; 255)),
    'street_nr' =&gt; DataDefinition::create('string')-&gt;setLabel(t('Street number'))-&gt;addConstraint('Length', array('max' =&gt; 100)),
    'zip' =&gt; DataDefinition::create('string')-&gt;setLabel(t('Zip'))-&gt;addConstraint('Length', array('max' =&gt; 5)),
    'city' =&gt; DataDefinition::create('string')-&gt;setLabel(t('City'))-&gt;addConstraint('Length', array('max' =&gt; 255)),
  );

  return $properties;
}

public static function schema(FieldStorageDefinitionInterface $field_definition)
{
  return array(
    'columns' =&gt; array(
      'street'    =&gt; array(
        ...
      ),
      'street_nr' =&gt; array(
        ...
      ),
      'zip'       =&gt; array(
        ...
      ),
      'city'      =&gt; array(
        ...
    ),

  ),
  'indexes' =&gt; array(),
  'foreign keys' =&gt; array(),
);


}
It seems like I have to provide a custom Element class in the module\Element folder to define the custom input elements for the form rendering.

See \Drupal\Core\Render\Element\Textfield.