From 8afb97d2429ad8f947c3d8eaa9c58ad46c2108b7 Mon Sep 17 00:00:00 2001 From: Cyle Carlson Date: Mon, 6 Feb 2017 15:05:08 -0600 Subject: [PATCH 01/11] Extend getThumbnail to allow for specific image filename. --- src/Entity/RealFavicon.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Entity/RealFavicon.php b/src/Entity/RealFavicon.php index a06a527..ab438fa 100644 --- a/src/Entity/RealFavicon.php +++ b/src/Entity/RealFavicon.php @@ -95,14 +95,18 @@ public function getArchive() { return unserialize(gzuncompress(stripslashes(base64_decode(strtr($data, '-_,', '+/='))))); } - public function getThumbnail() { - return $this->getDirectory() . '/favicon-16x16.png'; + /** + * Get a favicon image. + */ + public function getThumbnail($image_name = 'favicon-16x16.png') { + return $this->getDirectory() . '/' . $image_name; } /** * Return the location where Iconifys exist. * * @return [string] + * The directory path. */ protected function getDirectory() { return $this->directory . '/' . $this->id(); From 27bde8e47fe2f7ce35e21de9c8fcbcbd9e6376b7 Mon Sep 17 00:00:00 2001 From: Cyle Carlson Date: Mon, 6 Feb 2017 15:13:27 -0600 Subject: [PATCH 02/11] Provide function for returning the current real_favicon object. --- real_favicon.module | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/real_favicon.module b/real_favicon.module index d164f76..022c81b 100644 --- a/real_favicon.module +++ b/real_favicon.module @@ -28,14 +28,7 @@ function real_favicon_help($route_name, RouteMatchInterface $route_match) { * Implements hook_page_attachments_alter(). */ function real_favicon_page_attachments_alter(array &$attachments) { - $active_theme = \Drupal::theme()->getActiveTheme()->getName(); - $favicon_themes = \Drupal::config('real_favicon.settings')->get('themes'); - - if (isset($favicon_themes[$active_theme])) { - $real_favicon = RealFavicon::load($favicon_themes[$active_theme]); - if (!$real_favicon) { - return; - } + if ($real_favicon = real_favicon_load_by_theme()) { $tags = $real_favicon->getValidTagsAsString(); // Remove default favicon from html_head_link. if (!empty($attachments['#attached']['html_head_link'])) { @@ -66,3 +59,17 @@ function real_favicon_page_attachments_alter(array &$attachments) { ]; } } + +/** + * Load favicon by theme. + */ +function real_favicon_load_by_theme($active_theme = NULL) { + if (empty($active_theme)) { + $active_theme = \Drupal::theme()->getActiveTheme()->getName(); + } + $favicon_themes = \Drupal::config('real_favicon.settings')->get('themes'); + if (isset($favicon_themes[$active_theme])) { + return RealFavicon::load($favicon_themes[$active_theme]); + } + return FALSE; +} From cc654447e54fa7dca3181cdb261c994292029daa Mon Sep 17 00:00:00 2001 From: Cyle Carlson Date: Mon, 6 Feb 2017 17:04:30 -0600 Subject: [PATCH 03/11] Provide method of extracting the largest image from the manifest. --- src/Entity/RealFavicon.php | 49 +++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/src/Entity/RealFavicon.php b/src/Entity/RealFavicon.php index ab438fa..dd13d63 100644 --- a/src/Entity/RealFavicon.php +++ b/src/Entity/RealFavicon.php @@ -4,6 +4,7 @@ use Drupal\Core\Config\Entity\ConfigEntityBase; use Drupal\Core\Entity\EntityStorageInterface; +use Drupal\Component\Serialization\Json; /** * Defines the Favicon entity. @@ -54,6 +55,13 @@ class RealFavicon extends ConfigEntityBase implements RealFaviconInterface { */ protected $label; + /** + * The manifest of this package. + * + * @var array + */ + protected $manifest = []; + /** * The folder where Real Favicons exist. */ @@ -71,13 +79,52 @@ public function setTagsAsString($string) { } /** - * Set the tags from string. + * Get the tags as string. */ public function getTagsAsString() { $tags = $this->get('tags'); return $tags ? implode(PHP_EOL, $tags) : ''; } + /** + * Get the tags. + */ + public function getTags() { + return $this->get('tags'); + } + + /** + * Get the manifest. + */ + public function getManifest() { + if (empty($this->manifest)) { + $this->manifest = []; + $path = $this->getDirectory() . '/manifest.json'; + if (file_exists($path)) { + $data = file_get_contents($path); + $this->manifest = Json::decode($data); + } + } + return $this->manifest; + } + + /** + * Get the largest manifest image. + */ + public function getManifestLargeImage() { + $image = ''; + if ($manifest = $this->getManifest()) { + $size = 0; + foreach ($manifest['icons'] as $icon) { + $icon_size = explode('x', $icon['sizes']); + if ($icon_size[0] > $size) { + $image = $this->getDirectory() . $icon['src']; + } + } + } + return $image; + } + /** * Set the archive as base64 encoded string. */ From 8edb96bb6bc6b38799c3ddbe5eb2a33bfbdce467 Mon Sep 17 00:00:00 2001 From: JaceRider Date: Mon, 26 Jun 2017 09:19:49 -0500 Subject: [PATCH 04/11] Typo fix. --- src/Form/RealFaviconSettingsForm.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Form/RealFaviconSettingsForm.php b/src/Form/RealFaviconSettingsForm.php index 6c3e92d..f6b0d4f 100644 --- a/src/Form/RealFaviconSettingsForm.php +++ b/src/Form/RealFaviconSettingsForm.php @@ -36,7 +36,7 @@ public function getFormId() { } /** - * Defines the settings form for Eventbrite Event entities. + * Defines the settings form for Real Favicon entities. * * @param array $form * An associative array containing the structure of the form. From 9159d2ba65941f6c4e230818c7c3e593fcb6c320 Mon Sep 17 00:00:00 2001 From: JaceRider Date: Wed, 2 Aug 2017 13:56:11 -0500 Subject: [PATCH 05/11] Add a real favicon manager for performance reasons. --- real_favicon.module | 11 ++- real_favicon.services.yml | 5 ++ src/RealFaviconManager.php | 109 ++++++++++++++++++++++++++++ src/RealFaviconManagerInterface.php | 37 ++++++++++ 4 files changed, 159 insertions(+), 3 deletions(-) create mode 100644 real_favicon.services.yml create mode 100644 src/RealFaviconManager.php create mode 100644 src/RealFaviconManagerInterface.php diff --git a/real_favicon.module b/real_favicon.module index 022c81b..315d412 100644 --- a/real_favicon.module +++ b/real_favicon.module @@ -28,8 +28,10 @@ function real_favicon_help($route_name, RouteMatchInterface $route_match) { * Implements hook_page_attachments_alter(). */ function real_favicon_page_attachments_alter(array &$attachments) { - if ($real_favicon = real_favicon_load_by_theme()) { - $tags = $real_favicon->getValidTagsAsString(); + $theme = \Drupal::theme()->getActiveTheme()->getName(); + $realFaviconManager = \Drupal::service('real_favicon.manager'); + + if ($tags = $realFaviconManager->getTags($theme)) { // Remove default favicon from html_head_link. if (!empty($attachments['#attached']['html_head_link'])) { foreach ($attachments['#attached']['html_head_link'] as $i => $item) { @@ -53,7 +55,10 @@ function real_favicon_page_attachments_alter(array &$attachments) { [ '#type' => 'markup', '#markup' => $tags, - '#allowed_tags' => ['link', 'meta'] + '#allowed_tags' => ['link', 'meta'], + '#cache' => [ + 'tags' => $realFaviconManager->getCacheTags(), + ], ], 'real_favicon' ]; diff --git a/real_favicon.services.yml b/real_favicon.services.yml new file mode 100644 index 0000000..8ece612 --- /dev/null +++ b/real_favicon.services.yml @@ -0,0 +1,5 @@ +services: + real_favicon.manager: + class: Drupal\real_favicon\RealFaviconManager + arguments: ['@entity_type.manager', '@config.factory', '@cache.data'] + diff --git a/src/RealFaviconManager.php b/src/RealFaviconManager.php new file mode 100644 index 0000000..7b35e90 --- /dev/null +++ b/src/RealFaviconManager.php @@ -0,0 +1,109 @@ +entityTypeManager = $entity_type_manager; + $this->config = $config_factory->get('real_favicon.settings'); + $this->cache = $cache; + } + + /** + * {@inheritdoc} + */ + public function getTags($theme_id) { + $tags = NULL; + $enabled = $this->config->get('themes'); + if (!empty($enabled[$theme_id])) { + $cid = $this->cid . '.tags.' . $theme_id; + if ($cache = $this->cache->get($cid)) { + $tags = $cache->data; + } + else { + if ($favicon = $this->loadFavicon($theme_id)) { + $tags = $favicon->getValidTagsAsString(); + } + $this->cache->set($cid, $tags, Cache::PERMANENT, $this->cacheTags); + } + } + return $tags; + } + + /** + * Load a favicon. + */ + public function loadFavicon($theme_id) { + $favicon = NULL; + $enabled = $this->config->get('themes'); + if (!empty($enabled[$theme_id])) { + $favicon = $this->entityTypeManager->getStorage('real_favicon')->load($enabled[$theme_id]); + } + return $favicon; + } + + /** + * {@inheritdoc} + */ + public function getCacheTags() { + return $this->cacheTags; + } + +} diff --git a/src/RealFaviconManagerInterface.php b/src/RealFaviconManagerInterface.php new file mode 100644 index 0000000..b8972ea --- /dev/null +++ b/src/RealFaviconManagerInterface.php @@ -0,0 +1,37 @@ + Date: Wed, 2 Aug 2017 13:59:00 -0500 Subject: [PATCH 06/11] Remove unused code. --- real_favicon.module | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/real_favicon.module b/real_favicon.module index 315d412..f281329 100644 --- a/real_favicon.module +++ b/real_favicon.module @@ -64,17 +64,3 @@ function real_favicon_page_attachments_alter(array &$attachments) { ]; } } - -/** - * Load favicon by theme. - */ -function real_favicon_load_by_theme($active_theme = NULL) { - if (empty($active_theme)) { - $active_theme = \Drupal::theme()->getActiveTheme()->getName(); - } - $favicon_themes = \Drupal::config('real_favicon.settings')->get('themes'); - if (isset($favicon_themes[$active_theme])) { - return RealFavicon::load($favicon_themes[$active_theme]); - } - return FALSE; -} From 685a29723bae54b3b0aee5c3102b0b2419ccbdb9 Mon Sep 17 00:00:00 2001 From: JaceRider Date: Wed, 2 Aug 2017 14:17:41 -0500 Subject: [PATCH 07/11] Add favicon load utility function. --- real_favicon.module | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/real_favicon.module b/real_favicon.module index f281329..93299b3 100644 --- a/real_favicon.module +++ b/real_favicon.module @@ -6,7 +6,6 @@ */ use Drupal\Core\Routing\RouteMatchInterface; -use Drupal\real_favicon\Entity\RealFavicon; /** * Implements hook_help(). @@ -60,7 +59,23 @@ function real_favicon_page_attachments_alter(array &$attachments) { 'tags' => $realFaviconManager->getCacheTags(), ], ], - 'real_favicon' + 'real_favicon', ]; } } + +/** + * Load favicon by theme. + * + * @param string $theme_id + * The theme id. + * + * @return \Drupal\real_favicon\Entity\RealFavicon|null + * The real favicon entity. + */ +function real_favicon_load_by_theme($theme_id = NULL) { + if (empty($active_theme)) { + $active_theme = \Drupal::theme()->getActiveTheme()->getName(); + } + return \Drupal::service('real_favicon.manager')->loadFavicon($active_theme); +} From fbb4db4e3adc3ffc089ec633ea260702f59cbe93 Mon Sep 17 00:00:00 2001 From: JaceRider Date: Wed, 7 Mar 2018 11:42:41 -0600 Subject: [PATCH 08/11] New version of real favicon does not generate a manifest. --- src/Entity/RealFavicon.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Entity/RealFavicon.php b/src/Entity/RealFavicon.php index dd13d63..bfbd2e5 100644 --- a/src/Entity/RealFavicon.php +++ b/src/Entity/RealFavicon.php @@ -122,6 +122,10 @@ public function getManifestLargeImage() { } } } + else { + // New version of real favicon do not generate a manifest. + return $this->getDirectory() . '/apple-touch-icon.png'; + } return $image; } From 2cff64004ec19feba78e390713fdcdc6bc4c67d6 Mon Sep 17 00:00:00 2001 From: Cyle Carlson Date: Mon, 25 Jan 2021 11:27:39 -0600 Subject: [PATCH 09/11] Drupal 9 support. --- real_favicon.info.yml | 2 +- src/Entity/RealFavicon.php | 58 +++++++++++++++++++++------- src/Entity/RealFaviconInterface.php | 33 +++++++++++++++- src/Form/RealFaviconDeleteForm.php | 2 +- src/Form/RealFaviconForm.php | 53 +++++++++++++------------ src/Form/RealFaviconSettingsForm.php | 17 ++------ src/RealFaviconListBuilder.php | 5 ++- 7 files changed, 114 insertions(+), 56 deletions(-) diff --git a/real_favicon.info.yml b/real_favicon.info.yml index 8d15b91..51cf708 100644 --- a/real_favicon.info.yml +++ b/real_favicon.info.yml @@ -2,4 +2,4 @@ name: 'Real Favicon' description: 'A favicon generator for all platforms utilizing http://realfavicongenerator.net.' package: JaceRider type: module -core: 8.x +core_version_requirement: ^9 diff --git a/src/Entity/RealFavicon.php b/src/Entity/RealFavicon.php index bfbd2e5..553b6ed 100644 --- a/src/Entity/RealFavicon.php +++ b/src/Entity/RealFavicon.php @@ -5,6 +5,8 @@ use Drupal\Core\Config\Entity\ConfigEntityBase; use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Component\Serialization\Json; +use Drupal\Core\Entity\EntityMalformedException; +use Drupal\Core\File\FileSystemInterface; /** * Defines the Favicon entity. @@ -30,6 +32,12 @@ * "label" = "label", * "uuid" = "uuid" * }, + * config_export = { + * "id", + * "label", + * "tags", + * "archive", + * }, * links = { * "canonical" = "/admin/structure/real-favicon/{real_favicon}", * "add-form" = "/admin/structure/real-favicon/add", @@ -64,6 +72,8 @@ class RealFavicon extends ConfigEntityBase implements RealFaviconInterface { /** * The folder where Real Favicons exist. + * + * @var string */ protected $directory = 'public://favicon'; @@ -79,7 +89,7 @@ public function setTagsAsString($string) { } /** - * Get the tags as string. + * {@inheritDoc} */ public function getTagsAsString() { $tags = $this->get('tags'); @@ -130,10 +140,10 @@ public function getManifestLargeImage() { } /** - * Set the archive as base64 encoded string. + * {@inheritDoc} */ public function setArchive($zip_path) { - $data = strtr(base64_encode(addslashes(gzcompress(serialize(file_get_contents($zip_path)),9))), '+/=', '-_,'); + $data = strtr(base64_encode(addslashes(gzcompress(serialize(file_get_contents($zip_path)), 9))), '+/=', '-_,'); $parts = str_split($data, 200000); $this->set('archive', $parts); } @@ -156,10 +166,10 @@ public function getThumbnail($image_name = 'favicon-16x16.png') { /** * Return the location where Iconifys exist. * - * @return [string] + * @return string * The directory path. */ - protected function getDirectory() { + public function getDirectory() { return $this->directory . '/' . $this->id(); } @@ -172,6 +182,7 @@ public function preSave(EntityStorageInterface $storage) { if (!$this->isNew()) { $original = $storage->loadUnchanged($this->getOriginalId()); } + /** @var \Drupal\real_favicon\Entity\RealFaviconInterface $original */ if (is_string($this->get('tags'))) { $this->setTagsAsString($this->get('tags')); @@ -190,8 +201,11 @@ public function preSave(EntityStorageInterface $storage) { */ public static function preDelete(EntityStorageInterface $storage, array $entities) { parent::preDelete($storage, $entities); + /** @var \Drupal\Core\File\FileSystemInterface $file_system */ + $file_system = \Drupal::service('file_system'); foreach ($entities as $entity) { - file_unmanaged_delete_recursive($entity->getDirectory()); + /** @var \Drupal\real_favicon\Entity\RealFaviconInterface $entity */ + $file_system->deleteRecursive($entity->getDirectory()); // Clean up empty directory. Will fail silently if it is not empty. @rmdir($entity->directory); } @@ -210,32 +224,42 @@ protected function archiveDecode() { /** * Properly extract and store an IcoMoon zip file. * - * @param [string] $zip_path + * @param string $zip_path * The absolute path to the zip file. */ public function archiveExtract($zip_path) { - $archiver = archiver_get_archiver($zip_path); + /** @var \Drupal\Core\File\FileSystemInterface $file_system */ + $file_system = \Drupal::service('file_system'); + /** @var \Drupal\Core\Archiver\ArchiverManager $archiver_manager */ + $archiver_manager = \Drupal::service('plugin.manager.archiver'); + $archiver = $archiver_manager->getInstance(['filepath' => $zip_path]); if (!$archiver) { - throw new Exception(t('Cannot extract %file, not a valid archive.', array('%file' => $zip_path))); + throw new \Exception(t('Cannot extract %file, not a valid archive.', ['%file' => $zip_path])); } $directory = $this->getDirectory(); - file_unmanaged_delete_recursive($directory); - file_prepare_directory($directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS); + $file_system->deleteRecursive($directory); + $file_system->prepareDirectory($directory, FileSystemInterface::CREATE_DIRECTORY | FileSystemInterface::MODIFY_PERMISSIONS); $archiver->extract($directory); - drupal_set_message(t('Real Favicon package has been successfully %op.', ['%op' => ($this->isNew() ? t('updated') : t('added'))])); + \Drupal::messenger()->addMessage(t('Real Favicon package has been successfully %op.', ['%op' => ($this->isNew() ? t('updated') : t('added'))])); } + /** + * Get valid tags as strings. + */ public function getValidTagsAsString() { return implode(PHP_EOL, $this->getValidTags()) . PHP_EOL; } + /** + * Get valid tags. + */ public function getValidTags() { $base_path = base_path(); $html = $this->getTagsAsString(); - $found = array(); - $missing = array(); + $found = []; + $missing = []; $dom = new \DOMDocument(); $dom->loadHTML($html); @@ -283,6 +307,12 @@ public function getValidTags() { return $found; } + /** + * Normalize path. + * + * @return string + * The normalized path. + */ protected function normalizePath($file_path) { return file_url_transform_relative(file_create_url($this->getDirectory() . $file_path)); } diff --git a/src/Entity/RealFaviconInterface.php b/src/Entity/RealFaviconInterface.php index 86f7c8e..1bdcdd3 100644 --- a/src/Entity/RealFaviconInterface.php +++ b/src/Entity/RealFaviconInterface.php @@ -9,5 +9,36 @@ */ interface RealFaviconInterface extends ConfigEntityInterface { - // Add get/set methods for your configuration properties here. + /** + * Return the location where Iconifys exist. + * + * @return string + * The directory path. + */ + public function getDirectory(); + + /** + * Get the tags as a string. + * + * @return string + * The tags as a string. + */ + public function getTagsAsString(); + + /** + * Get a favicon image. + * + * @return string + * The favicon image. + */ + public function getThumbnail($image_name = 'favicon-16x16.png'); + + /** + * Set the archive as base64 encoded string. + * + * @param string $zip_path + * The zip path. + */ + public function setArchive($zip_path); + } diff --git a/src/Form/RealFaviconDeleteForm.php b/src/Form/RealFaviconDeleteForm.php index 7817594..20d39f2 100644 --- a/src/Form/RealFaviconDeleteForm.php +++ b/src/Form/RealFaviconDeleteForm.php @@ -38,7 +38,7 @@ public function getConfirmText() { public function submitForm(array &$form, FormStateInterface $form_state) { $this->entity->delete(); - drupal_set_message( + \Drupal::messenger()->addMessage( $this->t('content @type: deleted @label.', [ '@type' => $this->entity->bundle(), diff --git a/src/Form/RealFaviconForm.php b/src/Form/RealFaviconForm.php index 4a1f703..3fed3b1 100644 --- a/src/Form/RealFaviconForm.php +++ b/src/Form/RealFaviconForm.php @@ -2,13 +2,14 @@ namespace Drupal\real_favicon\Form; +use Drupal\Component\Utility\Environment; use Drupal\Core\Entity\EntityForm; use Drupal\Core\Form\FormStateInterface; /** - * Class RealFaviconForm. + * Class real favicon form. * - * @package Drupal\real_favicon\Form + * @package Drupal\entity\Form */ class RealFaviconForm extends EntityForm { @@ -18,50 +19,51 @@ class RealFaviconForm extends EntityForm { public function form(array $form, FormStateInterface $form_state) { $form = parent::form($form, $form_state); - $real_favicon = $this->entity; + /** @var \Drupal\entity\Entity\RealFaviconInterface $entity */ + $entity = $this->entity; $form['label'] = [ '#type' => 'textfield', '#title' => $this->t('Label'), '#maxlength' => 255, - '#default_value' => $real_favicon->label(), + '#default_value' => $entity->label(), '#description' => $this->t("Label for the Favicon."), '#required' => TRUE, ]; $form['id'] = [ '#type' => 'machine_name', - '#default_value' => $real_favicon->id(), + '#default_value' => $entity->id(), '#machine_name' => [ 'exists' => '\Drupal\real_favicon\Entity\RealFavicon::load', 'replace_pattern' => '[^a-z0-9-]+', 'replace' => '-', ], - '#disabled' => !$real_favicon->isNew(), + '#disabled' => !$entity->isNew(), ]; $form['tags'] = [ '#type' => 'textarea', '#title' => $this->t('Tags'), - '#default_value' => $real_favicon->getTagsAsString(), + '#default_value' => $entity->getTagsAsString(), '#description' => t('Paste the code provided by @url. Make sure each link is on a separate line. It is fine to paste links with paths like "/apple-touch-icon-57x57.png" as these will be converted to the correct paths automatically.', ['@url' => 'http://realfavicongenerator.net/']), '#required' => TRUE, ]; - $validators = array( - 'file_validate_extensions' => array('zip'), - 'file_validate_size' => array(file_upload_max_size()), - ); - $form['file'] = array( + $validators = [ + 'file_validate_extensions' => ['zip'], + 'file_validate_size' => [Environment::getUploadMaxSize()], + ]; + $form['file'] = [ '#type' => 'file', '#title' => t('Upload a zip file from realfavicongenerator.net to install'), - '#description' => array( + '#description' => [ '#theme' => 'file_upload_help', - '#description' => t('For example: %filename from your local computer. This only needs to be done once.', array('%filename' => 'favicons.zip')), + '#description' => t('For example: %filename from your local computer. This only needs to be done once.', ['%filename' => 'favicons.zip']), '#upload_validators' => $validators, - ), + ], '#size' => 50, '#upload_validators' => $validators, - ); + ]; return $form; } @@ -85,34 +87,35 @@ public function validateForm(array &$form, FormStateInterface $form_state) { * {@inheritdoc} */ public function save(array $form, FormStateInterface $form_state) { - $real_favicon = $this->entity; + /** @var \Drupal\entity\Entity\RealFaviconInterface $entity */ + $entity = $this->entity; if ($this->file) { try { $zip_path = $this->file->getFileUri(); - $real_favicon->setArchive($zip_path); + $entity->setArchive($zip_path); } - catch (Exception $e) { + catch (\Exception $e) { $form_state->setErrorByName('file', $e->getMessage()); return; } } - $status = $real_favicon->save(); + $status = $entity->save(); switch ($status) { case SAVED_NEW: - drupal_set_message($this->t('Created the %label Favicon.', [ - '%label' => $real_favicon->label(), + \Drupal::messenger()->addMessage($this->t('Created the %label Favicon.', [ + '%label' => $entity->label(), ])); break; default: - drupal_set_message($this->t('Saved the %label Favicon.', [ - '%label' => $real_favicon->label(), + \Drupal::messenger()->addMessage($this->t('Saved the %label Favicon.', [ + '%label' => $entity->label(), ])); } - $form_state->setRedirectUrl($real_favicon->urlInfo('collection')); + $form_state->setRedirectUrl($entity->toUrl('collection')); } } diff --git a/src/Form/RealFaviconSettingsForm.php b/src/Form/RealFaviconSettingsForm.php index f6b0d4f..6cfc802 100644 --- a/src/Form/RealFaviconSettingsForm.php +++ b/src/Form/RealFaviconSettingsForm.php @@ -5,8 +5,6 @@ use Drupal\Core\Form\ConfigFormBase; use Drupal\Core\Form\FormStateInterface; -use Drupal\real_favicon\RealFaviconSync; - /** * Class RealFaviconSettingsForm. * @@ -50,33 +48,26 @@ public function buildForm(array $form, FormStateInterface $form_state, array $fa $config = $this->config('real_favicon.settings'); $config_themes = $config->get('themes'); - $form['themes'] = array( + $form['themes'] = [ '#type' => 'details', '#title' => $this->t('Theme Favicons'), '#description' => $this->t('A favicon can be set per theme.'), '#open' => TRUE, '#tree' => TRUE, - ); + ]; foreach ($theme_options as $id => $name) { - $form['themes'][$id] = array( + $form['themes'][$id] = [ '#type' => 'select', '#title' => $this->t('%name Favicon', ['%name' => $name]), '#options' => [0 => '- Use Drupal Default -'] + $favicon_options, '#default_value' => !empty($config_themes[$id]) && isset($favicon_options[$config_themes[$id]]) ? $config_themes[$id] : 0, - ); + ]; } return parent::buildForm($form, $form_state); } - /** - * {@inheritdoc} - */ - public function validateForm(array &$form, FormStateInterface $form_state) { - parent::validateForm($form, $form_state); - } - /** * {@inheritdoc} */ diff --git a/src/RealFaviconListBuilder.php b/src/RealFaviconListBuilder.php index 7acb928..9660339 100644 --- a/src/RealFaviconListBuilder.php +++ b/src/RealFaviconListBuilder.php @@ -27,7 +27,7 @@ class RealFaviconListBuilder extends ConfigEntityListBuilder { public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) { return new static( $entity_type, - $container->get('entity.manager')->getStorage($entity_type->id()), + $container->get('entity_type.manager')->getStorage($entity_type->id()), $container->get('theme_handler') ); } @@ -39,6 +39,8 @@ public static function createInstance(ContainerInterface $container, EntityTypeI * The entity type definition. * @param \Drupal\Core\Entity\EntityStorageInterface $storage * The entity storage class. + * @param \Drupal\Core\Extension\ThemeHandlerInterface $theme_handler + * The theme handler. */ public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage, ThemeHandlerInterface $theme_handler) { $this->entityTypeId = $entity_type->id(); @@ -61,6 +63,7 @@ public function buildHeader() { * {@inheritdoc} */ public function buildRow(EntityInterface $entity) { + /** @var \Drupal\real_favicon\Entity\RealFaviconInterface $entity */ $row['image'] = [ 'data' => [ '#theme' => 'image', From 54cc82801fd8cccf77bb75de0116f8f6ccb295ee Mon Sep 17 00:00:00 2001 From: Cyle Carlson Date: Mon, 29 Mar 2021 11:26:45 -0500 Subject: [PATCH 10/11] Restore D8 support. --- real_favicon.info.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/real_favicon.info.yml b/real_favicon.info.yml index 51cf708..da88451 100644 --- a/real_favicon.info.yml +++ b/real_favicon.info.yml @@ -2,4 +2,4 @@ name: 'Real Favicon' description: 'A favicon generator for all platforms utilizing http://realfavicongenerator.net.' package: JaceRider type: module -core_version_requirement: ^9 +core_version_requirement: ^8.8 || ^9 From c836cc53ce64f15e4ceb6a0cbdae96cdc4f661dc Mon Sep 17 00:00:00 2001 From: JaceRider Date: Tue, 14 Dec 2021 14:07:42 -0600 Subject: [PATCH 11/11] Support D9 change where rel is no longer 'shortcut icon' and is just 'icon'. --- real_favicon.module | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/real_favicon.module b/real_favicon.module index 93299b3..f38f92b 100644 --- a/real_favicon.module +++ b/real_favicon.module @@ -36,7 +36,7 @@ function real_favicon_page_attachments_alter(array &$attachments) { foreach ($attachments['#attached']['html_head_link'] as $i => $item) { if (!empty($item) && is_array($item)) { foreach ($item as $ii => $iitem) { - if (isset($iitem['rel']) && $iitem['rel'] == 'shortcut icon') { + if (isset($iitem['rel']) && in_array($iitem['rel'], ['shortcut icon', 'icon'])) { unset($attachments['#attached']['html_head_link'][$i][$ii]); } }