You are here

function fontscom_api_entity_presave in @font-your-face 8.3

Implements hook_entity_presave().

File

modules/fontscom_api/fontscom_api.module, line 48
Fonts.com API module file.

Code

function fontscom_api_entity_presave(EntityInterface $entity) {
  if ($entity instanceof Font) {
    if ($entity->pid->value == 'fontscom_api' && $entity
      ->isActivated()) {
      $metadata = $entity
        ->getMetadata();
      $config = \Drupal::config('fontscom_api.settings');
      $enabled_fonts = fontscom_api_get_all_enabled_fonts();
      if (isset($enabled_fonts[$metadata['FontID']])) {

        // Do nothing.
      }
      else {
        fontscom_api_add_font_to_current_project($metadata['FontID']);
      }
    }
    elseif ($entity->pid->value == 'fontscom_api' && $entity
      ->isDeactivated()) {
      if (!empty($entity->original)) {
        $original_entity = $entity->original;
        if ($original_entity->status->value != $entity->status->value) {
          $metadata = $entity
            ->getMetadata();
          $config = \Drupal::config('fontscom_api.settings');
          $enabled_fonts = fontscom_api_get_all_enabled_fonts();
          if (isset($enabled_fonts[$metadata['FontID']])) {
            fontscom_api_remove_font_from_current_project($metadata['FontID']);
          }
        }
      }
    }
  }
}