You are here

public static function OpignoGroupManagedContent::baseFieldDefinitions in Opigno group manager 8

Same name and namespace in other branches
  1. 3.x src/Entity/OpignoGroupManagedContent.php \Drupal\opigno_group_manager\Entity\OpignoGroupManagedContent::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/OpignoGroupManagedContent.php, line 351

Class

OpignoGroupManagedContent
Defines the Opigno Group Content 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')
    ->setCardinality(1)
    ->setSetting('target_type', 'group');
  $fields['group_content_type_id'] = BaseFieldDefinition::create('string')
    ->setLabel('Group Content Type ID')
    ->setDescription('The content type ID (should be a plugin ID)');
  $fields['entity_id'] = BaseFieldDefinition::create('integer')
    ->setLabel('Entity ID')
    ->setDescription('The entity ID');
  $fields['success_score_min'] = BaseFieldDefinition::create('integer')
    ->setLabel('Success score minimum')
    ->setDescription('The minimum score to success this content')
    ->setDefaultValue(0);
  $fields['is_mandatory'] = BaseFieldDefinition::create('boolean')
    ->setLabel('Is mandatory')
    ->setDescription('Indicate if this content is mandatory to succeed the Group')
    ->setDefaultValue(FALSE);
  $fields['coordinate_x'] = BaseFieldDefinition::create('integer')
    ->setLabel('Coordinate X')
    ->setDescription('The X coordinate in this Group manager')
    ->setDefaultValue(0);
  $fields['coordinate_y'] = BaseFieldDefinition::create('integer')
    ->setLabel('Coordinate Y')
    ->setDescription('The Y coordinate in this Group manager')
    ->setDefaultValue(0);
  $fields['in_skills_system'] = BaseFieldDefinition::create('boolean')
    ->setLabel('In the sills system')
    ->setDescription('Indicate if this module in the skills system')
    ->setDefaultValue(FALSE);
  return $fields;
}