EntityUpdateTestsContentEntity.php in Entity Update 8
File
modules/entity_update_tests/src/Entity/EntityUpdateTestsContentEntity.php
View source
<?php
namespace Drupal\entity_update_tests\Entity;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\Core\Entity\ContentEntityBase;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\entity_update_tests\EntityUpdateTestHelper;
class EntityUpdateTestsContentEntity extends ContentEntityBase {
public static function getConfigurableFields($mode = NULL) {
$list = [];
if ($mode == 'install' || !$mode) {
$list['name'] = 'Name';
$list['description'] = 'Description';
}
if ($mode == 'type' || !$mode) {
$list['type'] = 'Type';
}
return $list;
}
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
$fields = parent::baseFieldDefinitions($entity_type);
$fields['fix'] = BaseFieldDefinition::create('string')
->setLabel(t('Fix field.'))
->setSettings([
'max_length' => 10,
'text_processing' => 0,
]);
if (EntityUpdateTestHelper::fieldStatus('name')) {
$fields['name'] = BaseFieldDefinition::create('string')
->setLabel(t('Name'))
->setSettings([
'max_length' => 100,
'text_processing' => 0,
]);
}
if (EntityUpdateTestHelper::fieldStatus('description')) {
$fields['description'] = BaseFieldDefinition::create('string_long')
->setLabel(t('Description'))
->setSettings([
'text_processing' => 0,
]);
}
$type = EntityUpdateTestHelper::fieldStatus('type');
$types = [
'string',
'integer',
];
if (in_array($type, $types)) {
$fields['type'] = BaseFieldDefinition::create($type)
->setLabel(t('Type'))
->setSettings([
'max_length' => 10,
'text_processing' => 0,
]);
}
return $fields;
}
}