class uc_addresses_views_plugin_argument_address_access in Ubercart Addresses 6.2
Same name and namespace in other branches
- 7 views/uc_addresses_views_plugin_argument_address_access.inc \uc_addresses_views_plugin_argument_address_access
Checks if the current user has access to addresses of the given user.
This inherits checks from views_plugin_argument_validate_user.
Hierarchy
- class \uc_addresses_views_plugin_argument_address_access extends \views_plugin_argument_validate
Expanded class hierarchy of uc_addresses_views_plugin_argument_address_access
1 string reference to 'uc_addresses_views_plugin_argument_address_access'
- uc_addresses_views_plugins in views/
uc_addresses.views.inc - Implements hook_views_plugins().
File
- views/
uc_addresses_views_plugin_argument_address_access.inc, line 13 - Definition of uatest_views_plugin_argument_address_access.
View source
class uc_addresses_views_plugin_argument_address_access extends views_plugin_argument_validate {
/**
* Implementation of views_plugin_argument_validate#validate_form().
*
* Used by Views 6.x-2.x.
*/
public function validate_form(&$form, &$form_state) {
// We are unable to rely on options having already been set, so let's make
// sure defaults are here:
if (!isset($this->argument->options['validate_uc_addresses_address_access_type'])) {
$this->argument->options['validate_uc_addresses_address_access_type'] = 'view';
}
$form['validate_uc_addresses_address_access_type'] = array(
'#type' => 'select',
'#title' => t('Address access type'),
'#description' => t('Select for which type of operation permissions should be checked. Usually "!access_type".', array(
'!access_type' => t('View'),
)),
'#options' => array(
'view' => t('View'),
'edit' => t('Edit'),
'delete' => t('Delete'),
),
'#default_value' => $this->argument->options['validate_uc_addresses_address_access_type'],
'#process' => array(
'views_process_dependency',
),
'#dependency' => array(
'edit-options-validate-type' => array(
$this->id,
),
),
);
}
/**
* Implementation of views_plugin_argument_validate#option_definition().
*
* Used by Views 6.x-3.x.
*/
public function option_definition() {
$options = parent::option_definition();
$options['access_type'] = array(
'default' => 'view',
);
return $options;
}
/**
* Implementation of views_plugin_argument_validate#options_form().
*
* Used by Views 6.x-3.x.
*/
public function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
$form['access_type'] = array(
'#type' => 'select',
'#title' => t('Address access type'),
'#description' => t('Select for which type of operation permissions should be checked. Usually "!access_type".', array(
'!access_type' => t('View'),
)),
'#options' => array(
'view' => t('View'),
'edit' => t('Edit'),
'delete' => t('Delete'),
),
'#default_value' => $this->options['access_type'],
);
}
/**
* Validates if argument is a valid user
* and if the current user has access to addresses of
* the given user.
*/
public function validate_argument($argument) {
// Check for address access.
$address = UcAddressesAddressBook::loadAddress($argument);
if (!$address) {
// Address does not exist.
return FALSE;
}
$access_type = 'view';
if (isset($this->argument->options['validate_uc_addresses_address_access_type'])) {
$access_type = $this->argument->options['validate_uc_addresses_address_access_type'];
}
elseif (isset($this->options['access_type'])) {
$access_type = $this->options['access_type'];
}
$address_user = user_load($address
->getUserId());
switch ($access_type) {
case 'view':
return UcAddressesPermissions::canViewAddress($address_user, $address);
case 'edit':
return UcAddressesPermissions::canEditAddress($address_user, $address);
case 'delete':
return UcAddressesPermissions::canDeleteAddress($address_user, $address);
}
return FALSE;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
uc_addresses_views_plugin_argument_address_access:: |
public | function | Implementation of views_plugin_argument_validate#options_form(). | |
uc_addresses_views_plugin_argument_address_access:: |
public | function | Implementation of views_plugin_argument_validate#option_definition(). | |
uc_addresses_views_plugin_argument_address_access:: |
public | function | Validates if argument is a valid user and if the current user has access to addresses of the given user. | |
uc_addresses_views_plugin_argument_address_access:: |
public | function | Implementation of views_plugin_argument_validate#validate_form(). |