type_id; } /** * {@inheritdoc} */ public function getTypeLabel() { if ($definition = $this->embedTypeManager()->getDefinition($this->getTypeId(), FALSE)) { return $definition['label']; } else { return $this->t('Unknown'); } } /** * {@inheritdoc} */ public function getTypePlugin() { if ($plugin_id = $this->getTypeId()) { return $this->embedTypeManager()->createInstance($plugin_id, $this->getTypeSettings()); } } /** * {@inheritdoc} */ public function getIconFile() { if ($this->icon_uuid) { return $this->entityManager()->loadEntityByUuid('file', $this->icon_uuid); } } /** * {@inheritdoc} */ public function getIconUrl() { if ($image = $this->getIconFile()) { return file_create_url($image->getFileUri()); } else { return $this->getTypePlugin()->getDefaultIconUrl(); } } /** * {@inheritdoc} */ public function calculateDependencies() { parent::calculateDependencies(); // Add the file icon entity as dependency if an UUID was specified. if ($this->icon_uuid && $file_icon = $this->entityManager()->loadEntityByUuid('file', $this->icon_uuid)) { $this->addDependency($file_icon->getConfigDependencyKey(), $file_icon->getConfigDependencyName()); } // Gather the dependencies of the embed type plugin. $plugin = $this->getTypePlugin(); $this->calculatePluginDependencies($plugin); return $this->dependencies; } /** * Gets the embed type plugin manager. * * @return \Drupal\embed\EmbedType\EmbedTypeManager * The embed type plugin manager. */ protected function embedTypeManager() { return \Drupal::service('plugin.manager.embed.type'); } /** * Gets the file usage service. * * @return \Drupal\file\FileUsage\FileUsageInterface * The file usage service. */ protected function fileUsage() { return \Drupal::service('file.usage'); } /** * {@inheritdoc} */ public function postSave(EntityStorageInterface $storage, $update = TRUE) { parent::postSave($storage, $update); $icon_file = $this->getIconFile(); if (isset($this->original) && $old_icon_file = $this->original->getIconFile()) { /** @var \Drupal\file\FileInterface $old_icon_file */ if (!$icon_file || $icon_file->uuid() != $old_icon_file->uuid()) { $this->fileUsage()->delete($old_icon_file, 'embed', $this->getEntityTypeId(), $this->id()); } } if ($icon_file) { $usage = $this->fileUsage()->listUsage($icon_file); if (empty($usage['embed'][$this->getEntityTypeId()][$this->id()])) { $this->fileUsage()->add($icon_file, 'embed', $this->getEntityTypeId(), $this->id()); } } } /** * {@inheritdoc} */ public static function postDelete(EntityStorageInterface $storage, array $entities) { parent::postDelete($storage, $entities); // Remove file usage for any button icons. foreach ($entities as $entity) { /** @var \Drupal\embed\EmbedButtonInterface $entity */ if ($icon_file = $entity->getIconFile()) { \Drupal::service('file.usage')->delete($icon_file, 'embed', $entity->getEntityTypeId(), $entity->id()); } } } /** * {@inheritdoc} */ public function getTypeSetting($key, $default = NULL) { if (isset($this->type_settings[$key])) { return $this->type_settings[$key]; } else { return $default; } } /** * {@inheritdoc} */ public function getTypeSettings() { return $this->type_settings; } }