public function ParagraphsSet::postSave in Paragraphs Sets 8.2
Acts on a saved entity before the insert or update hook is invoked.
Used after the entity is saved, but before invoking the insert or update hook. Note that in case of translatable content entities this callback is only fired on their current translation. It is up to the developer to iterate over all translations if needed.
Parameters
\Drupal\Core\Entity\EntityStorageInterface $storage: The entity storage object.
bool $update: TRUE if the entity has been updated, or FALSE if it has been inserted.
Overrides EntityBase::postSave
File
- src/
Entity/ ParagraphsSet.php, line 140
Class
- ParagraphsSet
- Defines the ParagraphsSet entity.
Namespace
Drupal\paragraphs_sets\EntityCode
public function postSave(EntityStorageInterface $storage, $update = TRUE) {
// Update the file usage for the icon files.
if (!$update || $this->icon_uuid != $this->original->icon_uuid) {
// The icon has changed. Update file usage.
/** @var \Drupal\file\FileUsage\FileUsageInterface $file_usage */
$file_usage = \Drupal::service('file.usage');
// Add usage of the new icon file, if it exists. It might not exist, if
// this Paragraphs type was imported as configuration, or if the icon has
// just been removed.
if ($this->icon_uuid && ($new_icon = $this
->getFileByUuid($this->icon_uuid))) {
$file_usage
->add($new_icon, 'paragraphs_sets', 'paragraphs_set', $this
->id());
}
if ($update) {
// Delete usage of the old icon file, if it exists.
if ($this->original->icon_uuid && ($old_icon = $this
->getFileByUuid($this->original->icon_uuid))) {
$file_usage
->delete($old_icon, 'paragraphs_sets', 'paragraphs_set', $this
->id());
}
}
}
parent::postSave($storage, $update);
}