You are here

public static function LPManagedContent::baseFieldDefinitions in Opigno Learning path 8

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

Class

LPManagedContent
Defines the Learning Path Content entity.

Namespace

Drupal\opigno_learning_path\Entity

Code

public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
  $fields = parent::baseFieldDefinitions($entity_type);
  $fields['learning_path_id'] = BaseFieldDefinition::create('entity_reference')
    ->setLabel('Learning Path')
    ->setCardinality(1)
    ->setSetting('target_type', 'group')
    ->setSetting('handler_settings', [
    'target_bundles' => [
      'learning_path' => 'learning_path',
    ],
  ]);
  $fields['lp_content_type_id'] = BaseFieldDefinition::create('string')
    ->setLabel('Learning Path 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 learning path')
    ->setDefaultValue(FALSE);
  $fields['coordinate_x'] = BaseFieldDefinition::create('integer')
    ->setLabel('Coordinate X')
    ->setDescription('The X coordinate in this learning path manager')
    ->setDefaultValue(0);
  $fields['coordinate_y'] = BaseFieldDefinition::create('integer')
    ->setLabel('Coordinate Y')
    ->setDescription('The Y coordinate in this learning path manager')
    ->setDefaultValue(0);
  return $fields;
}