You are here

function opigno_module_update_8005 in Opigno module 8

Creates Badge fields for opigno_module entity.

File

./opigno_module.install, line 412
Opigno module app install/update functionality.

Code

function opigno_module_update_8005() {
  $definition_manager = \Drupal::entityDefinitionUpdateManager();
  $field = BaseFieldDefinition::create('boolean')
    ->setLabel(t('Activate badge system for this module'))
    ->setRevisionable(TRUE)
    ->setTranslatable(TRUE)
    ->setDefaultValue(FALSE)
    ->setDisplayOptions('form', [
    'type' => 'boolean_checkbox',
    'weight' => 1,
  ]);
  $definition_manager
    ->installFieldStorageDefinition('badge_active', 'opigno_module', 'opigno_module', $field);
  $field = BaseFieldDefinition::create('string')
    ->setLabel(t('Name'))
    ->setDisplayOptions('form', [
    'type' => 'string_textfield',
    'weight' => 1,
  ]);
  $definition_manager
    ->installFieldStorageDefinition('badge_name', 'opigno_module', 'opigno_module', $field);
  $field = BaseFieldDefinition::create('string_long')
    ->setLabel(t('Badge description'))
    ->setRevisionable(FALSE)
    ->setTranslatable(FALSE)
    ->setRequired(FALSE)
    ->setDefaultValue('')
    ->setDisplayOptions('form', [
    'type' => 'string_textarea',
    'weight' => 2,
    'settings' => [
      'rows' => 3,
    ],
  ]);
  $definition_manager
    ->installFieldStorageDefinition('badge_description', 'opigno_module', 'opigno_module', $field);
  $options = [
    'finished' => 'Finished',
    'success' => 'Success',
  ];
  $field = BaseFieldDefinition::create('list_string')
    ->setLabel(t('Badge criteria'))
    ->setRevisionable(TRUE)
    ->setTranslatable(TRUE)
    ->setDefaultValue('finished')
    ->setSetting('allowed_values', $options)
    ->setDisplayOptions('form', [
    'type' => 'options_buttons',
    'weight' => 3,
  ]);
  $definition_manager
    ->installFieldStorageDefinition('badge_criteria', 'opigno_module', 'opigno_module', $field);
  $field = BaseFieldDefinition::create('image')
    ->setLabel(t('Badge image'))
    ->setTranslatable(FALSE)
    ->setSettings([
    'alt_field' => FALSE,
    'alt_field_required' => FALSE,
    'file_extensions' => 'png',
  ])
    ->setDisplayOptions('form', [
    'type' => 'image',
    'weight' => 4,
  ])
    ->setDisplayConfigurable('form', TRUE);
  $definition_manager
    ->installFieldStorageDefinition('badge_image', 'opigno_module', 'opigno_module', $field);
}