titobrasolin / drupal7.services Goto Github PK
View Code? Open in Web Editor NEW.NET API to integrate with Drupal 7 via Services 3 module.
License: MIT License
.NET API to integrate with Drupal 7 via Services 3 module.
License: MIT License
Hi Tito, I'm banging my head against the wall on this.
I have a boolean field in a user account. Getting data from Drupal is easy and altering simple key values in the IDictionary is easy but I can't figure out how to alter the more complex ones, such as the roles or my custom boolean field here:
field_user_done : [user_dftd]: hashcode { 13189358 }
{
und : [integer[]]: hashcode { 51595365 }
{
0
}
}
I got that output from running:
var newuser = ser.Deserialize(ser.Serialize(_user));
WriteLine(newuser.DumpToString());
A pure DumpToString() gets me this
field_user_done : [XmlRpcStruct]: hashcode { 43231651 }
{
und : [Object[]]: hashcode { 43231651 }
{
0
}
}
Could you please help me how I can alter this key value from 0 to 1 and update the node object or user object or where ever the field in question is used and I will create a wiki entry on it when I get it to work? This needs documentation imo because it applies to every custom field you create.
Many thanks
Custom user fields are missing in the XmlRpcStruct that is returned. Do you know how to access these?
thanks
How do you go about retrieving a custom field? The "title", etc, are straight forward to get and map to a BaseNode. But custom fields...? =)
When I make a dump on it, I'm getting a hashtable that contains a hashtable with an Object[]
I have been able to map the field in the BaseNode, but I don't know what to do with the generic Object[] containing the string value I'm interested in.
For example:
field_risk_trailing_trigger_1 : [XmlRpcStruct]: hashcode { 34013913 }
{
und : [Object[]]: hashcode { 34013913 }
{
300
}
}
I am struggling to update three fields. Not sure where making the mistake. Fields are not updated and there is no exception either. These fields are empty and dump shows like this:
field_fields_text_field : [Object[]]: hashcode { 23240469 }{}
field_fields_integer : [Object[]]: hashcode { 17324607 }{}
field_fields_entity_reference : [Object[]]: hashcode { 21703739 }{}
//text field update
string oldTextValue = "Test String";
XmlRpcStruct textField = new XmlRpcStruct();
XmlRpcStruct textFieldInner = new XmlRpcStruct();
textFieldInner.Add("value", oldTextValue + " (UPDATES) ");
textFieldInner.Add("format", "");
textFieldInner.Add("safe_value", oldTextValue + " (UPDATES) ");
textField.Add("und", textFieldInner);
node.Remove("field_fields_text_field");
node["field_fields_text_field"] = textField;
//integer field update
int oldIntegerValue = 5;
var newIntegerValue = oldIntegerValue + 1;
XmlRpcStruct integerField = new XmlRpcStruct();
node.Remove("field_fields_integer");
integerField.Add("und", newIntegerValue);
node["field_fields_integer"] = integerField;
//entity reference field update
string oldEntityTitle = "Test Node";
string oldEntityID = "62";
XmlRpcStruct entityField = new XmlRpcStruct();
string accountEntity = oldEntityTitle + " (" + oldEntityID + ")";
entityField.Add("und", accountEntity);
node.Remove("field_fields_entity_reference");
node["field_fields_entity_reference"] = entityField;
XmlRpcStruct entityField = new XmlRpcStruct();
XmlRpcStruct entityInnerField = new XmlRpcStruct();
entityInnerField.Add("target_id", oldEntityID);
entityField.Add("und", entityInnerField);
node.Remove("field_fields_entity_reference");
node["field_fields_entity_reference"] = entityField;
XmlRpcStruct entityField = new XmlRpcStruct();
XmlRpcStruct entityInnerField = new XmlRpcStruct();
string accountEntity = oldEntityTitle + " (" + oldEntityID + ")";
entityInnerField.Add("target_id", accountEntity);
entityField.Add("und", entityInnerField);
node.Remove("field_fields_entity_reference");
node["field_fields_entity_reference"] = entityField;
XmlRpcStruct entityField = new XmlRpcStruct();
entityField.Add("und", oldEntityID);
node.Remove("field_fields_entity_reference");
node["field_fields_entity_reference"] = entityField;
none of these is updating the node. Could you please help me out on this?
I have to run this in order to update the user account because the user methods and node methods are not the same.
drupal.UserUpdate(uid, drupal.ConvertAs2(_user));
So I created a second ConvertAs method for my usecase as a temporary fix.
Maybe you have a reason for using object with the nodes but IDictionary with the users so I didn't want to make a commit before discussing this with you.
public XmlRpcStruct ConvertAs2(IDictionary value) {
IDictionary old;
XmlRpcStruct @new;
old = value as IDictionary;
if (old == null) {
return null;
}
@new = new XmlRpcStruct();
foreach (string key in old.Keys) {
@new.Add(key, old[key] == null ? "" : ConvertAs(old[key]));
}
return @new;
}
Hi Tito!
Having worked on the actual application for a while I'm now at a point with my project where it's time to work on sending data back to Drupal, and hopefully be able to help out with the documentation some more.
I can not save entity reference fields. Saving users or nodes does work but entity reference fields gives me errors.
To try and narrow it down I tried to simply download a node and update the same node without any changes, and also by trying to change the title, (which works if I remove the entity reference field.)
I get this in the Drupal error log:
Warning: Illegal offset type in isset or empty in _form_validate() (line 1374 of /srv/bindings/6c4f370c7e414228ac95abd4a642e4b2/code/includes/form.inc).
together with another error saying "Illegal choice" in the field in question.
Could you please have a look and make a test to see if you can replicate this?
The debug data from Services in the watchdog log looks normal. The data is in there.
In Visual Studio, I get this error:
CODE: 406 MESSAGE: Server returned a fault exception: [406] An illegal choice has been detected. Please contact the site administrator.
Many thanks!
Hi!
Is there a recommended way on how to send the session cookie with a request or is this taken care of automatically after performing LoginUser()
i.e. if I want to load a node after logging in, should it be enough to just call NodeRetrieve()?
When I do it, I can only access public content, not content restricted to a role.
More specifically, the DrupalSessionObject returned is empty when running SystemConnect();
IsLoggedIn also returns false.
But I do get the user data from the LoginUser, i.e. var blabla = UserLogin("user", "pass");
But I don't know how to make it so the commands I enter after this runs as logged in user and not anonymous. I thought Thanks!
Hi,
I would like to create a node that contains an array of data. The node is created correctly but only the first item of the array is being added to the node.
Here is my code, only the first "target_id" is created:
var node = new Hashtable
{
{ "type", "step" },
{ "title", "title" },
{ "language", "en" },
{ "field_content_reference", new Hashtable
{
{ "und", new Object[3]
{
new XmlRpcStruct
{
{ "target_id", "Visibilite conso content (996)"} ,
},
new XmlRpcStruct
{
{ "target_id", "Visibilite conso (997)"}
},
new XmlRpcStruct
{
{ "target_id", "Visibilite conso (267)"}
}
}
}
}
}
};
var nid = drupal.NodeCreate(node);
Can you please help me with this?
Thanks
Some of the Drupal fields has empty value. It returns fields like this:
field_fields_text_field : [Object[]]: hashcode { 34181910 }{}
field_fields_boolean : [XmlRpcStruct]: hashcode { 39201736 }
{
und : [XmlRpcStruct[]]: hashcode { 17271312 }
{
1
}
}
field_fields_term_reference : [Object[]]: hashcode { 21224086 }{}
field_fields_integer : [Object[]]: hashcode { 56799051 }{}
field_fields_entity_reference : [Object[]]: hashcode { 41429416 }{}
Empty fields: field_fields_term_reference, field_fields_text_field, field_fields_integer..
While converting to the node type it gives the following error:
Exception thrown: 'System.InvalidOperationException' in System.Web.Extensions.dll
An unhandled exception of type 'System.InvalidOperationException' occurred in System.Web.Extensions.dll
Additional information: Type 'Drupal7.Services.BaseClasses.fields_term_reference' is not supported for deserialization of an array.
How to handle this ?
I have logged in and creatnode , but throw a exception: access deny:
here is my code:
DrupalServices service = new Drupal7.Services.DrupalServices("http://**********");
bool login = service.Login("*******", "*******");
XmlRpcStruct node = service.NodeRetrieve(1);
if (service.IsLoggedIn)
{
node["title"] = "123";
service.NodeUpdate(node);
}
A field collection is created in Drupal site and the dump is seen as follows:
field_fields_field_collection : [XmlRpcStruct]: hashcode { 61027830 } { und : [XmlRpcStruct[]]: hashcode { 12379565 } { [XmlRpcStruct]: hashcode { 44307222 } { value : 3 revision_id : 3 } [XmlRpcStruct]: hashcode { 63220684 } { value : 4 revision_id : 4 } } }
How we can add/update the fields in field collection and retrieve field collection entity ?
thanks
This is the only I found to contact you... Can you please update the Drupal-Ubuntu introduction document at Ubuntu.com that you wrote so it would also be in line with the new features of Drupal 8?
How can I get a list of all the node with specified type, and how to retrieve nodes with a field filter?
Thanks.
I really like the ExtensionMethods, but they don't work with Users. I have created a BaseUser.cs file as a starting point.
namespace Drupal7.Services.BaseClasses
{
public class user_roles
{
public entity[] und { get; set; }
}
public class user_rdf
{
public entity[] und { get; set; }
}
public class BaseUser
{
public user_trading_account field_user_trading_account { get; set; }
public user_rdf rdf_mapping { get; set; }
public user_roles roles { get; set; }
// User ID
private int _uid;
public int uid
{
get
{
return _uid;
}
set
{
_uid = value;
}
}
// Login
private string _login;
public string login
{
get
{
return _login;
}
set
{
_login = value;
}
}
// Access
private string _access;
public string access
{
get
{
return _access;
}
set
{
_access = value;
}
}
// Name
private string _name;
public string name
{
get
{
return _name;
}
set
{
_name = value;
}
}
// Timezone
private string _timezone;
public string timezone
{
get
{
return _timezone;
}
set
{
_timezone = value;
}
}
// Created
private string _created;
public string created
{
get
{
return _created;
}
set
{
_created = value;
}
}
// Status
private string _status;
public string status
{
get
{
return _status;
}
set
{
_status = value;
}
}
// Language
private string _language;
public string language
{
get
{
return _language;
}
set
{
_language = value;
}
}
// Mail
private string _mail;
public string mail
{
get
{
return _mail;
}
set
{
_mail = value;
}
}
}
}
I have defined a new node type named "News" with a term reference field. How do I assign values to the term reference field when I create a news node?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.