1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-23 23:02:58 +02:00

Update ProcessField and ProcessModule to implement the getAfterLoginUrl() method

This commit is contained in:
Ryan Cramer
2020-09-18 14:31:44 -04:00
parent d5146337de
commit 20f8a1ea14
2 changed files with 86 additions and 0 deletions

View File

@@ -2876,6 +2876,64 @@ class ProcessField extends Process implements ConfigurableModule {
return $result;
}
/**
* URL to redirect to after non-authenticated user is logged-in, or false if module does not support
*
* @param Page $page
* @return bool|string
* @sine 3.0.167
*
*/
public static function getAfterLoginUrl(Page $page) {
$sanitizer = $page->wire()->sanitizer;
$input = $page->wire()->input;
$segment = $input->urlSegment1;
$data = array();
if(empty($segment)) {
$data = array(
'templates_id' => (int) $input->get('templates_id'),
'fieldtype' => $input->get->name('fieldtype'),
'show_system' => (int) $input->get('show_system'),
'nosave' => (int) $input->get('nosave'),
'fieldgroup_id' => (int) $input->get('fieldgroup_id'),
);
} else if($segment === 'tags') {
$data = array(
'edit_tag' => $input->get->name('edit_tag'),
);
} else if($segment === 'edit') {
$data = array(
'id' => (int) $input->get('id'),
'context_namespace' => $input->get->fieldName('context_namespace'),
'context_label' => $input->get->text('context_label'),
'process_template' => (int) $input->get('process_template'),
'focus' => $input->get->fieldName('focus'),
'modal' => (int) $input->get('modal'),
'fieldgroup_id' => (int) $input->get('fieldgroup_id'),
);
if(!empty($data['context_label'])) $data['context_label'] = urlencode($data['context_label']);
} else if($segment === 'changeType' || $segment === 'change-type') {
$data = array(
'id' => (int) $input->get('id'),
'type' => $input->get->name('type'),
);
} else if($segment === 'sendTemplates' || $segment === 'send-templates') {
$templates = array();
foreach(explode(',', (string) $input->get('templates')) as $value) {
if(!empty($value)) $templates[] = $sanitizer->fieldName($value);
}
$data = array(
'id' => (int) $input->get('id'),
'templates' => implode(',', $templates),
);
} else if($segment === 'import' || $segment === 'export') {
// ok, no query string
} else {
$segment = '';
}
return $page->url() . $segment . (count($data) ? '?' . implode('&', $data) : '');
}
/**
* Build a form allowing configuration of this Module
*

View File

@@ -1580,5 +1580,33 @@ class ProcessModule extends Process {
return $form->render();
}
/**
* URL to redirect to after non-authenticated user is logged-in, or false if module does not support
*
* When supported, module should gather any input GET vars and URL segments that it recognizes,
* sanitize them, and return a URL for that request. ProcessLogin will redirect to the returned URL
* after user has successfully authenticated.
*
* If module does not support this, or only needs to support an integer 'id' GET var, then this
* method can return false.
*
* @param Page $page
* @return bool|string
* @sine 3.0.167
*
*/
public static function getAfterLoginUrl(Page $page) {
$url = $page->url();
$action = $page->wire()->input->urlSegmentStr;
$name = $page->wire()->input->get->fieldName('name');
if($action === 'edit' && $name && $page->wire()->modules->isInstalled($name)) {
$url .= "edit?name=$name";
$collapse = (int) $page->wire()->input->get('collapse_info');
if($collapse) $url .= "&collapse_info=$collapse";
}
return $url;
}
}