Closed DenoBeno closed 5 years ago
By the way, I would prefer to have a "reset" button to map doing it on its own. For all I care it can just change zoom/pan immediately without animation, but please only when I say so...
Is seems that the iFrame hosting the map Component is forcibly reloaded after the screenshot is taken. If this is really the case we can do nothing about that in the map component since after the reload all contextual information is lost. In any case, this issue has to be addressed in this issue.
That's a bad news. Especially combined with https://github.com/clarity-h2020/emikat/issues/22. So we have two issues at a hand now:
@patrickkaleta, is there anything you can do on the "screenshot" side to avoid this reload after taking a screenshot?
@patrickkaleta, is there anything you can do on the "screenshot" side to avoid this reload after taking a screenshot?
It's not really the fault of the screenshot feature, but instead caused by the edit-form, which is opened after the screenshot is created. Saving that edit-form causes the page to be reloaded. That's the default Drupal behaviour. I have to check and see if there is a way to bypass this. @fgeyer16 maybe you have already encountered such a problem in the past and found a solution?
Maybe this can help?
https://agaric.coop/blog/display-forms-modal-dialog-drupal-8
The last thing missing, is what will happen if the user creates a node? By default, the node will redirect the user to another page but if we want to just close the modal dialog and leave the user on the same page we need to tell the form to do that. For this we are going to alter the form and add an AJAX command letting Drupal know that we want to close the dialog as soon as the node is created. In the .module file of a custom module we will add this code:
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Ajax\AjaxResponse;
use Drupal\Core\Ajax\CloseModalDialogCommand;
use Drupal\Core\Ajax\RedirectCommand;
/**
* Implements hook_form_alter().
*/
function modal_form_example_form_node_article_form_alter(&$form, FormStateInterface $form_state, $form_id) {
$form['actions']['submit']['#submit'][] = '_modal_form_example_ajax_submit';
$form['actions']['submit']['#attributes']['class'][] = 'use-ajax-submit';
}
/**
* Close the Modal and redirect the user to the homepage.
*
* @param array $form
* The form that will be altered.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* FormState Object.
*/
function _modal_form_example_ajax_submit(array $form, FormStateInterface &$form_state) {
$response = new AjaxResponse();
$response->addCommand(new CloseModalDialogCommand());
$form_state->setResponse($response);
}
Similar tutorial here: https://openwritings.net/pg/drupal/drupal-8-form-submission-without-reloading-using-ajax
Unfortunately, they are all adding some custom php code.
Maybe this can help?
https://agaric.coop/blog/display-forms-modal-dialog-drupal-8
Looks promising, I will give it a try.
Unfortunately, they are all adding some custom php code.
Should not be much of a problem, since we are already using similar hooks in our csis helpers module and I doubt that we will have to change this feature (having a modal submit form not trigger a page reload) too often in the future.
Actually, I think that we will need this for all "screenshots", not just for the maps.
When user spends some time customising what is shown to take a screenshot, it's possible that they want to take another with just one or two parameters changed. The application should not reset and force them to repeat all the work for the next screenshot....
Later when we just edit the text (in summary tabs), reloading the page is OK and even necessary.
Actually, I think that we will need this for all "screenshots", not just for the maps.
Of course. It would even be more difficult if we wanted to specify that this should only work for certain types of screenshots, so let's apply it on all screenshots.
Later when we just edit the text (in summary tabs), reloading the page is OK and even necessary.
Sounds reasonable but that could become a problem. The hook function in your solution fires everytime a Report image is edited. I need to add an additional check that will prevent this on all summary pages.
I implemented this new feature. The page now doesn't reload after the edit form of the new report image is saved. (Edit forms on the Summary pages still trigger the page to reload)
However, I noticed that the study area starts moving around after the first screenshots, when the user moves the map or zooms in our out. I'll post a new bug report for that.
After taking a screenshot, the map zooms back to the study area. This should IMO not happen
I wanted to make two screenshots of the same area (larger than the study area) for two time periods. Since the map always resets the zoom & pan after screenshot, it's practically impossible to do this.