public function EntityLegalDocument::save in Entity Legal 8.2
Same name and namespace in other branches
- 4.0.x src/Entity/EntityLegalDocument.php \Drupal\entity_legal\Entity\EntityLegalDocument::save()
- 3.0.x src/Entity/EntityLegalDocument.php \Drupal\entity_legal\Entity\EntityLegalDocument::save()
Saves an entity permanently.
When saving existing entities, the entity is assumed to be complete, partial updates of entities are not supported.
Return value
int Either SAVED_NEW or SAVED_UPDATED, depending on the operation performed.
Throws
\Drupal\Core\Entity\EntityStorageException In case of failures an exception is thrown.
Overrides ConfigEntityBase::save
File
- src/
Entity/ EntityLegalDocument.php, line 296
Class
- EntityLegalDocument
- Defines the entity legal document entity.
Namespace
Drupal\entity_legal\EntityCode
public function save() {
$status = parent::save();
if ($status == SAVED_NEW) {
// Add or remove the body field, as needed.
$field = FieldConfig::loadByName('entity_legal_document_version', $this
->id(), 'entity_legal_document_text');
if (empty($field)) {
FieldConfig::create([
'field_storage' => FieldStorageConfig::loadByName('entity_legal_document_version', 'entity_legal_document_text'),
'bundle' => $this
->id(),
'label' => 'Document text',
'settings' => [
'display_summary' => FALSE,
],
])
->save();
// Assign widget settings for the 'default' form mode.
entity_get_form_display('entity_legal_document_version', $this
->id(), 'default')
->setComponent('entity_legal_document_text', [
'type' => 'text_textarea_with_summary',
])
->save();
// Assign display settings for 'default' view mode.
entity_get_display('entity_legal_document_version', $this
->id(), 'default')
->setComponent('entity_legal_document_text', [
'label' => 'hidden',
'type' => 'text_default',
])
->save();
}
}
else {
Cache::invalidateTags([
"entity_legal_document:{$this->id()}",
]);
}
return $status;
}