Active
Project:
Broken Link
Version:
8.x-3.1
Component:
Code
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
26 Jul 2020 at 10:01 UTC
Updated:
26 Jul 2020 at 10:01 UTC
Jump to comment: Most recent
I want to add a base field to broken_link entity. I have written the following code.
function mymodule_entity_base_field_info(\Drupal\Core\Entity\EntityTypeInterface $entity_type) {
if ($entity_type->id() === 'broken_link') {
$fields = [];
$fields['broken_link_page_title'] = BaseFieldDefinition::create('string')
->setName('Page title')
->setLabel('Page title')
->setConstraints([
'type' => 'varchar',
'length' => 255,
])
->setDescription(t('Page title which contains broken link.'));
return $fields;
}
}
function mymodule_entity_presave(EntityInterface $entity) {
if ($entity->getEntityTypeId() == 'broken_link') {
$entity->set('broken_link_page_title', 'testing');
}
}
I can see my new field in views. But I can't see my new field in the broken link base table in database.
Also the value is not storing in the hook_entity_presave.
Is there any specific method to add a base field to this broken_link entity?
Comments