updated entity update

This commit is contained in:
Bachir Soussi Chiadmi
2016-11-05 16:55:34 +01:00
parent 3b6c7b914d
commit d1963312a6
23 changed files with 613 additions and 149 deletions

View File

@@ -29,7 +29,7 @@ function entity_metadata_book_get_properties($node, array $options, $name, $enti
case 'book_ancestors':
$ancestors = array();
while (!empty($node->book['plid'])) {
while (!empty($node->book['plid']) && $node->book['plid'] != -1) {
$link = book_link_load($node->book['plid']);
array_unshift($ancestors, $link['nid']);
$node = node_load($link['nid']);
@@ -670,9 +670,11 @@ function entity_metadata_field_file_validate_item($items, $context) {
function entity_metadata_no_hook_node_access($op, $node = NULL, $account = NULL) {
// First deal with the case where a $node is provided.
if (isset($node)) {
if ($op == 'create') {
if (empty($node->vid) && in_array($op, array('create', 'update'))) {
// This is a new node or the original node.
if (isset($node->type)) {
return node_access($op, $node->type, $account);
$op = !empty($node->is_new) && $node->is_new ? 'create' : 'update';
return node_access($op, $op == 'create' ? $node->type : $node, $account);
}
else {
throw new EntityMalformedException('Permission to create a node was requested but no node type was given.');
@@ -796,14 +798,35 @@ function entity_metadata_comment_properties_access($op, $property, $entity = NUL
* Access callback for the taxonomy entities.
*/
function entity_metadata_taxonomy_access($op, $entity = NULL, $account = NULL, $entity_type = NULL) {
if ($entity_type == 'taxonomy_vocabulary') {
return user_access('administer taxonomy', $account);
}
if (isset($entity) && $op == 'update' && !isset($account) && taxonomy_term_edit_access($entity)) {
// If user has administer taxonomy permission then no further checks.
if (user_access('administer taxonomy', $account)) {
return TRUE;
}
if (user_access('administer taxonomy', $account) || user_access('access content', $account) && $op == 'view') {
return TRUE;
switch ($op) {
case "view":
if (user_access('access content', $account)) {
return TRUE;
}
break;
case "update":
if ($entity_type == 'taxonomy_term') {
return user_access("edit terms in $entity->vid", $account);
}
break;
case "create":
if ($entity_type == 'taxonomy_term') {
// Check for taxonomy_access_fix contrib module which adds additional
// permissions to create new terms in a given vocabulary.
if (function_exists('taxonomy_access_fix_access')) {
return taxonomy_access_fix_access('add terms', $entity->vocabulary_machine_name);
}
}
break;
case "delete":
if ($entity_type == 'taxonomy_term') {
return user_access("delete terms in $entity->vid", $account);
}
break;
}
return FALSE;
}

View File

@@ -163,4 +163,10 @@ function entity_metadata_node_entity_property_info_alter(&$info) {
'auto creation' => 'entity_property_create_array',
'field' => TRUE,
);
// Make it a list if cardinality is not 1.
$field_body = field_info_field('body');
if (isset($field_body) && $field_body['cardinality'] != 1) {
$info['node']['properties']['body']['type'] = 'list<text_formatted>';
}
}