Skip to content

Commit

Permalink
Merge branch 'favicon-setting' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
zerocrates committed Dec 15, 2023
2 parents 94d120f + 02a5a69 commit e91bc65
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
26 changes: 26 additions & 0 deletions application/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,32 @@ public function attachListeners(SharedEventManagerInterface $sharedEventManager)
[$this, 'noindexItemSet']
);

// Add favicon to layouts.
$sharedEventManager->attach(
'*',
'view.layout',
function (ZendEvent $event) {
$view = $event->getTarget();
// Get the favicon asset ID.
if ($view->status()->isSiteRequest()) {
$faviconAssetId = $view->siteSetting('favicon');
if (!is_numeric($faviconAssetId)) {
$faviconAssetId = $view->setting('favicon');
}
} else {
$faviconAssetId = $view->setting('favicon');
}
// Get the favicon href.
if (is_numeric($faviconAssetId)) {
$faviconAsset = $view->api()->searchOne('assets', ['id' => $faviconAssetId])->getContent();
$href = $faviconAsset ? $faviconAsset->assetUrl() : null;
} else {
$href = null; // Passing null clears the favicon.
}
$view->headLink(['rel' => 'icon', 'href' => $href], 'PREPEND');
}
);

$sharedEventManager->attach(
'*',
'api.output.serialize',
Expand Down
13 changes: 13 additions & 0 deletions application/src/Form/SettingForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,19 @@ public function init()
],
]);

$this->add([
'name' => 'favicon',
'type' => 'Omeka\Form\Element\Asset',
'options' => [
'element_group' => 'general',
'label' => 'Favicon', // @translate
],
'attributes' => [
'value' => $this->settings->get('favicon'),
'id' => 'favicon',
],
]);

// Display element group

$this->add([
Expand Down
12 changes: 12 additions & 0 deletions application/src/Form/SiteSettingsForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,18 @@ public function init()
'id' => 'disable_jsonld_embed',
],
]);
$this->add([
'name' => 'favicon',
'type' => 'Omeka\Form\Element\Asset',
'options' => [
'element_group' => 'general',
'label' => 'Favicon', // @translate
],
'attributes' => [
'value' => $settings->get('favicon'),
'id' => 'favicon',
],
]);

// Language section
$this->add([
Expand Down

0 comments on commit e91bc65

Please sign in to comment.