You are here

public static function OpignoGroupManagedLink::baseFieldDefinitions in Opigno group manager 3.x

Same name and namespace in other branches
  1. 8 src/Entity/OpignoGroupManagedLink.php \Drupal\opigno_group_manager\Entity\OpignoGroupManagedLink::baseFieldDefinitions()

Provides base field definitions for an entity type.

Implementations typically use the class \Drupal\Core\Field\BaseFieldDefinition for creating the field definitions; for example a 'name' field could be defined as the following:

$fields['name'] = BaseFieldDefinition::create('string')
  ->setLabel(t('Name'));

By definition, base fields are fields that exist for every bundle. To provide definitions for fields that should only exist on some bundles, use \Drupal\Core\Entity\FieldableEntityInterface::bundleFieldDefinitions().

The definitions returned by this function can be overridden for all bundles by hook_entity_base_field_info_alter() or overridden on a per-bundle basis via 'base_field_override' configuration entities.

Parameters

\Drupal\Core\Entity\EntityTypeInterface $entity_type: The entity type definition. Useful when a single class is used for multiple, possibly dynamic entity types.

Return value

\Drupal\Core\Field\FieldDefinitionInterface[] An array of base field definitions for the entity type, keyed by field name.

Overrides ContentEntityBase::baseFieldDefinitions

See also

\Drupal\Core\Entity\EntityFieldManagerInterface::getFieldDefinitions()

\Drupal\Core\Entity\FieldableEntityInterface::bundleFieldDefinitions()

File

src/Entity/OpignoGroupManagedLink.php, line 253

Class

OpignoGroupManagedLink
Defines the Opigno Group Link entity.

Namespace

Drupal\opigno_group_manager\Entity

Code

public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
  $fields = parent::baseFieldDefinitions($entity_type);
  $fields['group_id'] = BaseFieldDefinition::create('entity_reference')
    ->setLabel('Group')
    ->setDescription('The Group entity containing this link')
    ->setCardinality(1)
    ->setSetting('target_type', 'group');
  $fields['parent_content_id'] = BaseFieldDefinition::create('entity_reference')
    ->setLabel('The parent group content')
    ->setDescription('The parent group content')
    ->setCardinality(1)
    ->setSetting('target_type', 'opigno_group_content');
  $fields['child_content_id'] = BaseFieldDefinition::create('entity_reference')
    ->setLabel('The child group content')
    ->setDescription('The child group content')
    ->setCardinality(1)
    ->setSetting('target_type', 'opigno_group_content');
  $fields['required_score'] = BaseFieldDefinition::create('integer')
    ->setLabel('Required score')
    ->setDescription('The required score to go from parent to child content');
  $fields['required_activities'] = BaseFieldDefinition::create('string')
    ->setLabel(t('Required activities'))
    ->setDescription(t('The required activities of previous step'))
    ->setSetting('max_length', 8191)
    ->setDefaultValue(0);
  return $fields;
}