/**
  * Check to make sure that the array of permissions are valid.
  *
  * @param $permissions
  *   Permissions to check.
  * @param $reset
  *   Reset cached available permissions.
  * @return
  *   TRUE or FALSE depending on whether the permissions are valid.
  */
 protected function checkPermissions(array $permissions, $reset = FALSE)
 {
     $available =& backdrop_static(__FUNCTION__);
     if (!isset($available) || $reset) {
         $available = array_keys(module_invoke_all('permission'));
     }
     $valid = TRUE;
     foreach ($permissions as $permission) {
         if (!in_array($permission, $available)) {
             $this->fail(t('Invalid permission %permission.', array('%permission' => $permission)), t('Role'));
             $valid = FALSE;
         }
     }
     return $valid;
 }
예제 #2
0
/**
 * Act before the storage backends update field data.
 *
 * This hook allows modules to store data before the Field Storage API,
 * optionally preventing the field storage module from doing so.
 *
 * @param $entity_type
 *   The type of $entity; for example, 'node' or 'user'.
 * @param $entity
 *   The entity with fields to save.
 * @param $skip_fields
 *   An array keyed by field IDs whose data has already been written and
 *   therefore should not be written again. The values associated with these
 *   keys are not specified.
 * @return
 *   Saved field IDs are set set as keys in $skip_fields.
 */
function hook_field_storage_pre_update($entity_type, $entity, &$skip_fields)
{
    $first_call =& backdrop_static(__FUNCTION__, array());
    if ($entity_type == 'node' && $entity->status) {
        // We don't maintain data for old revisions, so clear all previous values
        // from the table. Since this hook runs once per field, per entity, make
        // sure we only wipe values once.
        if (!isset($first_call[$entity->nid])) {
            $first_call[$entity->nid] = FALSE;
            db_delete('custom_index')->condition('nid', $entity->nid)->execute();
        }
        // Only save data to the table if the node is published.
        if ($entity->status) {
            $query = db_insert('custom_index')->fields(array('nid', 'title', 'tid', 'sticky', 'created', 'comment_count', 'last_comment_timestamp'));
            foreach ($entity->custom as $language) {
                foreach ($language as $delta) {
                    $query->values(array('nid' => $entity->nid, 'title' => $entity->title, 'tid' => $delta['value'], 'sticky' => $entity->sticky, 'created' => $entity->created, 'comment_count' => 0, 'last_comment_timestamp' => $entity->created));
                }
            }
            $query->execute();
        }
    }
}