You are here

function commerce_wishlist_share in Commerce Wishlist 7.3

Form callback: Wishlist sharing.

1 string reference to 'commerce_wishlist_share'
commerce_wishlist_block_view in ./commerce_wishlist.module
Implements hook_block_view().

File

./commerce_wishlist.module, line 428
Provides a wish list for use in Drupal Commerce.

Code

function commerce_wishlist_share($form, &$form_state, $wishlist) {
  $form_state['wishlist'] = $wishlist;
  $state = empty($wishlist->commerce_wishlist_visibility[LANGUAGE_NONE][0]['value']) ? 0 : $wishlist->commerce_wishlist_visibility[LANGUAGE_NONE][0]['value'];
  $account = user_load($wishlist->uid);
  $form = array();
  switch ($state) {

    // Private visibility.
    case COMMERCE_WISHLIST_VISIBILITY_PRIVATE:
      $form['message'] = array(
        '#markup' => t('Your wish list is private and can only be viewed by you.'),
      );
      break;

    // Protected visibility.
    case COMMERCE_WISHLIST_VISIBILITY_PROTECTED:
      $form['message'] = array(
        '#markup' => t("Your wish list is protected and can be viewed only by visiting this URL: <a href='@link'>@user's wish list</a>.", array(
          '@link' => commerce_wishlist_get_wishlist_url($wishlist),
          '@user' => format_username($account),
        )),
      );
      break;

    // Public visibility.
    case COMMERCE_WISHLIST_VISIBILITY_PUBLIC:
      $form['message'] = array(
        '#markup' => t('Your wish list is public and can be viewed by everyone.'),
      );
  }
  $form['message']['#weight'] = -10;
  field_attach_form('commerce_order', $wishlist, $form, $form_state, NULL, array(
    'field_name' => 'commerce_wishlist_visibility',
  ));
  $form['commerce_wishlist_visibility'][LANGUAGE_NONE]['#title'] = t('Set wish list to');
  unset($form['commerce_wishlist_visibility'][LANGUAGE_NONE]['#description']);
  $form['actions'] = array(
    '#type' => 'actions',
  );
  $form['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
  );
  return $form;
}