Skip to content
This repository was archived by the owner on Jun 4, 2018. It is now read-only.

Added new configuration field 'noBackend' to prevent admin pages being redirected. #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions AutodetectLanguage.module
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,13 @@ class AutodetectLanguage extends WireData implements Module, ConfigurableModule
$this->defaultSiteLanguageCode = "";
$this->onlyOnHomepage = "";
$this->noDetectGetParam = "";
$this->noBackend = 1;
}

public function detectLanguageRedirect(HookEvent $event) {
if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
$page = wire("page");
$page = $event->object;
if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])
AND ($page->template != "admin" OR $this->noBackend == false)) {

// defaults to "en" if unset
if (empty($this->defaultSiteLanguageCode)) {
Expand Down Expand Up @@ -176,6 +178,13 @@ class AutodetectLanguage extends WireData implements Module, ConfigurableModule
if(isset($data['noDetectGetParam'])) $field->value = $data['noDetectGetParam'];
$inputfields->add($field);

return $inputfields;
$field = wire('modules')->get('InputfieldCheckbox');
$field->name ='noBackend';
$field->label = 'Only detect language on frontend';
$field->attr('value', $data['noBackend'] ? $data['noBackend'] : 0 );
$field->attr('checked', $data['noBackend'] === 1 ? 'checked' : '' );
$inputfields->add($field);

return $inputfields;
}
}