You are here

function votingapi_reaction_entity_base_field_info in Voting API Reaction 8

Implements hook_entity_base_field_info().

File

./votingapi_reaction.module, line 35
Allows users to react to any entity using Voting and Field APIs.

Code

function votingapi_reaction_entity_base_field_info(EntityTypeInterface $entity_type) {

  // Add the field_name as a base field.
  if ($entity_type
    ->id() == 'vote') {
    return [
      'field_name' => BaseFieldDefinition::create('string')
        ->setLabel(t('Field name'))
        ->setName('field_name')
        ->setRevisionable(FALSE)
        ->setRequired(FALSE)
        ->setDescription(t('Holds the field name.'))
        ->setPropertyConstraints('value', [
        'Length' => [
          'max' => FieldStorageConfig::NAME_MAX_LENGTH,
        ],
      ]),
    ];
  }
  return NULL;
}