You are here

function webform_protected_downloads_component_delete_access in Webform Protected Downloads 7

Same name and namespace in other branches
  1. 6 webform_protected_downloads.module \webform_protected_downloads_component_delete_access()

Custom access callback that checks wheather a webform component can be deleted

Parameters

string $op:

object $node:

array $component:

Return value

boolean

1 string reference to 'webform_protected_downloads_component_delete_access'
webform_protected_downloads_menu_alter in ./webform_protected_downloads.module
Implementation of hook_menu_alter().

File

./webform_protected_downloads.module, line 278
This file contains hook declarations and functions for the Webform Protected Downloads module.

Code

function webform_protected_downloads_component_delete_access($op, $node, $component) {

  // check whether the current component exists already, otherwhise the coming
  // checks would be unnecessary
  if (isset($component['cid'])) {
    $component_in_use = webform_protected_downloads_get_configuration($node->nid, 'mail_field_cid') == $component['cid'];
    $node_protected = webform_protected_downloads_node_has_protected_files($node->nid);
    if ($node_protected && $component_in_use) {
      if (arg(5) == 'delete') {

        // we are really on the delete confirmation page
        drupal_set_message(t('Access to this action has been disabled by the Webform Protected Downloads module. The component that you want to delete is in use. Please got to the <a href="@protected_downloads_page">Protected Downloads configuration</a> of this webform and change the Mail confirmation field or unprotect all files. <br /><a href="@last_page">Go back to the form</a>', array(
          '@protected_downloads_page' => url('node/' . $node->nid . '/protected-downloads'),
          '@last_page' => url($_GET['destination']),
        )));
      }
      else {

        // we are most probably on the components edit form
        drupal_set_message(t('Deletion of this component has been disabled by the Webform Protected Downloads module, because the component is currently in use. This can be changed on the <a href="@protected_downloads_page">Protected Downloads configuration</a> page.', array(
          '@protected_downloads_page' => url('node/' . $node->nid . '/protected-downloads'),
        )));
      }
      return FALSE;
    }
  }
  return node_access($op, $node);
}