nortmas
7/17/2014 - 9:20 AM

Access webform machine name

<?php

/**
 * Plugins are described by creating a $plugin array which will be used
 * by the system that includes this file.
 */
$plugin = array(
  'title' => t('Webform machine name'),
  'description' => t('Controls access depends on webform machine name'),
  'required context' => array(new ctools_context_required(t('Node'), 'node')),
  'callback' => 'bmi_access_webform_machine_name',
  'settings form' => 'bmi_access_webform_machine_name_access_settings_form',
  'summary' => 'bmi_access_webform_machine_name_access_summary',
);

/**
 * Settings form for our access plugin.
 */
function bmi_access_webform_machine_name_access_settings_form(&$form, &$form_state, $conf) {
  $form['settings']['webform_machine_name'] = array(
    '#type' => 'textfield',
    '#title' => t('Webform machine name'),
    '#description' => t('Will provide access, if loaded webform machine name is matched'),
    '#default_value' => !empty($conf['webform_machine_name']) ? $conf['webform_machine_name'] : '',
    '#required' => TRUE,
  );
  return $form;
}

/**
 * Provide a summary description based on selected settings.
 */
function bmi_access_webform_machine_name_access_summary($conf, $context) {
  if (!empty($conf['webform_machine_name']))
     return t('Will provide access, if loaded webform machine name is matched: ') . $conf['webform_machine_name'];
}

/**
 * Check for access.
 */
function bmi_access_webform_machine_name($conf, $context) {
  return $context[0]->data->webform['machine_name'] == $conf['webform_machine_name'] ? TRUE : FALSE;
}
ctools_include('ajax');
$commands[] = ctools_ajax_command_redirect($url);

// ctools_ajax_command_attr         Set a single property to a value, on all matched elements.
// ctools_ajax_command_redirect     Force a client-side redirect.
// ctools_ajax_command_reload       Force a reload of the current page.
// ctools_ajax_command_submit       Submit a form.
// ctools_ajax_image_button         Render an image as a button link. This will automatically apply an AJAX class to the link and add the appropriate javascript to make this happen.
// ctools_ajax_render_error         Send an error response back via AJAX and immediately exit.
// ctools_ajax_text_button          Render text as a link. This will automatically apply an AJAX class to the link and add the appropriate javascript to make this happen.