I am employing the code below to check what deployment mode server is on. This is throwing the error. Please point out the issue with the usage of the object $this->_appState
to get the the mode. Thanks.
public function __construct(
\Magento\Framework\View\Element\Template\Context $context,
\Magento\Framework\App\State $appState,
\Magento\Framework\Filesystem $fileSystem) {
$this->_appState = $appState->getMode();
// Code to get the absolute path to the pub folder.
$this->_pubPath = $fileSystem->getDirectoryRead(\Magento\Framework\App\Filesystem\DirectoryList::PUB)->getAbsolutePath();
parent::__construct($context);
}
/**
* getAllPagesJSContent() returns the custom JS contents to calling custom allpages.js.
* This function checks if the deployment mode is production or not, and returns
* pmm/custom/js/allpages.min.js or pmm/custom/js/allpages.js
*
* @param void
* @return string file contents or empty
*/
public function getAllPagesJSContent() {
echo $this->_appState;
// Check current environment. If it is the production retrieve the allpages.min.js file.
if ($this->_appState == "production") {
echo "Hello from production 1";
if (($custom_js_file_contents = $this->get_custom_js_file_contents('allpages.min.js')) !== FALSE) {
return $custom_js_file_contents;
}
}