Commit c4a279fd authored by akalam's avatar akalam

Perform actions for managing authlinks

parent 694b2130
......@@ -45,7 +45,7 @@ function node_authlink_form_node_type_form_alter(&$form, FormStateInterface &$fo
'#default_value' => isset($config_grants[$type])? $config_grants[$type] : [],
'#options' => [
'view' => t('View'),
'update' => t('Update'),
'edit' => t('Update'),
'delete' => t('Delete'),
],
'#description' => t('What operations will be temporarily given to authorised user for the node. This not affect users who is authorised yet.'),
......@@ -201,7 +201,7 @@ function node_authlink_load_authkey($nid) {
* @param $node Node object or NID.
* @param $op Operation to do with node. view, edit (default) or delete.
*/
function node_authlink_get_url($node, $op = 'edit') {
function node_authlink_get_url($node, $op = 'view') {
if (is_numeric($node)) {
$node = Node::load($node);
}
......@@ -251,7 +251,7 @@ function node_authlink_node_access(NodeInterface $node, $op, AccountInterface $a
// Check key if:
if (isset($_GET['authkey']) && // authkey param is set
isset($node->authkey)) { // authkey in node is set
isset($node->authkey)) { // authkey in node is setand
if ($node->authkey == $_GET['authkey']) {
// Start session
......
......@@ -58,47 +58,67 @@ class NodeAuthlinkNodeForm extends FormBase {
$node = Node::load($node);
$form['disclaimer'] = [
'#type' => 'markup',
'#markup' => '<p>' . $this->t('Use the following form to manage anonymous authlinks for performing View, Update or Delete tasks without any further authentication. The links available will depends on the configuration of this content type.') . '</p>',
];
if (isset($config_grants[$node->bundle()])) {
foreach ($config_grants[$node->bundle()] as $op) {
if (!$op) {
continue;
}
$url = node_authlink_get_url($node, $op);
if ($url) {
// @todo: use a table instead.
$form['link_'.$op] = [
'#type' => 'markup',
'#markup' => '<p>' . $url . '</p>',
];
$form['delete_' . $op] = [
'#type' => 'submit',
'#value' => $this->t('Delete @op authlink', ['@op' => $op]),
'#weight' => '0',
'#submit' => ['::deleteAuthlink' . ucfirst($op)]
];
}
else {
$form['create_' . $op] = [
'#type' => 'submit',
'#value' => $this->t('Create @op authlink', ['@op' => $op]),
'#weight' => '0',
'#submit' => ['::createAuthlink' . ucfirst($op)]
'#markup' => "<p><strong>$op</strong>: $url</p>",
];
}
}
if (node_authlink_load_authkey($node->id())) {
$form['delete'] = [
'#type' => 'submit',
'#value' => $this->t('Delete authlink'),
'#weight' => 10,
'#submit' => ['::deleteAuthlink'],
];
}
else {
$form['create'] = [
'#type' => 'submit',
'#value' => $this->t('Create authlink'),
'#weight' => 10,
'#submit' => ['::createAuthlink']
];
}
}
}
return $form;
}
public function createAuthlink(array &$form, FormStateInterface $form_state, $op) {
/**
* Create authlink submit callback.
*
* @param array $form
* @param \Drupal\Core\Form\FormStateInterface $form_state
*/
public function createAuthlink(array &$form, FormStateInterface $form_state) {
node_authlink_create($form_state->getBuildInfo()['args'][0]);
}
public function deleteAuthlink(array &$form, FormStateInterface $form_state, $op) {
/**
* Delete authlink submit callback.
* @param array $form
* @param \Drupal\Core\Form\FormStateInterface $form_state
*/
public function deleteAuthlink(array &$form, FormStateInterface $form_state) {
node_authlink_delete($form_state->getBuildInfo()['args'][0]);
}
/**
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment