Skip to main content
Drupal 8

Main navigation

  • Home
    • Question And Answer
    • NEWS
    • Projects
  • Tutorials - Drupal
    • Android
    • Other
User account menu
  • Log in

Breadcrumb

  1. Home

Custom Content Entity Field types of drupal 8

By editor , 12 November, 2016
Question

What are the Field types of content Entity on drupal 8 ?

Tags

  • Drupal 8
  • Code
  • Entity
  • Database
  • Add new comment
Create a custom Content Entity on drupal 8 (Full)
Create a custom Content Entity on drupal 8 (Basic)
Create a field in a node entity programmatically on Drupal 8.
Drupal Mysql / Database Data types

Comments9

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.

Felix (not verified)

9 years 2 months ago

entity_reference define sorting?

Great article - really useful info here that is hard to find anywhere else.

Is is possible to define the sort order of the entity_reference in the BaseFieldDefinition? 

If it's not possible in the BaseFieldDefinition then where should I define the sorting?

  • Reply

Felix (not verified)

9 years 2 months ago

In reply to entity_reference define sorting? by Felix (not verified)

default sort ordering

After some further digging this seems to be the key bit of code:

->setSetting('handler_settings', [ 'sort' => [ 'field' => 'code', 'direction' => 'ASC', ] ])

  • Reply

editor

9 years 2 months ago

Thank you

Thank you Felix

  • Reply

Erik de Kamps (not verified)

9 years 1 month ago

Great info

Keep getting back to this as a reference, great info!

Thank you.

  • Reply

Carol Pettirossi (not verified)

9 years ago

Tmestamp example

Please, add timestamp example ;)

  • Reply

Carol Pettirossi (not verified)

9 years ago

In reply to Tmestamp example by Carol Pettirossi (not verified)

$fields['timestamp'] =…

$fields['timestamp'] = BaseFieldDefinition::create('created')
  ->setLabel(new TranslatableMarkup('Created On'))
  ->setDescription(t('The time that the node was created.'))
  ->setDisplayOptions('view', [
    'weight' => -2,
    'type' => 'timestamp',
    'settings' => [
      'date_format' => 'custom',
      'custom_date_format' => 'd/m/Y H:i:s',
    ]
  ])
  ->setDisplayConfigurable('view', TRUE);

  • Reply

Vincent (not verified)

8 years 9 months ago

Medium

Thx !

Have you find how to use medium size data fields in long_string ?

  • Reply

Vincent (not verified)

8 years 9 months ago

In reply to Medium by Vincent (not verified)

Oh yeah ! Find by myself =)…

Oh yeah ! Find by myself =).

<?php

namespace Drupal\monitoring\Plugin\Field\FieldType;

use Drupal\Component\Utility\Random;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\Field\Plugin\Field\FieldType\StringItemBase;

/**
 * Defines the 'string_medium' field type.
 *
 * @FieldType(
 *   id = "string_medium",
 *   label = @Translation("Text (plain, medium)"),
 *   description = @Translation("A field containing a medium string value."),
 *   category = @Translation("Text"),
 *   default_widget = "string_textarea",
 *   default_formatter = "basic_string",
 * )
 */
class StringMediumItem extends StringItemBase {

  /**
   * {@inheritdoc}
   */
  public static function schema(FieldStorageDefinitionInterface $field_definition) {
    return [
      'columns' => [
        'value' => [
          'type' => 'text',
          'size' => 'medium',
        ],
      ],
    ];
  }

  /**
   * {@inheritdoc}
   */
  public static function generateSampleValue(FieldDefinitionInterface $field_definition) {
    $random = new Random();
    $values['value'] = $random->paragraphs();
    return $values;
  }

}

I really love D8 !

  • Reply

John (not verified)

8 years 6 months ago

How to set datetime

How to add datetime field type

 

  • Reply

Links

  • Drupal.org
  • Drupal core release cycle
  • Drupal events with ease
  • Unit test with Drupal using PHPUnit (Drupal 10)
  • Tokens for file upload url
  • Tips for Docker
  • CKEditor inline image files usage for custom forms.
  • Install Docker on Linux Mint
  • Install PHP 8.1
  • Drupal Security Best Practices
  • Order and sort items with tabledrag
  • Add a custom service YAML container
  • Apply a patch with composer