Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don’t warn about manually set @web #3798

Merged
merged 1 commit into from
Feb 7, 2019
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions src/templates/_includes/forms.html
Original file line number Diff line number Diff line change
Expand Up @@ -259,9 +259,9 @@
: 'This can be set to an environment variable.'|t('app'))
~ ' <a href="https://docs.craftcms.com/v3/config/environments.html" class="go">' ~ 'Learn more'|t('app') ~ '</a>'
}) %}
{% elseif config.warning is not defined and (value == '@web' or value[0:5] == '@web/') %}
{% elseif config.warning is not defined and (value == '@web' or value[0:5] == '@web/') and craft.app.request.isWebAliasSetDynamically %}
{% set config = config|merge({
warning: 'The `@web` alias is not recommended.'|t('app')
warning: 'The `@web` alias is not recommended if it is determined automatically.'|t('app')
}) %}
{% endif %}
{% endif %}
Expand Down
16 changes: 16 additions & 0 deletions src/web/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ class Request extends \yii\web\Request
*/
private $_actionSegments;

/**
* @var bool
*/
private $_isWebAliasSetDynamically = false;

/**
* @var bool
*/
Expand Down Expand Up @@ -156,6 +161,7 @@ public function init()
}
if (Craft::getRootAlias('@web') === false) {
Craft::setAlias('@web', $this->getHostInfo() . $this->getBaseUrl());
$this->_isWebAliasSetDynamically = true;
}

$generalConfig = Craft::$app->getConfig()->getGeneral();
Expand Down Expand Up @@ -447,6 +453,16 @@ public function getActionSegments()
return $this->_actionSegments;
}

/**
* Returns whether the `@web` alias is set dynamically.
*
* @return bool Whether the `@web` alias is set dynamically.
*/
public function getIsWebAliasSetDynamically(): bool
{
return $this->_isWebAliasSetDynamically;
}

/**
* Returns whether this is a Live Preview request.
*
Expand Down