patched loggintobogan fixed bug against field_permissions
removed field_collection (gonna dev own custom modules for showroom updated field-permissions to last dev
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
|
||||
/* Table cells. */
|
||||
.field-permissions-cell,
|
||||
.field-permissions-header {
|
||||
@@ -29,20 +28,19 @@ html.js .field-permissions-tooltip {
|
||||
color: #444;
|
||||
background-color: #f0f0f0;
|
||||
border: 1px solid #aaa;
|
||||
|
||||
/* CSS3 properties not supported by all browsers. */
|
||||
-webkit-box-shadow: 2px 2px 2px #ccc;
|
||||
-khtml-box-shadow: 2px 2px 2px #ccc;
|
||||
-icab-box-shadow: 2px 2px 2px #ccc;
|
||||
-moz-box-shadow: 2px 2px 2px #ccc;
|
||||
-o-box-shadow: 2px 2px 2px #ccc;
|
||||
box-shadow: 2px 2px 2px #ccc;
|
||||
-khtml-box-shadow: 2px 2px 2px #ccc;
|
||||
-icab-box-shadow: 2px 2px 2px #ccc;
|
||||
-moz-box-shadow: 2px 2px 2px #ccc;
|
||||
-o-box-shadow: 2px 2px 2px #ccc;
|
||||
box-shadow: 2px 2px 2px #ccc;
|
||||
-webkit-border-radius: 5px;
|
||||
-khtml-border-radius: 5px;
|
||||
-icab-border-radius: 5px;
|
||||
-moz-border-radius: 5px;
|
||||
-o-border-radius: 5px;
|
||||
border-radius: 5px;
|
||||
-khtml-border-radius: 5px;
|
||||
-icab-border-radius: 5px;
|
||||
-moz-border-radius: 5px;
|
||||
-o-border-radius: 5px;
|
||||
border-radius: 5px;
|
||||
}
|
||||
.field-permissions-tooltip .item-list,
|
||||
#field-permissions-tooltip .item-list {
|
||||
|
@@ -8,13 +8,13 @@
|
||||
/**
|
||||
* Obtain the list of field permissions.
|
||||
*
|
||||
* @param $field_label
|
||||
* @param string $field_label
|
||||
* The human readable name of the field to use when constructing permission
|
||||
* names. Usually this will be derived from one or more of the field instance
|
||||
* labels.
|
||||
*/
|
||||
function field_permissions_list($field_label = '') {
|
||||
return array(
|
||||
$permissions = array(
|
||||
'create' => array(
|
||||
'label' => t('Create field'),
|
||||
'title' => t('Create own value for field %field', array('%field' => $field_label)),
|
||||
@@ -36,46 +36,47 @@ function field_permissions_list($field_label = '') {
|
||||
'title' => t("View anyone's value for field %field", array('%field' => $field_label)),
|
||||
),
|
||||
);
|
||||
|
||||
drupal_alter('field_permissions_list', $permissions, $field_label);
|
||||
|
||||
return $permissions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns field permissions in a format suitable for use in hook_permission().
|
||||
*
|
||||
* @param $field
|
||||
* @param array $field
|
||||
* The field to return permissions for.
|
||||
* @param $label
|
||||
* @param mixed $label
|
||||
* (optional) The human readable name of the field to use when constructing
|
||||
* permission names; for example, this might be the label of one of the
|
||||
* corresponding field instances. If not provided, an appropriate label will
|
||||
* be automatically derived from all the field's instances.
|
||||
*
|
||||
* @return
|
||||
* @return array
|
||||
* An array of permission information, suitable for use in hook_permission().
|
||||
*/
|
||||
function field_permissions_list_field_permissions($field, $label = NULL) {
|
||||
$description = '';
|
||||
|
||||
// If there is no preferred label, construct one from all the instance
|
||||
// labels.
|
||||
if (!isset($label)) {
|
||||
$labels = array();
|
||||
foreach ($field['bundles'] as $entity_type => $bundles) {
|
||||
foreach ($bundles as $bundle_name) {
|
||||
$instance = field_info_instance($entity_type, $field['field_name'], $bundle_name);
|
||||
$labels[] = $instance['label'];
|
||||
$label = $field['field_name'];
|
||||
}
|
||||
$instances = array();
|
||||
$description = '';
|
||||
foreach ($field['bundles'] as $entity_type => $bundles) {
|
||||
foreach ($bundles as $bundle_name) {
|
||||
$instance = field_info_instance($entity_type, $field['field_name'], $bundle_name);
|
||||
$entity = entity_get_info($entity_type);
|
||||
if (!isset($entity['bundles'][$bundle_name])) {
|
||||
continue;
|
||||
}
|
||||
$instance_desc_tokens = array(
|
||||
$entity['label'],
|
||||
$entity['bundles'][$bundle_name]['label'],
|
||||
$instance['label'],
|
||||
);
|
||||
$instances[] = '"' . implode(':', $instance_desc_tokens) . '"';
|
||||
}
|
||||
// If all the instances have the same label, just use that. Otherwise, use
|
||||
// the field name (with the full list of instance labels as the permission
|
||||
// description).
|
||||
$labels = array_unique($labels);
|
||||
if (count($labels) == 1) {
|
||||
$label = array_shift($labels);
|
||||
}
|
||||
else {
|
||||
$label = $field['field_name'];
|
||||
$description = t('This field appears as: %instances', array('%instances' => implode(', ', $labels)));
|
||||
}
|
||||
$description = t('This field appears as: %instances.', array('%instances' => implode(', ', $instances)));
|
||||
}
|
||||
|
||||
$permissions = array();
|
||||
@@ -91,7 +92,7 @@ function field_permissions_list_field_permissions($field, $label = NULL) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of hook_permission().
|
||||
* Implements hook_permission().
|
||||
*/
|
||||
function _field_permissions_permission() {
|
||||
$perms = array(
|
||||
@@ -145,9 +146,7 @@ function _field_permissions_field_settings_form_alter(&$form, $form_state, $form
|
||||
'#type' => 'container',
|
||||
'#states' => array(
|
||||
'visible' => array(
|
||||
// We must cast this to a string until http://drupal.org/node/879580 is
|
||||
// fixed.
|
||||
':input[name="field[field_permissions][type]"]' => array('value' => (string) FIELD_PERMISSIONS_CUSTOM),
|
||||
':input[name="field[field_permissions][type]"]' => array('value' => FIELD_PERMISSIONS_CUSTOM),
|
||||
),
|
||||
),
|
||||
// Custom styling for the permissions matrix on the field settings page.
|
||||
@@ -156,6 +155,23 @@ function _field_permissions_field_settings_form_alter(&$form, $form_state, $form
|
||||
),
|
||||
);
|
||||
|
||||
$form['field']['field_permissions']['permission_warning'] = array(
|
||||
'#type' => 'item',
|
||||
'#markup' => '<div class="messages error"><b>'
|
||||
. t('Field permissions error')
|
||||
. '</b><br />'
|
||||
. t('If you are seeing this message and are not seeing a table of permissions, something is wrong! See !link for more information.', array(
|
||||
'!link' => l(t('the Field Permission documentation'), 'https://www.drupal.org/node/2802067#known-issues', array(
|
||||
'attributes' => array('target' => '_blank'),
|
||||
)),
|
||||
)) . '</div>',
|
||||
'#states' => array(
|
||||
'visible' => array(
|
||||
':input[name="field[field_permissions][type]"]' => array('value' => FIELD_PERMISSIONS_CUSTOM),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
// Add the field permissions matrix itself. Wait until the #pre_render stage
|
||||
// to move it to the above container, to avoid having the permissions data
|
||||
// saved as part of the field record.
|
||||
@@ -183,15 +199,15 @@ function _field_permissions_field_settings_form_alter(&$form, $form_state, $form
|
||||
* to actually be saved. For an example submit handler, see
|
||||
* _field_permissions_field_settings_form_submit().
|
||||
*
|
||||
* @param $field
|
||||
* @param array $field
|
||||
* The field whose permissions will be displayed in the matrix.
|
||||
* @param $instance
|
||||
* @param array $instance
|
||||
* The field instance for which the permissions will be displayed. Although
|
||||
* the permissions are per-field rather than per-instance, the instance label
|
||||
* will be used to display an appropriate human-readable name for each
|
||||
* permission.
|
||||
*
|
||||
* @return
|
||||
* @return array
|
||||
* A form array defining the permissions matrix.
|
||||
*
|
||||
* @see user_admin_permissions()
|
||||
@@ -327,37 +343,52 @@ function _field_permissions_field_settings_form_submit($form, &$form_state) {
|
||||
* Menu callback; Field permissions overview.
|
||||
*/
|
||||
function field_permissions_overview() {
|
||||
drupal_add_css(drupal_get_path('module', 'field_permissions') .'/field_permissions.admin.css');
|
||||
drupal_add_css(drupal_get_path('module', 'field_permissions') . '/field_permissions.admin.css');
|
||||
|
||||
$headers = array(t('Field name'), t('Field type'), t('Entity type'), t('Used in'));
|
||||
$headers = array(
|
||||
t('Field name'),
|
||||
t('Field type'),
|
||||
t('Entity type'),
|
||||
t('Used in'),
|
||||
);
|
||||
foreach (field_permissions_list() as $permission_type => $permission_info) {
|
||||
$headers[] = array('data' => $permission_info['label'], 'class' => 'field-permissions-header');
|
||||
}
|
||||
$destination = drupal_get_destination();
|
||||
|
||||
// Load list of field instances, types and bundles in the system.
|
||||
$instances = field_info_instances();
|
||||
// Load list of fields, field types and bundles in the system.
|
||||
$field_types = field_info_field_types();
|
||||
$bundles = field_info_bundles();
|
||||
$bundles_info = field_info_bundles();
|
||||
|
||||
// Retrieve the permissions for each role.
|
||||
$role_permissions = user_role_permissions(user_roles());
|
||||
|
||||
// Based on field_ui_fields_list() in field_ui.admin.inc.
|
||||
$rows = array();
|
||||
foreach ($instances as $obj_type => $type_bundles) {
|
||||
foreach ($type_bundles as $bundle => $bundle_instances) {
|
||||
foreach ($bundle_instances as $field_name => $instance) {
|
||||
foreach (field_info_fields() as $field_name => $field) {
|
||||
foreach ($field['bundles'] as $entity_type => $bundles) {
|
||||
foreach ($bundles as $bundle) {
|
||||
// Some fields might belong to bundles that are disabled (which are not
|
||||
// returned by field_info_bundles()).
|
||||
// @see https://www.drupal.org/node/1351506
|
||||
if (!isset($bundles_info[$entity_type][$bundle])) {
|
||||
continue;
|
||||
}
|
||||
// Each field will have a row in the table.
|
||||
$field = field_info_field($field_name);
|
||||
$admin_path = _field_ui_bundle_admin_path($obj_type, $bundle);
|
||||
if (module_exists('field_ui')) {
|
||||
$admin_path = _field_ui_bundle_admin_path($entity_type, $bundle);
|
||||
$field_admin_path = l($bundles_info[$entity_type][$bundle]['label'], $admin_path . '/fields/' . $field_name, array(
|
||||
'query' => $destination,
|
||||
'fragment' => 'edit-field-field-permissions-type',
|
||||
));
|
||||
}
|
||||
else {
|
||||
$field_admin_path = $bundles_info[$entity_type][$bundle]['label'];
|
||||
}
|
||||
$rows[$field_name]['data'][0] = $field['locked'] ? t('@field_name (Locked)', array('@field_name' => $field_name)) : $field_name;
|
||||
$rows[$field_name]['data'][1] = t($field_types[$field['type']]['label']);
|
||||
$rows[$field_name]['data'][2] = $obj_type;
|
||||
$rows[$field_name]['data'][3][] = l($bundles[$obj_type][$bundle]['label'], $admin_path . '/fields/'. $field_name, array(
|
||||
'query' => $destination,
|
||||
'fragment' => 'edit-field-field-permissions-type',
|
||||
));
|
||||
$rows[$field_name]['data'][1] = $field_types[$field['type']]['label'];
|
||||
$rows[$field_name]['data'][2] = $entity_type;
|
||||
$rows[$field_name]['data'][3][] = $field_admin_path;
|
||||
$rows[$field_name]['class'] = $field['locked'] ? array('menu-disabled') : array('');
|
||||
|
||||
// Append field permissions information to the report.
|
||||
@@ -381,7 +412,7 @@ function field_permissions_overview() {
|
||||
$all_users_have_access = isset($role_permissions[DRUPAL_ANONYMOUS_RID][$permission]) && isset($role_permissions[DRUPAL_AUTHENTICATED_RID][$permission]);
|
||||
$status_class = $all_users_have_access ? 'field-permissions-status-on' : 'field-permissions-status-off';
|
||||
$title = $all_users_have_access ? t('All users have this permission') : t('Not all users have this permission');
|
||||
$data = l('', 'admin/people/permissions', array(
|
||||
$data = l(NULL, 'admin/people/permissions', array(
|
||||
'attributes' => array(
|
||||
'class' => array('field-permissions-status', $status_class),
|
||||
'title' => $title,
|
||||
@@ -416,7 +447,7 @@ function field_permissions_overview() {
|
||||
|
||||
// Allow external modules alter the table headers and rows.
|
||||
foreach (module_implements('field_permissions_overview_alter') as $module) {
|
||||
$function = $module .'_field_permissions_overview_alter';
|
||||
$function = $module . '_field_permissions_overview_alter';
|
||||
$function($headers, $rows);
|
||||
}
|
||||
|
||||
|
@@ -1,63 +1,74 @@
|
||||
/**
|
||||
* @file
|
||||
*/
|
||||
|
||||
(function ($) {
|
||||
|
||||
Drupal.behaviors.fieldPermissionsSettings = {
|
||||
attach: function (context) {
|
||||
// For user fields, we want the "Create own value for field X" permission
|
||||
// row to only be displayed when it's meaningful (i.e., when the "Display
|
||||
// on user registration form" checkbox is checked).
|
||||
var $user_register_form_checkbox, $required_field_checkbox, $create_permission_row;
|
||||
$user_register_form_checkbox = $('.form-item-instance-settings-user-register-form .form-checkbox', context);
|
||||
if ($user_register_form_checkbox.length) {
|
||||
// The "Required field" checkbox can cause the user registration checkbox
|
||||
// to change, so we need it also.
|
||||
$required_field_checkbox = $('.form-item-instance-required .form-checkbox', context);
|
||||
if ($required_field_checkbox.length) {
|
||||
// Get the permissions table row corresponding to the "Create own value
|
||||
// for field X" permission. The theme_user_admin_permissions() function
|
||||
// does not give us a good way to directly detect which row contains
|
||||
// the create permissions, so we have rely on the fact that it will be
|
||||
// the first row.
|
||||
$create_permission_row = $('table#permissions tbody tr', context).filter(':first');
|
||||
new Drupal.fieldPermissions.HideCreatePermission($user_register_form_checkbox, $required_field_checkbox, $create_permission_row);
|
||||
Drupal.behaviors.fieldPermissionsSettings = {
|
||||
attach: function (context) {
|
||||
// For user fields, we want the "Create own value for field X" permission
|
||||
// row to only be displayed when it's meaningful (i.e., when the "Display
|
||||
// on user registration form" checkbox is checked).
|
||||
var $user_register_form_checkbox, $required_field_checkbox, $create_permission_row;
|
||||
$user_register_form_checkbox = $('.form-item-instance-settings-user-register-form .form-checkbox', context);
|
||||
if ($user_register_form_checkbox.length) {
|
||||
// The "Required field" checkbox can cause the user registration checkbox
|
||||
// to change, so we need it also.
|
||||
$required_field_checkbox = $('.form-item-instance-required .form-checkbox', context);
|
||||
if ($required_field_checkbox.length) {
|
||||
// Get the permissions table row corresponding to the "Create own value
|
||||
// for field X" permission. The theme_user_admin_permissions() function
|
||||
// does not give us a good way to directly detect which row contains
|
||||
// the create permissions, so we have rely on the fact that it will be
|
||||
// the first row.
|
||||
$create_permission_row = $('table#permissions tbody tr', context).filter(':first');
|
||||
new Drupal.fieldPermissions.HideCreatePermission($user_register_form_checkbox, $required_field_checkbox, $create_permission_row);
|
||||
}
|
||||
}
|
||||
|
||||
// Show a warning if there's no available permissions matrix.
|
||||
$('#edit-field-field-permissions-permission-warning').toggle(!$('#permissions').length);
|
||||
|
||||
$('[name="field[field_permissions][type]"]').bind('change', function(option) {
|
||||
$('#edit-field-field-permissions-permission-warning').toggle(!$('#permissions').length);
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
Drupal.fieldPermissions = {};
|
||||
Drupal.fieldPermissions = {};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Constructor for the HideCreatePermission object.
|
||||
*
|
||||
* This object hides and shows the "Create own value for field X" permission
|
||||
* for user fields when it is appropriate to do so, depending on the state of
|
||||
* the "Display on user registration form" and "Required field" checkboxes.
|
||||
*/
|
||||
Drupal.fieldPermissions.HideCreatePermission = function ($user_register_form_checkbox, $required_field_checkbox, $create_permission_row) {
|
||||
this.$user_register_form_checkbox = $user_register_form_checkbox;
|
||||
this.$create_permission_row = $create_permission_row;
|
||||
// Start off by making sure the create permission row has the correct
|
||||
// visibility.
|
||||
this.setCreatePermissionVisibility();
|
||||
// Set the row's visibility again whenever the user registration checkbox
|
||||
// changes, or when the required field checkbox (which controls it) changes.
|
||||
$user_register_form_checkbox.bind('change', $.proxy(this.setCreatePermissionVisibility, this));
|
||||
$required_field_checkbox.bind('change', $.proxy(this.setCreatePermissionVisibility, this));
|
||||
};
|
||||
Drupal.fieldPermissions.HideCreatePermission = function ($user_register_form_checkbox, $required_field_checkbox, $create_permission_row) {
|
||||
this.$user_register_form_checkbox = $user_register_form_checkbox;
|
||||
this.$create_permission_row = $create_permission_row;
|
||||
// Start off by making sure the create permission row has the correct
|
||||
// visibility.
|
||||
this.setCreatePermissionVisibility();
|
||||
// Set the row's visibility again whenever the user registration checkbox
|
||||
// changes, or when the required field checkbox (which controls it) changes.
|
||||
$user_register_form_checkbox.bind('change', $.proxy(this.setCreatePermissionVisibility, this));
|
||||
$required_field_checkbox.bind('change', $.proxy(this.setCreatePermissionVisibility, this));
|
||||
};
|
||||
|
||||
/**
|
||||
* Set the correct visibility of the "Create own value for field X" permission.
|
||||
*/
|
||||
Drupal.fieldPermissions.HideCreatePermission.prototype.setCreatePermissionVisibility = function () {
|
||||
// Granting permissions for "Create own value for field X" only makes sense
|
||||
// when the field is configured to appear on the user registration form, so
|
||||
// only show the row in the permissions table then.
|
||||
if (this.$user_register_form_checkbox.is(':checked')) {
|
||||
this.$create_permission_row.show();
|
||||
}
|
||||
else {
|
||||
this.$create_permission_row.hide();
|
||||
}
|
||||
};
|
||||
/**
|
||||
* Set the correct visibility of the "Create own value for field X" permission.
|
||||
*/
|
||||
Drupal.fieldPermissions.HideCreatePermission.prototype.setCreatePermissionVisibility = function () {
|
||||
// Granting permissions for "Create own value for field X" only makes sense
|
||||
// when the field is configured to appear on the user registration form, so
|
||||
// only show the row in the permissions table then.
|
||||
if (this.$user_register_form_checkbox.is(':checked')) {
|
||||
this.$create_permission_row.show();
|
||||
}
|
||||
else {
|
||||
this.$create_permission_row.hide();
|
||||
}
|
||||
};
|
||||
|
||||
})(jQuery);
|
||||
|
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Hooks provided by the Field Permission module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Defines the owner of an entity.
|
||||
*
|
||||
* Because not all entities have uids, this hook allows other modules to specify
|
||||
* one.
|
||||
*
|
||||
* @param int $uid
|
||||
* The userid that will be checked against the current user's account->uid.
|
||||
* @param object $entity
|
||||
* The entity this field belongs to.
|
||||
*/
|
||||
// @codingStandardsIgnoreStart
|
||||
function hook_field_permissions_userid_ENTITY_TYPE_alter(&$uid, $entity) {
|
||||
// This example always assigns user 15 as the owner of an entity.
|
||||
$uid = 15;
|
||||
}
|
||||
// @codingStandardsIgnoreEnd
|
||||
|
||||
/**
|
||||
* Alter the permissions handled by field_permissions module.
|
||||
*
|
||||
* @param array $permissions
|
||||
* The $permissions array created by the Field permissions module.
|
||||
* @param string $field_label
|
||||
* The field name.
|
||||
*/
|
||||
function hook_field_permissions_list_alter(&$permissions, $field_label) {
|
||||
$permissions += array(
|
||||
'view own node preview' => array(
|
||||
'label' => t('View own field on node preview'),
|
||||
'title' => t('View own value for field %field on node preview', array('%field' => $field_label)),
|
||||
),
|
||||
'view node preview' => array(
|
||||
'label' => t('View field on node preview'),
|
||||
'title' => t("View anyone's value for field %field on node preview", array('%field' => $field_label)),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook invoked with custom field permissions.
|
||||
*
|
||||
* This hook can be used to revoke access to the field. If access is not
|
||||
* revoked, default access of the Field permissions module will apply.
|
||||
*
|
||||
* @param string $op
|
||||
* The operation to be performed. Possible values: 'edit', 'view'.
|
||||
* @param array $field
|
||||
* The field on which the operation is to be performed.
|
||||
* @param string $entity_type
|
||||
* The type of $entity; for example, 'node' or 'user'.
|
||||
* @param object $entity
|
||||
* (optional) The entity for the operation.
|
||||
* @param object $account
|
||||
* (optional) The account to check; if not given use currently logged in user.
|
||||
*
|
||||
* @return bool
|
||||
* FALSE if the operation is not allowed.
|
||||
*
|
||||
* @see field_permissions_field_access()
|
||||
* @see field_access()
|
||||
*/
|
||||
function hook_field_permissions_custom_field_access($op, $field, $entity_type, $entity, $account) {
|
||||
if ($op == 'view' && $entity_type == 'node' && !empty($entity)) {
|
||||
// Check if user has access to view this field in any entity.
|
||||
if (!user_access('view node preview ' . $field['field_name'], $account)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// If the user has permission to view entities that they own, return TRUE if
|
||||
// they own this entity or FALSE if they don't.
|
||||
if (user_access('view own node preview ' . $field['field_name'], $account)) {
|
||||
return _field_permissions_entity_is_owned_by_account($entity, $account);
|
||||
}
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
@@ -2,14 +2,12 @@ name = Field Permissions
|
||||
description = Set field-level permissions to create, update or view fields.
|
||||
package = Fields
|
||||
core = 7.x
|
||||
files[] = field_permissions.module
|
||||
files[] = field_permissions.admin.inc
|
||||
files[] = field_permissions.test
|
||||
configure = admin/reports/fields/permissions
|
||||
|
||||
; Information added by drupal.org packaging script on 2012-01-25
|
||||
version = "7.x-1.0-beta2"
|
||||
; Information added by Drupal.org packaging script on 2016-10-15
|
||||
version = "7.x-1.0-beta2+21-dev"
|
||||
core = "7.x"
|
||||
project = "field_permissions"
|
||||
datestamp = "1327510549"
|
||||
datestamp = "1476570240"
|
||||
|
||||
|
@@ -16,6 +16,28 @@ function field_permissions_install() {
|
||||
->execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_uninstall().
|
||||
*/
|
||||
function field_permissions_uninstall() {
|
||||
|
||||
// Collect all the field data that reference "field_permissions", within
|
||||
// the field_config table.
|
||||
//
|
||||
$records = db_query("SELECT * FROM field_config WHERE data LIKE '%field_permissions%'");
|
||||
|
||||
foreach ($records as $record) {
|
||||
$data = $record->data;
|
||||
$data = unserialize($data);
|
||||
unset($data['field_permissions']);
|
||||
$data = serialize($data);
|
||||
|
||||
// Update the record.
|
||||
db_query("UPDATE field_config SET data = :data WHERE id = :id",
|
||||
array(':data' => $data, ':id' => $record->id));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a larger weight for the module so that the Field Permissions become available.
|
||||
*/
|
||||
|
@@ -79,6 +79,13 @@ function field_permissions_form_field_ui_field_edit_form_alter(&$form, &$form_st
|
||||
return _field_permissions_field_settings_form_alter($form, $form_state, $form_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_field_permissions_userid_ENTITY_TYPE_alter().
|
||||
*/
|
||||
function field_permissions_field_permissions_userid_field_collection_item_alter(&$uid, $entity) {
|
||||
$uid = isset($entity->hostEntity()->uid) ? $entity->hostEntity()->uid : $uid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of hook_field_access().
|
||||
*
|
||||
@@ -124,6 +131,12 @@ function field_permissions_field_access($op, $field, $entity_type, $entity, $acc
|
||||
}
|
||||
// Otherwise, check access by permission.
|
||||
elseif ($field['field_permissions']['type'] == FIELD_PERMISSIONS_CUSTOM) {
|
||||
// Allow other modules to deny access first.
|
||||
$result = module_invoke_all('field_permissions_custom_field_access', $op, $field, $entity_type, $entity, $account);
|
||||
if (in_array(FALSE, $result)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!isset($entity)) {
|
||||
return field_permissions_empty_entity_access($op, $field['field_name'], $account);
|
||||
}
|
||||
@@ -258,5 +271,76 @@ function _field_permissions_entity_is_owned_by_account($entity, $account) {
|
||||
// set (for example, if the entity type does not store a uid or does not have
|
||||
// a concept of "ownership"), we need to assume that the provided user
|
||||
// account does not own it.
|
||||
return isset($entity->uid) && $entity->uid == $account->uid;
|
||||
$uid = isset($entity->uid) ? $entity->uid : FALSE;
|
||||
if (method_exists($entity, 'entityType')) {
|
||||
drupal_alter('field_permissions_userid_' . $entity->entityType(), $uid, $entity);
|
||||
}
|
||||
|
||||
return $uid === $account->uid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_features_pipe_COMPONENT_alter().
|
||||
*
|
||||
* Add field permissions to features when exporting a field_base.
|
||||
*/
|
||||
function field_permissions_features_pipe_field_base_alter(&$pipe, $data, $export) {
|
||||
// Validate if there are field_base components that will be exported for this
|
||||
// feature.
|
||||
if (isset($export['features']['field_base'])) {
|
||||
module_load_include('inc', 'field_permissions', 'field_permissions.admin');
|
||||
// Iterate through the exported field_base components for this feature and
|
||||
// add the defined field permissions.
|
||||
foreach ($export['features']['field_base'] as $field_name) {
|
||||
$field = field_info_field($field_name);
|
||||
if (isset($field['field_permissions']['type']) && $field['field_permissions']['type'] == FIELD_PERMISSIONS_CUSTOM) {
|
||||
$perms = field_permissions_list_field_permissions($field, '');
|
||||
foreach ($perms as $perm => $info) {
|
||||
$pipe['user_permission'][] = $perm;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_field_attach_form().
|
||||
*/
|
||||
function field_permissions_field_attach_form($entity_type, $entity, &$form, &$form_state, $langcode) {
|
||||
// Some fields are validated if they are #required even if field's #access
|
||||
// property is set to false. For example: file/image fields, options fields.
|
||||
foreach (element_children($form) as $key) {
|
||||
if (isset($form[$key]['#access']) && !$form[$key]['#access']) {
|
||||
_field_permissions_make_elements_non_required($form[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the #required property to FALSE recursively on form elements.
|
||||
*/
|
||||
function _field_permissions_make_elements_non_required(&$elements) {
|
||||
if (!is_array($elements)) {
|
||||
return;
|
||||
}
|
||||
if (!empty($elements['#required'])) {
|
||||
$elements['#required'] = FALSE;
|
||||
}
|
||||
foreach (element_children($elements) as $key) {
|
||||
_field_permissions_make_elements_non_required($elements[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_field_delete_field().
|
||||
*/
|
||||
function field_permissions_field_delete_field($field) {
|
||||
// Delete any permissions related to the deleted field.
|
||||
$all_permissions = array_keys(field_permissions_permission());
|
||||
if (!empty($all_permissions)) {
|
||||
db_delete('role_permission')
|
||||
->condition('module', 'field_permissions')
|
||||
->condition('permission', $all_permissions, 'NOT IN')
|
||||
->execute();
|
||||
}
|
||||
}
|
||||
|
@@ -26,7 +26,7 @@ class FieldPermissionsTestCase extends DrupalWebTestCase {
|
||||
parent::setUp('field_ui', 'field_permissions');
|
||||
|
||||
// Create test user.
|
||||
$admin_permissions = array('access content', 'administer nodes', 'bypass node access', 'administer content types', 'administer taxonomy', 'administer permissions', 'create page content');
|
||||
$admin_permissions = array('access content', 'administer nodes', 'bypass node access', 'administer content types', 'administer taxonomy', 'administer permissions', 'create page content', 'administer fields');
|
||||
$this->limited_user = $this->drupalCreateUser($admin_permissions);
|
||||
$all_rids = array_keys($this->limited_user->roles);
|
||||
sort($all_rids);
|
||||
@@ -162,11 +162,11 @@ class FieldPermissionsTestCase extends DrupalWebTestCase {
|
||||
// See if we have that exposed on the permissions UI as well now.
|
||||
$this->drupalGet('admin/people/permissions');
|
||||
$this->assertText(t('Field Permissions'));
|
||||
$this->assertRaw(t('Create own value for field %field', array('%field' => $field_info['name'])));
|
||||
$this->assertRaw(t('Edit own value for field %field', array('%field' => $field_info['name'])));
|
||||
$this->assertRaw(t("Edit anyone's value for field %field", array('%field' => $field_info['name'])));
|
||||
$this->assertRaw(t('View own value for field %field', array('%field' => $field_info['name'])));
|
||||
$this->assertRaw(t("View anyone's value for field %field", array('%field' => $field_info['name'])));
|
||||
$this->assertRaw(t('Create own value for field %field', array('%field' => $field_info['machine_name'])));
|
||||
$this->assertRaw(t('Edit own value for field %field', array('%field' => $field_info['machine_name'])));
|
||||
$this->assertRaw(t("Edit anyone's value for field %field", array('%field' => $field_info['machine_name'])));
|
||||
$this->assertRaw(t('View own value for field %field', array('%field' => $field_info['machine_name'])));
|
||||
$this->assertRaw(t("View anyone's value for field %field", array('%field' => $field_info['machine_name'])));
|
||||
|
||||
// == CREATE ===============================================================
|
||||
|
||||
|
Reference in New Issue
Block a user