You are here

function Notifications_Subscription::form_info in Notifications 7

Same name and namespace in other branches
  1. 6.4 includes/notifications_subscription.class.inc \Notifications_Subscription::form_info()

Subscription information field for several forms

Return value

Forms API field structure

File

./notifications.subscription.inc, line 1524
Drupal Notifications Framework - Default class file

Class

Notifications_Subscription
Common base for subscription type and subscription instance

Code

function form_info() {
  $info = $this
    ->get_type();

  // Get fields formatted as array of items
  $fields = $this
    ->get_fields();
  if (!empty($info['name'])) {

    // This subscription type already has a name
    $value = $info['name'];
  }
  elseif (empty($fields)) {

    // No name, maybe no fields it should be enough with the title
    $value = '';
  }
  elseif (count($fields) == 1) {

    // If the field is unique, we don't need a table nor a name for it
    $value = $this
      ->format_fields(self::FORMAT_HTML | self::FORMAT_INLINE);
  }
  else {

    // Multiple fields, format as a table
    $value = $this
      ->format_fields(self::FORMAT_TABLE);
  }

  // Build a form field with all these values
  $field = array(
    '#type' => 'item',
    '#title' => t('@type subscription', array(
      '@type' => $this
        ->get_type('title'),
    )),
    '#value' => $value,
  );
  if (!empty($info['description'])) {
    $field['#description'] = $info['description'];
  }
  return $field;
}