Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I'm trying to import the json export of a web service description in code. I have the export saved as an inc file in a /webservices folder. Here is my code.
function loudservices_default_wsclient_service() {
// Check for all web service files in webserivces directory
$webservicefiles = file_scan_directory(drupal_get_path('module', 'loudservices') . '/webservices', '/.*\.inc$/');
// Add webservice to list of webservices
foreach ($webservicefiles as $filepath => $file) {
$jsonservice = file_get_contents($filepath);
$service = json_decode($jsonservice);
if (isset($service)) {
$services[$service->name] = $service;
}
}
// At the end, return array of default services.
return $services;
}
This doesn't work for me. Does anyone have any idea how I can import the json export as a web service description via code?
Comments
Comment #0.0
JayShoe CreditAttribution: JayShoe commentedupdated
Comment #1
JayShoe CreditAttribution: JayShoe commentedDo you think that in order to do what I need to do, we need could or should integrate ctools with wsclient?
Comment #2
PatchRanger CreditAttribution: PatchRanger commentedhook_default_wsclient_service
implementation should contain the instances ofWSClientServiceDescription
, which are in fact entities: see http://drupalcode.org/project/wsclient.git/blob/refs/heads/7.x-1.x:/wscl... .So in order to define default implementation using export of this service, you should use
entity_import
: see http://drupalcode.org/project/entity.git/blob/refs/heads/7.x-1.x:/entity... . Something like this (I didn't try it, but I guess it should work):One more thing to note: I think there could be even better way - such as extend default
EntityDefaultFeaturesController
forwsclient_service
entity type, which controls every interaction with export-import functionality. I guess Rules implementation could be a good example: it manages to save exports of rules into files postfixed byrules_defaults.inc
and auto-import them if found as implemented here: http://drupalcode.org/project/rules.git/blob/refs/heads/7.x-2.x:/rules.f... . In my view we could go the same way.Comment #2.0
PatchRanger CreditAttribution: PatchRanger commentedI understand the question better. Here is try two.