Drupalgap Services

  • 24 December 2017
  • GeeX

 

Achtung Services Paramter Call 

 http://kimo2007.dnshome.de:8888/d7mobile/?q=drupalgap/search_node/retrie...

Kein ? nach retrieve.json

 

Fieldinfo Service

drupalgap.services.inc

 'drupalgap_field' => array(
      'actions' => array(
        'field_info_instances' => array(
          'help' => t('Retrieves information about field instances.'),
          'file' => array(
            'type' => 'inc',
            'module' => 'drupalgap',
            'name' => 'drupalgap.resource',
          ),
          'callback' => '_drupalgap_field_info_instances',
          'args' => array(
            array(
              'name' => 'entity_type',
              'optional' => TRUE,
              'source' => array('data' => 'entity_type'),
              'description' => 'The entity type for which to return instances.',
              'type' => 'string',
            ),
            array(
              'name' => 'bundle_name',
              'optional' => TRUE,
              'source' => array('data' => 'bundle_name'),
              'description' => 'The bundle name for which to return instances.',
              'type' => 'string',
            ),
          ),
          'access callback' => '_drupalgap_resource_access',
          'access callback file' => array(
            'type' => 'inc',
            'module' => 'drupalgap',
            'name' => 'drupalgap.resource',
          ),
          'access arguments' => array('access content'),
          'access arguments append' => TRUE,
        ),
      ),
    ),

 

drupalgap.resource.inc

//JSON
//[{"entity_type":"node"},{"bundle_name":"demo"}]
function _drupalgap_field_info_instances($entity_type = NULL, $bundle_name = NULL) {
	watchdog('my_module', 'entity_type<pre>'.print_r($entity_type,true).'</pre> bundle_name<pre>'.print_r($bundle_name,true).'</pre>'  );
	return field_info_instances($entity_type['entity_type'], $bundle_name['bundle_name']);
}

 

Drupalgap implementation

function test_field_info_instance(options,entity_type,bundle_name) {
//	var arg={'entity_type':entity_type,'bundle_name':bundle_name};  
	var param='entity_type='+entity_type+'&bundle_name='+bundle_name;
	
	var my_args = {
			  'entity_type' : entity_type,
			  'bundle_name' : bundle_name,
			};
//	alert(entity_type);
	try {
		options.contentType = 'application/json';
	    options.method = 'POST';
	    options.path = 'drupalgap_field/field_info_instances.json';
	    options.service = 'd7menu';
	    options.resource = 'field_info_instance';
	    options.data = JSON.stringify(my_args);
	    Drupal.services.call(options);
	  }
	  catch (error) {
	    console.log('test_field_info_instance - ' + error);
	  }
	}

function _getFieldInfoInstance(entity_type,bundle_name){
	alert(entity_type);
	test_field_info_instance({
	    success: function(result) {
	    console.log(result);	    	
	    }
	},entity_type,bundle_name);	
}

 

D7Menu Service

d7menu.module

<?php
function d7menu_ctools_plugin_api($owner, $api) {
  if ($owner == 'services' && $api == 'services') {
    return array(
      'version' => 3,
      'file' => 'd7menu.resource.inc'
    );
  }
}

d7menu.resource.inc

function d7menu_services_resources() {
	$resources = array(
			'd7menu' => array(
					'actions' => array(
							'get_menu' => array(
									'help' => t('Gets a menu for drupalgap.'),
									'file' => array(
											'type' => 'inc',
											'module' => 'd7menu',
											'name' => 'd7menu.services',
									),
									'callback' => 'd7menu_get_menu',
									'args' => array(
											array(
													'name'         => 'name',
													'type'         => 'string',
													'description'  => t('Drupal menu name'),
													'source'       => array('data' => 'name'),
													'optional'     => TRUE,
											),
									),
									'access callback' => '_drupalgap_resource_access',
									'access callback file' => array(
											'type' => 'inc',
											'module' => 'drupalgap',
											'name' => 'drupalgap.resource',
									),
									'access arguments' => array('access content'),
									'access arguments append' => TRUE,
							),
					),
			),
	);
	return $resources;
}

d7.menu.services.inc

function d7menu_get_menu($name='d7mobile') {
  $menu=menu_load_links($name);
	$out=array();
	foreach($menu as $item)$out['nodes'][]=array('node'=>array('title'=>$item['link_title'],'path'=>$item['link_path']));
	$out['nodes']['length']=sizeof($menu);
print drupal_json_output($out);
exit();
}

 

Drupalgap Implementation

function d7mobilemenu_get_menu(options,name) {
var arg={'name':name}; 
try {
    options.method = 'POST';
    options.path = 'd7menu/get_menu.json';
    options.service = 'd7menu';
    options.resource = 'get_menu';
    options.data = JSON.stringify(arg);
    Drupal.services.call(options);
  }
  catch (error) {
    console.log('d7m_get_menu - ' + error);
  }
}


function _getMenu(name){
d7m_get_menu({
    success: function(result) {

      if (result.nodes.length &gt; 0) {
            var items = [];
            $.each(result.nodes, function(index, object){
                var node = object.node;
                items.push(
                 // l(node.title,  node.path,'{options:{reloadPage:true}}')  
                  l(node.title,  node.path)  
             
                );
             });

            var html = theme('popup', {
            content: theme('jqm_item_list', {
                items: items
            }),          
            attributes: {
              id: d7mobilemenu_container_id(),
          //    'style':'min-height:50px;'
            },
            button_attributes: {
            'style':'position:relative',
            'data-icon': drupalgap.settings.d7mobilemenu.icon,
              'data-iconpos': 'notext',
              'data-mini': 'true',
              'class': 'ui-btn-left'  //ui-btn-right
            },        
          
        });
               $('#'+d7mobilemenu_container_id()+'_'+drupalgap_get_page_id()).html(html).trigger('create');   
           
      }//if
   
    }
},name);
}