The final step in our journey is to turn our feature into a full-blown app by integrating it with the Apps API.

The Manifest File

Panopoly and some of its extension apps like Panopoly News and Panopoly FAQ are stored on a manifest file on the Panopoly Apps server. This manifest file lets Drupal know which features are actually apps and what server they belong to. If your app is adopted by Panopoly then your app will get added to their Panopoly Apps manifest and you won't have to do anything. However if you want to set up your own App Server then a little more magic is required.

Setting up an apps server is very similar to setting up a Feature server however we will assume you have already set up your own server and that it has a properly constructed manifest file. If this is the case then the only thing that you need to do is implement the following hook in your MYAPP.module file.

/**
 * provides server information to the apps
 *
 * this hook is only called on the current profile
 * RETURN: an array of assoctive server arrays
 */
function hook_apps_servers_info() {
  return array(
    'servername' => array(
      'title' => t('Store Title'), //the title to be use for the server
      'description' => t('A description of the server and what apps it might have'),
      'manifest' => 'http://apps.com/app/query', // the location of the  json manifest
    ),
  );
}

If you are successful you should see something like this in the apps dashboard

APPS

Hook App Info

The Apps module makes it very easy for developers to provide their own demo content. This is a great way to give site builders and end users a good sense of what your app is all about and apps are encouraged to ship with some sort of demo content.

The Apps module also makes it very easy to provide basic configuration options for your own app. A lot of apps will not require configuration options but more advanced users should be aware of the easy integration provided by the Apps module.

Demo Content

Creating demo content is fairly simple with the Default Content module.
This module lets you export content in the same way that you exported your configuration in Step 4. What is even cooler is that it allows you to export attached images as well so you can give the user more visually appealing demo content. The best approach is to create some nodes in the normal manner and then export them into a feature called "YOURAPP_demo" which should reside inside of YOURAPP. It is also important to mention that at this point not all content, such as terms that you might add to your node, is exportable.

DEMO

Once you have created your demo content feature and placed it inside of your app you need to let your app know about it. This is easy to do with hook_apps_app_info which should be placed in YOURAPP.module.

/**
 * Implementation of hook_apps_app_info()
 */
function panopoly_news_apps_app_info() {
  return array(
  	'demo content description' => 'If you are using Panopoly News for the first time we recommend you install some demo content to see how the magic works.',
  	'demo content module' => 'panopoly_news_demo',
  );
}

If you have properly implemented this hook you should see the following in your apps config page

DEMOCONTNET

App Configuration

Another really easy thing to implement with the Apps module is a basic configuration form for your app. You can specify a custom form builder function using the same hook you used to specify your demo content module.

/**
 * Implementation of hook_apps_app_info()
 */
function panopoly_news_apps_app_info() {
  return array(
  	'demo content description' => 'If you are using Panopoly News for the first time we recommend you install some demo content to see how the magic works.',
  	'demo content module' => 'panopoly_news_demo',
  	'configure form' => 'panopoly_news_configure_form',
  );
}

Now, just provide a normal form builder function

/**
 * Config form for Panopoly News
 */
function panopoly_news_configure_form($form, &$form_state) {
  $form = array();
  
  // This is currently just to test the apps config integration
  $form['panopoly_news_config_group'] = array(
      '#type' => 'fieldset',
      '#title' => "Configuration Options for Panopoly News",
  );

  $form['panopoly_news_config_group']['panopoly_news_test'] = array(
    '#title' => t('Trivia'),
    '#type' => 'select',
    '#required' => TRUE,
    '#options' => array(
      '1' => 'Mark Antony',
      '0' => 'Mark Anthony',
    ),
    '#default_value' => variable_get('panopoly_news_test', FALSE) ? '1' : '0',
    '#description' => t('Which Mark is superior?'),
  );

  return system_settings_form($form);
}

And you should now have a simple config form for your app

CONFIG

These are the two most basic and readily accessible implementations an app builder can use to get some cool functionality into their app with little effort. That being said there are a bunch of other really cool features in the apps module and we encourage you to check out the rest of the Apps API.

Comments

Ari Gold’s picture

"Setting up an apps server is very similar to setting up a Feature server however we will assume you have already set up your own server and that it has a properly constructed manifest file."

If we already have a Feature Server setup do we just need to make sure an app is uploaded to the Feature Server and includes a properly constructed manifest file? Or do we need to use http://drupal.org/project/appserver. Is there documentation on setting up an App Server and can we link to it from here rather than assuming it's already setup?

medien-vp’s picture

+1 for this request. I too would be very interested in such documentation.

pirog’s picture

You definitely will want to use the AppServer module if you are interested in providing your own apps. There is sadly not a lot of good documentation for how to set it up but you might be able to find something useful here
https://groups.drupal.org/open-app-standard/oas

Mike Pirog
CTO, Co-Founder
https://thinktandem.io