This repository has been archived by the owner on Aug 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #59 from SamNewism/master
fix bug with switching country when address is used on a non-entry
- Loading branch information
Showing
7 changed files
with
114 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
<?php | ||
/** | ||
* NSM Fields for Craft CMS 3.x | ||
* | ||
* nsm-fields | ||
* | ||
* @link http://newism.com.au | ||
* @copyright Copyright (c) 2017 newism | ||
*/ | ||
|
||
namespace newism\fields\controllers; | ||
|
||
use Craft; | ||
use craft\web\Controller; | ||
use Exception; | ||
use newism\fields\NsmFields; | ||
use Twig_Error_Loader; | ||
|
||
use yii\web\Response; | ||
use newism\fields\models\AddressModel; | ||
|
||
/** | ||
* Address Controller | ||
* | ||
* Generally speaking, controllers are the middlemen between the front end of | ||
* the CP/website and your plugin’s services. They contain action methods which | ||
* handle individual tasks. | ||
* | ||
* A common pattern used throughout Craft involves a controller action gathering | ||
* post data, saving it on a model, passing the model off to a service, and then | ||
* responding to the request appropriately depending on the service method’s response. | ||
* | ||
* Action methods begin with the prefix “action”, followed by a description of what | ||
* the method does (for example, actionSaveIngredient()). | ||
* | ||
* https://craftcms.com/docs/plugins/controllers | ||
* | ||
* @author newism | ||
* @package nsm-fields | ||
* @since 1.0.0 | ||
*/ | ||
class AddressController extends Controller | ||
{ | ||
|
||
// Protected Properties | ||
// ========================================================================= | ||
|
||
/** | ||
* @var bool|array Allows anonymous access to this controller's actions. | ||
* The actions must be in 'kebab-case' | ||
* @access protected | ||
*/ | ||
protected $allowAnonymous = []; | ||
|
||
// Public Methods | ||
// ========================================================================= | ||
|
||
/** | ||
* @return response | ||
* @throws Twig_Error_Loader | ||
* @throws \yii\base\Exception | ||
*/ | ||
public function actionRefreshCountry(): Response | ||
{ | ||
$this->requireAcceptsJson(); | ||
|
||
$address = Craft::$app->fields->getFieldByHandle('address'); | ||
|
||
$addressModel = new AddressModel([ | ||
'countryCode' => Craft::$app->request->post('countryCode') | ||
]); | ||
|
||
$response = [ | ||
'html' => Craft::$app->getView()->namespaceInputs($address->renderFormFields($addressModel), Craft::$app->request->post('namespace')) | ||
]; | ||
|
||
return $this->asJson($response); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters