Skip to content

Update the AdminNotification AjaxMarkAsRead controller #10433

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

Merged
merged 2 commits into from
Aug 4, 2017

Conversation

dmanners
Copy link
Contributor

@dmanners dmanners commented Aug 4, 2017

Update the AdminNotification AjaxMarkAsRead controller

  • stop the direct usage of object manager in the execute method,
  • modify the execute method to use the resultFactory for building the response

Description

This PR is really more a question with regards to best practice when building AjaxControllers.

Questions:

  1. $this->getResponse()->representJson() vs $this->resultFactory->create(ResultFactory::TYPE_JSON) which is the option that should be considered for usage?
  2. Are mixed returns of \Magento\Framework\Controller\Result\Json|void ok or should it always be at least of type \Magento\Framework\App\ResponseInterface\ResultInterface
  3. Calling setData on array of response data or calling setJsonData or already formatted data?

Contribution checklist

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds on Travis CI are green)

 - stop the direct usage of object manager in the execute method,
 - modify the execute method to use the resultFactory for building the response
@ishakhsuvarov ishakhsuvarov self-assigned this Aug 4, 2017
@ishakhsuvarov ishakhsuvarov added this to the August 2017 milestone Aug 4, 2017
);

/** @var \Magento\Framework\Controller\Result\Json $resultJson */
$resultJson = $this->resultFactory->create(ResultFactory::TYPE_JSON);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$this->getResponse()->representJson() vs $this->resultFactory->create(ResultFactory::TYPE_JSON) which is the option that should be considered for usage?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the second option is more up to date.

* Mark notification as read (AJAX action)
*
* @return void
* @return \Magento\Framework\Controller\Result\Json|void
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are mixed returns of \Magento\Framework\Controller\Result\Json|void ok or should it always be at least of type \Magento\Framework\App\ResponseInterface\ResultInterface

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should follow the \Magento\Framework\App\ActionInterface interface signature, since it implements it.


/** @var \Magento\Framework\Controller\Result\Json $resultJson */
$resultJson = $this->resultFactory->create(ResultFactory::TYPE_JSON);
$resultJson->setData($responseData);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calling setData on array of response data or calling setJsonData or already formatted data what is "best practice" or does it not matter?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Taking into account the conversation happening in #10342 I can not say which one is the best practice atm. I assume you should use the one which is currently not deprecated.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setData is an obvious leader as you don't want encodeJson in every controller which would also require additional JSON serializer dependency.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ishakhsuvarov both are not deprecated ATM due to revert :)

@magento-team magento-team merged commit 9a15cae into magento:develop Aug 4, 2017
@dmanners dmanners deleted the update-admin-ajax-controller branch December 19, 2017 13:07
@Ctucker9233
Copy link

@magento-team Will this be backported to 2.2?

@orlangur
Copy link
Contributor

@Ctucker9233 no, it cannot

due to changes in Magento Code Contributions Guide we can't accept such Pull Requests to 2.2 release line. All code cleanup like typos, spelling mistakes, removing unused code, etc should be delivered to 2.3 release line only.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants