You are here

protected function ParagraphsType::updateFileIconUsage in Paragraphs 8

Updates the icon file usage information.

Parameters

\Drupal\file\FileInterface|mixed $new_icon: The new icon file, FALSE on deletion.

\Drupal\file\FileInterface|mixed $old_icon: (optional) Old icon, on update or deletion.

2 calls to ParagraphsType::updateFileIconUsage()
ParagraphsType::postSave in src/Entity/ParagraphsType.php
Acts on a saved entity before the insert or update hook is invoked.
ParagraphsType::restoreDefaultIcon in src/Entity/ParagraphsType.php
Restores the icon file from the default icon value.

File

src/Entity/ParagraphsType.php, line 310

Class

ParagraphsType
Defines the ParagraphsType entity.

Namespace

Drupal\paragraphs\Entity

Code

protected function updateFileIconUsage($new_icon, $old_icon = FALSE) {

  /** @var \Drupal\file\FileUsage\FileUsageInterface $file_usage */
  $file_usage = \Drupal::service('file.usage');
  if ($new_icon) {

    // Add usage of the new icon file.
    $file_usage
      ->add($new_icon, 'paragraphs', 'paragraphs_type', $this
      ->id());
  }
  if ($old_icon) {

    // Delete usage of the old icon file.
    $file_usage
      ->delete($old_icon, 'paragraphs', 'paragraphs_type', $this
      ->id());
  }
}