You are here

function _itoggle_ajax_toggle_entity in iToggle 7

Same name and namespace in other branches
  1. 7.2 itoggle.pages.inc \_itoggle_ajax_toggle_entity()

Helper function Changes entity properties

Parameters

string $type:

string $property:

int $id:

int $value:

1 call to _itoggle_ajax_toggle_entity()
itoggle_ajax_callback in ./itoggle.module
Page callback

File

./itoggle.module, line 133
iToggle module.

Code

function _itoggle_ajax_toggle_entity($type, $property, $id, $value) {

  // check permissions
  $access = FALSE;
  if (FALSE) {

    // @TODO check permissions
    // @TODO if node, check if override_node_options exists
    if (module_exists('override_node_options')) {
      $node = node_load($id);
      $type = $node->type;
      $access = user_access("override {$type} published option");
    }
  }
  else {
    $access = TRUE;
  }
  if ($access === TRUE) {
    $entity = entity_load($type, array(
      $id,
    ));
    if ($entity) {
      if ($entity->{$property} != $value) {
        $entity->{$property} = $value;
        $return = entity_save($type, $entity);
        return $return !== FALSE;
      }

      // if the value is already set just return TRUE
      return TRUE;
    }
  }
  return FALSE;
}