Frage

Ich habe das folgende Problem damit, Knoten von Drupal 7 bis zu einer Drupal 6 -Installation zu erstellen. Auf der Site Target Drupal wird Dienste 3.x ausgeführt.

Hier ist mein Code:

$base_url = $params['path'];
$data = array(
  'username' => $params['username'],
  'password' => $params['password'],
);
$data = http_build_query($data, '', '&');
$headers = array();
$options = array(
  'headers' => array('Accept' => 'application/json'),
  'method' => 'POST',
  'data' => $data
);

$response = drupal_http_request($params['path'] . '/user/login', $options);
$data = json_decode($response->data);

// Check if login was successful
if ($response->code == 200) {
  // Now recycle the login cookie we recieved in the first request
  $options['headers']['Cookie'] = $data->session_name . '=' . $data->sessid;

  // Create a new node
  $data = array(
    'node' => array (
      'type' => 'cloudnode',
      'title' => 'node1',
      'field_ip_address' => array ('value' => '1.2.3.4'),
    )
  );
  $options['data'] = http_build_query( $data, '', '&');
  $options['method'] = 'POST';
  $response = drupal_http_request($base_url . '/node', $options);
} 
else {
  die ('Failed to login');
}

Ich bekomme eine 200 -Antwort; Der Knoten wird erstellt, aber irgendwie kümmert er sich überhaupt nicht um mein CCK -Feld 'field_ip_address'.

Ich habe irgendeine Art von Variationen ausprobiert, aber sie funktionieren nicht. Es gibt nicht viel Dokumentation.

Wenn es jemandem gelungen ist, mit Ruhe Knoten zu erstellen, wäre ich sehr interessiert für jede Hilfe.

War es hilfreich?

Lösung

CCK -Felder werden immer als Array von Feldern gespeichert, auch wenn das tatsächliche Feld nur auf einen einzelnen Wert beschränkt ist.

Sie sollten also so etwas sein wie:

'field_ip_address' => array(array('value' => '1.2.3.4'))

Beachten Sie, dass in Drupal 7 Feldwerte zusätzlich von der Sprache gruppiert werden, die "und" ist (und "(und" (und "(und 'Language_none) Wenn das Feld Sprache-agnostisch ist. Es wäre also so etwas:

'field_ip_address' => array('und' => array(array('value' => '1.2.3.4')))

Kopiert aus meinem Kommentar, damit die Frage als behoben gekennzeichnet werden kann :)

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit drupal.stackexchange
scroll top